summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 22:25:39 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-12 22:25:39 +0200
commit971754eba93701cfb22bc4399a37debf238eddf1 (patch)
treee3a36023f93b73a1621de0c6c9503ccbb301fb03
parentFix dict generators for python 2.5 (diff)
downloadpyload-971754eba93701cfb22bc4399a37debf238eddf1.tar.xz
General fixup (1)
-rwxr-xr-xpyload/Core.py17
-rw-r--r--pyload/Database/Backend.py9
-rw-r--r--pyload/Database/User.py2
-rw-r--r--pyload/config/Parser.py8
-rw-r--r--pyload/config/Setup.py16
-rw-r--r--pyload/manager/Account.py7
-rw-r--r--pyload/manager/Addon.py5
-rw-r--r--pyload/network/HTTPChunk.py4
-rw-r--r--pyload/network/HTTPDownload.py2
-rw-r--r--pyload/network/JsEngine.py6
-rw-r--r--pyload/network/XDCCRequest.py2
-rw-r--r--pyload/utils/__init__.py18
-rw-r--r--pyload/utils/pylgettext.py1
-rw-r--r--pyload/webui/App/__init__.py3
-rw-r--r--pyload/webui/App/api.py (renamed from pyload/webui/app/api.py)20
-rw-r--r--pyload/webui/App/app.py (renamed from pyload/webui/app/pyload.py)4
-rw-r--r--pyload/webui/App/cnl.py (renamed from pyload/webui/app/cnl.py)0
-rw-r--r--pyload/webui/App/json.py (renamed from pyload/webui/app/json.py)2
-rw-r--r--pyload/webui/App/utils.py (renamed from pyload/webui/app/utils.py)2
-rw-r--r--pyload/webui/__init__.py12
-rw-r--r--pyload/webui/app/__init__.py3
-rwxr-xr-xsetup.py2
22 files changed, 78 insertions, 67 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index 217d9aff5..0fa9e6a44 100755
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -9,6 +9,7 @@ import codecs
import getopt
import imp
import logging
+import logging.handlers
import os
import signal
import subprocess
@@ -17,7 +18,7 @@ import time
import traceback
import pyload
-import pyload.utils.pylgettext as gettext
+from pyload.utils import pylgettext as gettext
from pyload import remote
from pyload.Database import DatabaseBackend, FileHandler
@@ -50,9 +51,9 @@ class Core(object):
self.pidfile = "pyload.pid"
self.deleteLinks = False #: will delete links on startup
- if len(argv) > 1:
+ if len(sys.argv) > 1:
try:
- options, args = getopt.getopt(argv[1:], 'vchdusqp:',
+ options, args = getopt.getopt(sys.argv[1:], 'vchdusqp:',
["version", "clear", "clean", "help", "debug", "user",
"setup", "configdir=", "changedir", "daemon",
"quit", "status", "no-remote","pidfile="])
@@ -111,7 +112,7 @@ class Core(object):
self.remote = False
except getopt.GetoptError:
- print 'Unknown Argument(s) "%s"' % " ".join(argv[1:])
+ print 'Unknown Argument(s) "%s"' % " ".join(sys.argv[1:])
self.print_help()
sys.exit()
@@ -212,7 +213,7 @@ class Core(object):
t = time.time()
print "waiting for pyLoad to quit"
- whileself.pidfile) and t + 10 > time.time():
+ while os.path.exists(self.pidfile) and t + 10 > time.time():
time.sleep(0.25)
if not os.path.exists(self.pidfile):
@@ -272,7 +273,7 @@ class Core(object):
self.config = ConfigParser()
- gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
+ gettext.setpaths([os.path.join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation("pyLoad", self.path("locale"),
languages=[self.config.get("general", "language"), "en"], fallback=True)
translation.install(True)
@@ -453,7 +454,7 @@ class Core(object):
def init_logger(self, level):
- self.log = logging.logging.getLogger("log")
+ self.log = logging.getLogger("log")
self.log.setLevel(level)
date_fmt = "%Y-%m-%d %H:%M:%S"
@@ -617,7 +618,7 @@ class Core(object):
self.deletePidFile()
- def os.path(self, *args):
+ def path(self, *args):
return os.path.join(pypath, *args)
diff --git a/pyload/Database/Backend.py b/pyload/Database/Backend.py
index 622880e65..846586417 100644
--- a/pyload/Database/Backend.py
+++ b/pyload/Database/Backend.py
@@ -9,12 +9,11 @@ except Exception:
import sqlite3
import Queue
+import os
import shutil
import threading
import traceback
-from pyload.utils import chmod
-
DB_VERSION = 4
@@ -138,7 +137,11 @@ class DatabaseBackend(threading.Thread):
convert = self._checkVersion() #: returns None or current version
self.conn = sqlite3.connect("files.db")
- os.chmod("files.db", 0600)
+
+ try:
+ os.chmod("files.db", 0600)
+ except Exception:
+ pass
self.c = self.conn.cursor() #: compatibility
diff --git a/pyload/Database/User.py b/pyload/Database/User.py
index b895a4e12..83ee66b93 100644
--- a/pyload/Database/User.py
+++ b/pyload/Database/User.py
@@ -82,7 +82,7 @@ class UserMethods(object):
@style.queue
def getAllUserData(db):
db.c.execute("SELECT name, permission, role, template, email FROM users")
- return dict(r[0], {"permission": r[1], "role": r[2], "template": r[3], "email": r[4]}) for r in db.c)
+ return dict((r[0], {"permission": r[1], "role": r[2], "template": r[3], "email": r[4]}) for r in db.c)
@style.queue
diff --git a/pyload/config/Parser.py b/pyload/config/Parser.py
index f834e4b4e..6e060ec9e 100644
--- a/pyload/config/Parser.py
+++ b/pyload/config/Parser.py
@@ -7,7 +7,7 @@ import shutil
import time
import traceback
-from pyload.utils import chmod, encode, decode
+from pyload.utils import encode, decode
CONF_VERSION = 1
@@ -205,7 +205,11 @@ class ConfigParser(object):
def saveConfig(self, config, filename):
"""saves config to filename"""
with open(filename, "wb") as f:
- os.chmod(filename, 0600)
+ try:
+ os.chmod(filename, 0600)
+ except Exception:
+ pass
+
f.write("version: %i \n" % CONF_VERSION)
for section in config.iterkeys():
f.write('\n%s - "%s":\n' % (section, config[section]['desc']))
diff --git a/pyload/config/Setup.py b/pyload/config/Setup.py
index fdf2524f5..567be70f8 100644
--- a/pyload/config/Setup.py
+++ b/pyload/config/Setup.py
@@ -418,20 +418,20 @@ class SetupAssistant(object):
def set_configdir(self, configdir, persistent=False):
- dirname = path.abspath(configdir)
+ dirname = os.path.abspath(configdir)
try:
- if not path.exists(dirname):
- os.makedirs(dirname, 0700)
+ if not os.path.exists(os.path.dirname):
+ os.makedirs(os.path.dirname, 0700)
- os.chdir(dirname)
+ os.chdir(os.path.dirname)
if persistent:
- c = path.join(rootdir, "config", "configdir")
- if not path.exists(c):
+ c = os.path.join(rootdir, "config", "configdir")
+ if not os.path.exists(c):
os.makedirs(c, 0700)
with open(c, "wb") as f:
- f.write(dirname)
+ f.write(os.path.dirname)
except IOError:
return False
@@ -478,7 +478,7 @@ class SetupAssistant(object):
def check_prog(self, command):
- pipe = PIPE
+ pipe = subprocess.PIPE
try:
subprocess.call(command, stdout=pipe, stderr=pipe)
return True
diff --git a/pyload/manager/Account.py b/pyload/manager/Account.py
index b743ccabc..8274c6592 100644
--- a/pyload/manager/Account.py
+++ b/pyload/manager/Account.py
@@ -7,7 +7,7 @@ import shutil
import threading
from pyload.manager.Event import AccountUpdateEvent
-from pyload.utils import chmod, lock
+from pyload.utils import lock
ACC_VERSION = 1
@@ -132,7 +132,10 @@ class AccountManager(object):
for option, values in data['options'].iteritems():
f.write("\t@%s %s\n" % (option, " ".join(values)))
- os.chmod(f.name, 0600)
+ try:
+ os.chmod(f.name, 0600)
+ except Exception:
+ pass
except Exception, e:
self.core.log.error(str(e))
diff --git a/pyload/manager/Addon.py b/pyload/manager/Addon.py
index a632111ea..65afb4b0f 100644
--- a/pyload/manager/Addon.py
+++ b/pyload/manager/Addon.py
@@ -8,8 +8,9 @@ import threading
import traceback
import types
+import SafeEval
+
from pyload.Thread import AddonThread
-from pyload.manager.Plugin import literal_eval
from pyload.utils import lock
@@ -90,7 +91,7 @@ class AddonManager(object):
if not args:
args = ()
if parse:
- args = tuple([literal_eval(x) for x in args])
+ args = tuple([SafeEval.const_eval(x) for x in args])
plugin = self.pluginMap[plugin]
f = getattr(plugin, func)
return f(*args)
diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py
index 1ce72a918..5252afb06 100644
--- a/pyload/network/HTTPChunk.py
+++ b/pyload/network/HTTPChunk.py
@@ -101,7 +101,7 @@ class ChunkInfo(object):
return ci
- def os.remove(self):
+ def remove(self):
fs_name = fs_encode("%s.chunks" % self.name)
if os.path.exists(fs_name): os.remove(fs_name)
@@ -305,7 +305,7 @@ class HTTPChunk(HTTPRequest):
self.fp.close() #: needs to be closed, or merging chunks will fail
- def os.close(self):
+ def close(self):
""" closes everything, unusable after this """
if self.fp: self.fp.close()
self.c.close()
diff --git a/pyload/network/HTTPDownload.py b/pyload/network/HTTPDownload.py
index e5917aa1f..8b124512b 100644
--- a/pyload/network/HTTPDownload.py
+++ b/pyload/network/HTTPDownload.py
@@ -304,7 +304,7 @@ class HTTPDownload(object):
chunk.close()
- def os.close(self):
+ def close(self):
""" cleanup """
for chunk in self.chunks:
self.closeChunk(chunk)
diff --git a/pyload/network/JsEngine.py b/pyload/network/JsEngine.py
index 8b5e2d760..9c8de05a7 100644
--- a/pyload/network/JsEngine.py
+++ b/pyload/network/JsEngine.py
@@ -213,10 +213,10 @@ class RhinoEngine(AbstractEngine):
jspath = [
"/usr/share/java/js.jar",
"js.jar",
- path.join(pypath, "js.jar")
+ os.path.join(pypath, "js.jar")
]
for p in jspath:
- if path.exists(p):
+ if os.path.exists(p):
self.path = p
break
else:
@@ -240,7 +240,7 @@ class JscEngine(AbstractEngine):
def setup(self):
jspath = "/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc"
- self.path = jspath if path.exists(jspath) else ""
+ self.path = jspath if os.path.exists(jspath) else ""
def eval(self, script):
diff --git a/pyload/network/XDCCRequest.py b/pyload/network/XDCCRequest.py
index 470ab96a7..b71594915 100644
--- a/pyload/network/XDCCRequest.py
+++ b/pyload/network/XDCCRequest.py
@@ -143,5 +143,5 @@ class XDCCRequest(object):
return (self.recv * 100) / self.filesize if elf.filesize else 0
- def os.close(self):
+ def close(self):
pass
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index 3c525caeb..5ca4e4563 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -12,17 +12,15 @@ import sys
import time
import urllib
-import pyload.utils.pylgettext as gettext
+from pyload.utils import pylgettext as gettext
# abstraction layer for json operations
-from bottle import json_loads
-
-
-def os.chmod(*args):
- try:
- os.chmod(*args)
- except Exception:
- pass
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+from bottle import json_loads, json_dumps
def decode(string):
@@ -252,7 +250,7 @@ def load_translation(name, locale, default="en"):
import traceback
try:
- gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
+ gettext.setpaths([os.path.join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation(name, os.path.join(pypath, "locale"),
languages=[locale, default], fallback=True)
except Exception:
diff --git a/pyload/utils/pylgettext.py b/pyload/utils/pylgettext.py
index 76bb268ec..fc83ac264 100644
--- a/pyload/utils/pylgettext.py
+++ b/pyload/utils/pylgettext.py
@@ -53,5 +53,6 @@ def find(domain, localedir=None, languages=None, all=False):
else:
return results
+
# Is there a smarter/cleaner pythonic way for this?
translation.func_globals['find'] = find
diff --git a/pyload/webui/App/__init__.py b/pyload/webui/App/__init__.py
new file mode 100644
index 000000000..f48708914
--- /dev/null
+++ b/pyload/webui/App/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from pyload.webui.App import app, api, cnl, json
diff --git a/pyload/webui/app/api.py b/pyload/webui/App/api.py
index 99a7c2998..31366b902 100644
--- a/pyload/webui/app/api.py
+++ b/pyload/webui/App/api.py
@@ -8,9 +8,9 @@ import SafeEval
import bottle
from pyload.Api import BaseObject
-from pyload.utils import json
+from pyload.utils import json, json_dumps
from pyload.webui import PYLOAD
-from pyload.webui.app.utils import toDict, set_session
+from pyload.webui.App.utils import toDict, set_session
# json encoder that accepts TBase objects
@@ -34,10 +34,10 @@ def call_api(func, args=""):
s = s.get_by_id(request.POST['session'])
if not s or not s.get("authenticated", False):
- return bottle.HTTPError(403, json.dumps("Forbidden"))
+ return bottle.HTTPError(403, json_dumps("Forbidden"))
if not PYLOAD.isAuthorized(func, {"role": s['role'], "permission": s['perms']}):
- return bottle.HTTPError(401, json.dumps("Unauthorized"))
+ return bottle.HTTPError(401, json_dumps("Unauthorized"))
args = args.split("/")[1:]
kwargs = {}
@@ -51,19 +51,19 @@ def call_api(func, args=""):
return callApi(func, *args, **kwargs)
except Exception, e:
traceback.print_exc()
- return bottle.HTTPError(500, json.dumps({"error": e.message, "traceback": traceback.format_exc()}))
+ return bottle.HTTPError(500, json_dumps({"error": e.message, "traceback": traceback.format_exc()}))
def callApi(func, *args, **kwargs):
if not hasattr(PYLOAD.EXTERNAL, func) or func.startswith("_"):
print "Invalid API call", func
- return bottle.HTTPError(404, json.dumps("Not Found"))
+ return bottle.HTTPError(404, json_dumps("Not Found"))
result = getattr(PYLOAD, func)(*[SafeEval.const_eval(x) for x in args],
**dict((x, SafeEval.const_eval(y)) for x, y in kwargs.iteritems()))
# null is invalid json response
- return json.dumps(result or True, cls=TBaseEncoder)
+ return json_dumps(result or True, cls=TBaseEncoder)
# post -> username, password
@@ -78,16 +78,16 @@ def login():
info = PYLOAD.checkAuth(user, password)
if not info:
- return json.dumps(False)
+ return json_dumps(False)
s = set_session(request, info)
# get the session id by dirty way, documentations seems wrong
try:
sid = s._headers['cookie_out'].split("=")[1].split(";")[0]
- return json.dumps(sid)
+ return json_dumps(sid)
except Exception:
- return json.dumps(True)
+ return json_dumps(True)
@bottle.route('/api/logout')
diff --git a/pyload/webui/app/pyload.py b/pyload/webui/App/app.py
index 58acdf12c..9d031e659 100644
--- a/pyload/webui/app/pyload.py
+++ b/pyload/webui/App/app.py
@@ -12,7 +12,7 @@ import bottle
from pyload.webui import PYLOAD, PYLOAD_DIR, THEME_DIR, THEME, SETUP, env
-from pyload.webui.app.utils import render_to_response, parse_permissions, parse_userdata, \
+from pyload.webui.App.utils import render_to_response, parse_permissions, parse_userdata, \
login_required, get_permission, set_permission, permlist, toDict, set_session
from pyload.utils.filters import relpath, unquotepath
@@ -298,7 +298,7 @@ def config():
@bottle.route('/filechooser/<file:path>')
@bottle.route('/pathchooser/<path:path>')
@login_required('STATUS')
-def os.path(file="", path=""):
+def path(file="", path=""):
type = "file" if file else "folder"
path = os.path.normpath(unquotepath(path))
diff --git a/pyload/webui/app/cnl.py b/pyload/webui/App/cnl.py
index 07b966f5e..07b966f5e 100644
--- a/pyload/webui/app/cnl.py
+++ b/pyload/webui/App/cnl.py
diff --git a/pyload/webui/app/json.py b/pyload/webui/App/json.py
index a7fe8dcfb..98eb8c4f2 100644
--- a/pyload/webui/app/json.py
+++ b/pyload/webui/App/json.py
@@ -10,7 +10,7 @@ import bottle
from pyload.utils import decode, formatSize
from pyload.webui import PYLOAD
-from pyload.webui.app.utils import login_required, render_to_response, toDict
+from pyload.webui.App.utils import login_required, render_to_response, toDict
def format_time(seconds):
diff --git a/pyload/webui/app/utils.py b/pyload/webui/App/utils.py
index 5663c6f58..18d66c302 100644
--- a/pyload/webui/app/utils.py
+++ b/pyload/webui/App/utils.py
@@ -115,7 +115,7 @@ def toDict(obj):
return dict((att, getattr(obj, att)) for att in obj.__slots__)
-class CherryPyWSGI(ServerAdapter):
+class CherryPyWSGI(bottle.ServerAdapter):
def run(self, handler):
from wsgiserver import CherryPyWSGIServer
diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py
index e1fe6738f..1dcd6bb6e 100644
--- a/pyload/webui/__init__.py
+++ b/pyload/webui/__init__.py
@@ -4,11 +4,11 @@
import os
import sys
-import beaker
+import beaker.middleware
import bottle
import jinja2
-import pyload.utils.pylgettext as gettext
+from pyload.utils import pylgettext as gettext
from pyload.Thread import Server
from pyload.utils.middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware
@@ -16,7 +16,7 @@ from pyload.network.JsEngine import JsEngine
from pyload.utils import decode, formatSize
-THEME_DIR = os.path.abspath(os.path.join(dirname(__file__), "themes"))
+THEME_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "themes"))
PYLOAD_DIR = os.path.abspath(os.path.join(THEME_DIR, "..", "..", ".."))
sys.path.append(PYLOAD_DIR)
@@ -76,7 +76,7 @@ if PREFIX:
else:
env.filters['url'] = lambda x: PREFIX + x if x.startswith("/") else x
-gettext.setpaths([join(os.sep, "usr", "share", "pyload", "locale"), None])
+gettext.setpaths([os.path.join(os.sep, "usr", "share", "pyload", "locale"), None])
translation = gettext.translation("django", os.path.join(PYLOAD_DIR, "locale"),
languages=[config.get("general", "language"), "en"],fallback=True)
translation.install(True)
@@ -95,7 +95,7 @@ web = GZipMiddleWare(web)
if PREFIX:
web = PrefixMiddleware(web, prefix=PREFIX)
-import pyload.webui.app
+from pyload.webui import App
def run_auto(host="0.0.0.0", port="8000"):
@@ -115,7 +115,7 @@ def run_threaded(host="0.0.0.0", port="8000", theads=3, cert="", key=""):
wsgiserver.CherryPyWSGIServer.numthreads = theads
- from pyload.webui.app.utils import CherryPyWSGI
+ from pyload.webui.App.utils import CherryPyWSGI
bottle.run(app=web, host=host, port=port, server=CherryPyWSGI, quiet=True)
diff --git a/pyload/webui/app/__init__.py b/pyload/webui/app/__init__.py
deleted file mode 100644
index 39d0fadd5..000000000
--- a/pyload/webui/app/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from pyload.webui.app import api, cnl, json, pyload
diff --git a/setup.py b/setup.py
index 5c7a52819..4c73ea43f 100755
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@ import sys
import pyload
-PROJECT_DIR = path.abspath(path.join(__file__, ".."))
+PROJECT_DIR = os.path.abspath(path.join(__file__, ".."))
setuptools.setup(
name="pyload",