Rev1833, Fix utf8 system paths

This commit is contained in:
shortcutme 2017-01-22 21:22:53 +01:00
parent 6a46181e8e
commit a0c3d7f8a6
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
7 changed files with 45 additions and 25 deletions

View File

@ -130,7 +130,7 @@ class UiRequestPlugin(object):
# Db
yield "<br><br><b>Db</b>:<br>"
for db in sys.modules["Db.Db"].opened_dbs:
yield "- %.3fs: %s<br>" % (time.time() - db.last_query_time, db.db_path)
yield "- %.3fs: %s<br>" % (time.time() - db.last_query_time, db.db_path.encode("utf8"))
# Sites
yield "<br><br><b>Sites</b>:"
@ -220,7 +220,7 @@ class UiRequestPlugin(object):
objs = [obj for obj in gc.get_objects() if isinstance(obj, greenlet)]
yield "<br>Greenlets (%s):<br>" % len(objs)
for obj in objs:
yield " - %.1fkb: %s<br>" % (self.getObjSize(obj, hpy), cgi.escape(repr(obj)))
yield " - %.1fkb: %s<br>" % (self.getObjSize(obj, hpy), cgi.escape(repr(obj).encode("utf8")))
from Worker import Worker
objs = [obj for obj in gc.get_objects() if isinstance(obj, Worker)]
@ -401,7 +401,10 @@ class UiRequestPlugin(object):
except Exception, err:
output("<br><b>! Error: %s</b><br>" % err)
taken = time.time() - s
multipler = standard / taken
if taken > 0:
multipler = standard / taken
else:
multipler = 99
if multipler < 0.3:
speed = "Sloooow"
elif multipler < 0.5:

View File

@ -118,19 +118,33 @@ class ActionsPlugin(object):
def formatAutorun(self):
args = sys.argv[:]
args.insert(0, sys.executable)
if not getattr(sys, 'frozen', False): # Not frozen
args.insert(0, sys.executable)
cwd = os.getcwd().decode(sys.getfilesystemencoding())
else:
cwd = os.path.dirname(sys.executable).decode(sys.getfilesystemencoding())
if sys.platform == 'win32':
args = ['"%s"' % arg for arg in args]
args = ['"%s"' % arg for arg in args if arg]
cmd = " ".join(args)
# Dont open browser on autorun
cmd = cmd.replace("start.py", "zeronet.py").replace('"--open_browser"', "").replace('"default_browser"', "").strip()
cmd += ' --open_browser ""'
cmd = cmd.decode(sys.getfilesystemencoding())
return "@echo off\ncd /D %s\n%s" % (os.getcwd(), cmd)
return u"""
@echo off
chcp 65001
set PYTHONIOENCODING=utf-8
cd /D \"%s\"
%s
""" % (cwd, cmd)
def isAutorunEnabled(self):
path = self.getAutorunPath()
return os.path.isfile(path) and open(path).read() == self.formatAutorun()
return os.path.isfile(path) and open(path).read().decode("utf8") == self.formatAutorun()
def titleAutorun(self):
translate = _["Start ZeroNet when Windows starts"]
@ -143,4 +157,4 @@ class ActionsPlugin(object):
if self.isAutorunEnabled():
os.unlink(self.getAutorunPath())
else:
open(self.getAutorunPath(), "w").write(self.formatAutorun())
open(self.getAutorunPath(), "w").write(self.formatAutorun().encode("utf8"))

View File

@ -10,7 +10,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.5.1"
self.rev = 1830
self.rev = 1833
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"
@ -61,20 +61,22 @@ class Config(object):
else:
fix_float_decimals = False
if __file__.endswith("/Contents/Resources/core/src/Config.py"):
this_file = os.path.abspath(__file__).replace("\\", "/")
if this_file.endswith("/Contents/Resources/core/src/Config.py"):
# Running as ZeroNet.app
if __file__.startswith("/Application") or __file__.startswith("/private"):
if this_file.startswith("/Application") or this_file.startswith("/private"):
# Runnig from non-writeable directory, put data to Application Support
start_dir = os.path.expanduser("~/Library/Application Support/ZeroNet")
start_dir = os.path.expanduser("~/Library/Application Support/ZeroNet").decode(sys.getfilesystemencoding())
else:
# Running from writeable directory put data next to .app
start_dir = re.sub("/[^/]+/Contents/Resources/core/src/Config.py", "", __file__)
start_dir = re.sub("/[^/]+/Contents/Resources/core/src/Config.py", "", this_file).decode(sys.getfilesystemencoding())
config_file = start_dir + "/zeronet.conf"
data_dir = start_dir + "/data"
log_dir = start_dir + "/log"
elif __file__.replace("\\", "/").endswith("/core/src/Config.py"):
elif this_file.endswith("/core/src/Config.py"):
# Running as exe or source is at Application Support directory, put var files to outside of core dir
start_dir = __file__.replace("/core/src/Config.py", "")
start_dir = this_file.replace("/core/src/Config.py", "").decode(sys.getfilesystemencoding())
config_file = start_dir + "/zeronet.conf"
data_dir = start_dir + "/data"
log_dir = start_dir + "/log"

View File

@ -70,13 +70,14 @@ class CryptConnectionManager:
return True # Files already exits
import subprocess
cmd = "%s req -x509 -newkey rsa:2048 -sha256 -batch -keyout %s -out %s -nodes -config %s" % helper.shellquote(
self.openssl_bin,
config.data_dir+"/key-rsa.pem",
config.data_dir+"/cert-rsa.pem",
self.openssl_env["OPENSSL_CONF"]
)
proc = subprocess.Popen(
"%s req -x509 -newkey rsa:2048 -sha256 -batch -keyout %s -out %s -nodes -config %s" % helper.shellquote(
self.openssl_bin,
config.data_dir+"/key-rsa.pem",
config.data_dir+"/cert-rsa.pem",
self.openssl_env["OPENSSL_CONF"]
),
cmd.encode(sys.getfilesystemencoding()),
shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=self.openssl_env
)
back = proc.stdout.read().strip()

View File

@ -19,8 +19,8 @@ from Plugin import PluginManager
class SiteStorage(object):
def __init__(self, site, allow_create=True):
self.site = site
self.directory = "%s/%s" % (config.data_dir, self.site.address) # Site data diretory
self.allowed_dir = os.path.abspath(self.directory.decode(sys.getfilesystemencoding())) # Only serve file within this dir
self.directory = u"%s/%s" % (config.data_dir, self.site.address) # Site data diretory
self.allowed_dir = os.path.abspath(self.directory) # Only serve file within this dir
self.log = site.log
self.db = None # Db class
self.db_checked = False # Checked db tables since startup

View File

@ -160,7 +160,7 @@ class TorManager:
res_protocol = self.send("PROTOCOLINFO", conn)
cookie_match = re.search('COOKIEFILE="(.*?)"', res_protocol)
if cookie_match:
cookie_file = cookie_match.group(1)
cookie_file = cookie_match.group(1).decode("string-escape")
auth_hex = binascii.b2a_hex(open(cookie_file, "rb").read())
res_auth = self.send("AUTHENTICATE %s" % auth_hex, conn)
elif config.tor_password:

View File

@ -196,7 +196,7 @@ def openLibrary():
global ssl
try:
if sys.platform.startswith("win"):
dll_path = os.path.dirname(__file__) + "/" + "libeay32.dll"
dll_path = os.path.dirname(os.path.abspath(__file__)) + "/" + "libeay32.dll"
elif sys.platform == "cygwin":
dll_path = "/bin/cygcrypto-1.0.0.dll"
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle OSX