Made it run on linux
This commit is contained in:
1 parent
7d0b413961
commit
a4a2606b6a
3 files changed
+28
-19
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
from twisted.web import static, resource
|
from twisted.web import static, resource
|
||||||
import sys, os, glob, imp
|
import sys, os, imp
|
||||||
|
|
||||||
from Hatenatools import *#UGO, PPM, TMB and NTFT
|
from Hatenatools import *#UGO, PPM, TMB and NTFT
|
||||||
#from DB import Database#flipnote handler
|
#from DB import Database#flipnote handler
|
||||||
@@ -163,27 +163,22 @@ class FolderResource(resource.Resource):
|
|||||||
path = "/".join(request.path.split("/")[3:])
|
path = "/".join(request.path.split("/")[3:])
|
||||||
Log(request, path)
|
Log(request, path)
|
||||||
return "I am a folder, but I'm to lazy to list my contents..."
|
return "I am a folder, but I'm to lazy to list my contents..."
|
||||||
def LoadHatenadirStructure(Resource, path="hatenadir/ds/v2-xx", root = True):
|
def LoadHatenadirStructure(Resource, path=os.path.join("hatenadir", "ds", "v2-xx")):
|
||||||
for i in glob.glob("%s\*" % path):
|
for root, dirs, files in os.walk(path):
|
||||||
if os.path.isfile(i):
|
if root <> path: continue#use recursion instead
|
||||||
filename = os.path.basename(i)
|
for filename in files:
|
||||||
filetype = filename.split(".")[-1].lower()
|
filetype = filename.split(".")[-1].lower()
|
||||||
|
os.path.join(path, filename)
|
||||||
|
|
||||||
if filetype == "ugoxml":
|
if filetype == "ugoxml":
|
||||||
Resource.putChild(filename[:-3], UGOXMLResource(i))
|
Resource.putChild(filename[:-3], UGOXMLResource(os.path.join(path, filename)))
|
||||||
elif filetype == "py":
|
elif filetype == "py":
|
||||||
try:
|
try:
|
||||||
#sys.path.append(os.path.abspath(os.path.dirname(i)))
|
pyfile = imp.load_source("pyfile", os.path.abspath(os.path.join(path, filename)))
|
||||||
# #pyfile = __import__(filename[:-3])
|
|
||||||
#pyfile = importlib.import_module(filename[:-3])
|
|
||||||
#sys.path.pop(-1)
|
|
||||||
#pyfile = imp.load_module(i)
|
|
||||||
|
|
||||||
pyfile = imp.load_source("pyfile", os.path.abspath(i))
|
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
pyfile = None
|
pyfile = None
|
||||||
print "Error!"
|
print "Error!"
|
||||||
print "Failed to import the python file \"%s\"" % i
|
print "Failed to import the python file \"%s\"" % os.path.join(path, filename)
|
||||||
print err
|
print err
|
||||||
|
|
||||||
if pyfile:
|
if pyfile:
|
||||||
@@ -192,11 +187,11 @@ def LoadHatenadirStructure(Resource, path="hatenadir/ds/v2-xx", root = True):
|
|||||||
pass#ignore
|
pass#ignore
|
||||||
else:
|
else:
|
||||||
Resource.putChild(filename, FileResource(os.path.join(path, filename)))
|
Resource.putChild(filename, FileResource(os.path.join(path, filename)))
|
||||||
elif os.path.isdir(i):
|
for foldername in dirs:# os.path.isdir(i):
|
||||||
if os.path.basename(i)[:2] <> "__":
|
if foldername[:2] <> "__":
|
||||||
folder = FolderResource()
|
folder = FolderResource()
|
||||||
LoadHatenadirStructure(folder, os.path.join(path, os.path.basename(i)), False)
|
LoadHatenadirStructure(folder, os.path.join(path, foldername))
|
||||||
Resource.putChild(os.path.basename(i), folder)
|
Resource.putChild(foldername, folder)
|
||||||
|
|
||||||
#when loading:
|
#when loading:
|
||||||
def Setup():
|
def Setup():
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
<trait>0</trait>
|
<trait>0</trait>
|
||||||
<value />
|
<value />
|
||||||
<value>0</value>
|
<value>0</value>
|
||||||
<embedded_file>__ntfts\News.ntft</embedded_file>
|
<embedded_file>__ntfts/News.ntft</embedded_file>
|
||||||
</button>
|
</button>
|
||||||
</ugo_xml>
|
</ugo_xml>
|
||||||
@@ -11,6 +11,20 @@ if useWSGI: from twisted.application import internet, service
|
|||||||
import sys, time, os, atexit
|
import sys, time, os, atexit
|
||||||
print "Done!"
|
print "Done!"
|
||||||
|
|
||||||
|
#set working directory
|
||||||
|
if os.path.dirname(__file__):
|
||||||
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
else:
|
||||||
|
for i in sys.path:
|
||||||
|
path = os.path.split(i)[0]
|
||||||
|
if not os.path.exists(os.path.join(path, "server.py")): continue
|
||||||
|
if not os.path.exists(os.path.join(path, "hatena.py")): continue
|
||||||
|
if not os.path.exists(os.path.join(path, "DB.py")): continue
|
||||||
|
os.chdir(path)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print "Can't force working directory, may fail crash!"
|
||||||
|
|
||||||
#Logging
|
#Logging
|
||||||
class Log:
|
class Log:
|
||||||
class filesplit:#a file object writing to two outputs
|
class filesplit:#a file object writing to two outputs
|
||||||
|
|||||||
Reference in new issue
Block a user
