diff options
Diffstat (limited to 'module')
| -rw-r--r-- | module/PluginManager.py | 68 | ||||
| -rw-r--r-- | module/setup.py | 37 | 
2 files changed, 89 insertions, 16 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: | 
