summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-24 14:47:50 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-08-24 14:47:50 +0200
commit9bf785a0fbaf5f8d64037d2010c6c0b0416db1f0 (patch)
tree27bfd5600dd6583c7e6c8931ee738557628a488f
parentfixes for django 1.1 (diff)
downloadpyload-9bf785a0fbaf5f8d64037d2010c6c0b0416db1f0.tar.xz
change configpath with setup, parser use plugins in homedir
-rw-r--r--module/PluginManager.py68
-rw-r--r--module/setup.py37
-rwxr-xr-xpyLoadCore.py13
3 files changed, 99 insertions, 19 deletions
diff --git a/module/PluginManager.py b/module/PluginManager.py
index 8f2a94ca9..8f00b9f25 100644
--- a/module/PluginManager.py
+++ b/module/PluginManager.py
@@ -18,10 +18,16 @@
"""
import re
+import sys
from os import listdir
+from os import makedirs
+
from os.path import isfile
from os.path import join
+from os.path import exists
+from os.path import abspath
+
from sys import version_info
from itertools import chain
@@ -53,6 +59,15 @@ class PluginManager():
def createIndex(self):
"""create information for all plugins available"""
+
+ sys.path.append(abspath(""))
+
+ if not exists("userplugins"):
+ makedirs("userplugins")
+ if not exists(join("userplugins", "__init__.py")):
+ f = open(join("userplugins", "__init__.py"), "wb")
+ f.close()
+
self.rePattern = re.compile(r'__pattern__.*=.*r("|\')([^"\']+)')
self.reVersion = re.compile(r'__version__.*=.*("|\')([0-9.]+)')
self.reConfig = re.compile(r'__config__.*=.*\[([^\]]+)', re.MULTILINE)
@@ -67,9 +82,10 @@ class PluginManager():
self.log.info(_("created index of plugins"))
- def parse(self, typ, folder, create=False, pattern=False):
+ def parse(self, typ, folder, create=False, pattern=False, home={}):
"""
returns dict with information
+ home contains parsed plugins from module.
{
name : {path, version, config, (pattern, re), (plugin, class)}
@@ -77,8 +93,17 @@ class PluginManager():
"""
plugins = {}
- pfolder = join(pypath, "module", "plugins", folder)
-
+ if home:
+ pfolder = join("userplugins", folder)
+ if not exists(pfolder):
+ makedirs(pfolder)
+ if not exists(join(pfolder, "__init__.py")):
+ f = open(join(pfolder, "__init__.py"), "wb")
+ f.close()
+
+ else:
+ pfolder = join(pypath, "module", "plugins", folder)
+
for f in listdir(pfolder):
if (isfile(join(pfolder, f)) and f.endswith(".py") or f.endswith("_25.pyc") or f.endswith("_26.pyc") or f.endswith("_27.pyc")) and not f.startswith("_"):
data = open(join(pfolder, f))
@@ -95,11 +120,28 @@ class PluginManager():
name = f[:-3]
if name[-1] == "." : name = name[:-4]
+
+ version = self.reVersion.findall(content)
+ if version:
+ version = float(version[0][1])
+ else:
+ version = 0
+
+ if home and home.has_key(name):
+ if home[name]["v"] > version:
+ continue
+
+
plugins[name] = {}
+ plugins[name]["v"] = version
- module = f.replace(".pyc","").replace(".py","")
- path = "module.plugins.%s.%s" % (folder, module)
-
+
+ module = f.replace(".pyc","").replace(".py","")
+ if home:
+ path = "userplugins.%s.%s" % (folder, module)
+ else:
+ path = "module.plugins.%s.%s" % (folder, module)
+
plugins[name]["name"] = module
plugins[name]["path"] = path
@@ -118,13 +160,7 @@ class PluginManager():
plugins[name]["re"] = re.compile(pattern)
except:
self.log.error(_("%s has invalid pattern.") % name)
-
- version = self.reVersion.findall(content)
- if version:
- version = float(version[0][1])
- else:
- version = 0
- plugins[name]["v"] = version
+
config = self.reConfig.findall(content)
@@ -137,8 +173,10 @@ class PluginManager():
for item in config:
self.core.config.addPluginConfig([name]+item)
- # replace with plugins in homedir, plugin updater
-
+ if not home:
+ temp = self.parse(typ, folder, create, pattern, plugins)
+ plugins.update(temp)
+
return plugins
#----------------------------------------------------------------------
diff --git a/module/setup.py b/module/setup.py
index a75aede05..c1f449be4 100644
--- a/module/setup.py
+++ b/module/setup.py
@@ -19,10 +19,12 @@
from getpass import getpass
import gettext
from hashlib import sha1
-from os import remove
import os
+from os import remove
+from os import makedirs
from os.path import abspath
from os.path import dirname
+from os.path import exists
from os.path import isfile
from os.path import join
import random
@@ -30,6 +32,7 @@ import re
from subprocess import PIPE
from subprocess import call
import sys
+from sys import exit
class Setup():
"""
@@ -129,6 +132,15 @@ class Setup():
return False
print ""
+ print _("Do you want to change the config path? Current is %s" % abspath(""))
+ print _("If you use pyLoad on a server or the home partition lives on an iternal flash it may be a good idea to change it.")
+ path = self.ask(_("Change config path?"), "n", bool=True)
+ if path:
+ self.conf_path()
+ #calls exit when changed
+
+
+ print ""
print _("Do you want to configure basic settings?")
print _("This is recommend for first run.")
con = self.ask(_("Make basic setup?"), "y", bool=True)
@@ -152,6 +164,8 @@ class Setup():
print ""
print _("Setup finished successfully.")
+ print _("Hit enter to exit and restart pyLoad")
+ raw_input()
return True
def system_check(self):
@@ -325,6 +339,27 @@ class Setup():
self.config.password = self.ask("", "", password=True)
self.config.save()
+ def conf_path(self, trans=False):
+ if trans:
+ translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"]])
+ translation.install(unicode=(True if sys.getfilesystemencoding().startswith("utf") else False))
+
+ print _("Setting new configpath, current configuration will not be transfered!")
+ path = self.ask(_("Configpath"), abspath(""))
+ try:
+ path = join(pypath, path)
+ if not exists(path):
+ makedirs(path)
+ f = open(join(pypath, "module","config", "configdir"), "wb")
+ f.write(path)
+ f.close()
+ print _("Configpath changed, setup will now close, please restart to go on.")
+ print _("Press Enter to exit.")
+ raw_input()
+ exit()
+ except Exception, e:
+ print _("Setting config path failed: %s") % str(e)
+
def print_dep(self, name, value):
"""Print Status of dependency"""
if value:
diff --git a/pyLoadCore.py b/pyLoadCore.py
index e140b42a3..be6d40126 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -76,7 +76,7 @@ class Core(object):
if len(argv) > 1:
try:
- options, args = getopt(argv[1:], 'vca:hdus', ["version", "clear", "add=", "help", "debug", "user", "setup", "configdir="])
+ options, args = getopt(argv[1:], 'vca:hdus', ["version", "clear", "add=", "help", "debug", "user", "setup", "configdir"])
for option, argument in options:
if option in ("-v", "--version"):
@@ -109,6 +109,12 @@ class Core(object):
s = Setup(pypath, self.config)
s.start()
exit()
+ elif option == "--configdir":
+ from module.setup import Setup
+ self.config = ConfigParser()
+ s = Setup(pypath, self.config)
+ s.conf_path(True)
+ exit()
except GetoptError:
print 'Unknown Argument(s) "%s"' % " ".join(argv[1:])
self.print_help()
@@ -127,7 +133,7 @@ class Core(object):
print " -u, --user", " " * 13, "Set new User and password"
print " -d, --debug", " " * 12, "Enable debug mode"
print " -s, --setup", " " * 12, "Run Setup Assistent"
- print " --configdir=<path>", " " * 5, "Custom config dir, (see config folder for permanent change)"
+ print " --configdir", " " * 12, "Set new config directory"
print " -h, --help", " " * 13, "Display this help screen"
print ""
@@ -160,7 +166,8 @@ class Core(object):
print "Setup failed"
if not res:
remove("pyload.conf")
- exit()
+
+ exit()
try: signal.signal(signal.SIGQUIT, self.quit)
except: pass