def setupPluginsSettings(self): """ Config of every enabled plugin """ config = self.config choices = [] choices.append(_("Exit")) plugins = config.options("plugins") plugins.sort() for plugin in list(plugins): self.loadPlugin(plugin) if hasattr(self.plugins[plugin], "setup"): choices.append("{0:25s} {1}".format(plugin, self.plugins[plugin].about)) else: plugins.remove(plugin) while True: print() console.writeln(" " + _("Plugins settings menu"), console.color("RB", False, "")) choice = console.menu(_("Plugins:"), choices, padding=1) if choice == choices[0]: break plugin = plugins[choices.index(choice) - 1] console.write(" " + _("Configuration of") + " ", console.color("GB", False, "")) console.writeln(plugin, console.color("GB", True, "")) self.plugins[plugin].setup() config.save()
def interactiveSetup(self): """ Interactive setup script. """ print() console.writeln(_("Entering setup menu for profile {0}.").format(self.profile), console.color("G", True, "")) self.setupWorkDir() choice = "" choices = [] choices.append(_("Exit")) choices.append(_("General options")) choices.append("Geocaching.com") choices.append(_("Output")) choices.append(_("Enable/Disable plugins")) choices.append(_("Plugins settings")) while choice != choices[0]: print() console.writeln(_("Main menu"), console.color("RB", True, "")) choice = console.menu(_("Action:"), choices) if choice == choices[1]: self.setupGeneral() elif choice == choices[2]: self.setupGeocachingCom() elif choice == choices[3]: self.setupOutput() elif choice == choices[4]: self.setupPlugins() elif choice == choices[5]: self.setupPluginsSettings() self.setupEnd()
def interactiveSetup(self): """ Interactive setup script. """ print() console.writeln( _("Entering setup menu for profile {0}.").format(self.profile), console.color("G", True, "")) self.setupWorkDir() choice = "" choices = [] choices.append(_("Exit")) choices.append(_("General options")) choices.append("Geocaching.com") choices.append(_("Output")) choices.append(_("Enable/Disable plugins")) choices.append(_("Plugins settings")) while choice != choices[0]: print() console.writeln(_("Main menu"), console.color("RB", True, "")) choice = console.menu(_("Action:"), choices) if choice == choices[1]: self.setupGeneral() elif choice == choices[2]: self.setupGeocachingCom() elif choice == choices[3]: self.setupOutput() elif choice == choices[4]: self.setupPlugins() elif choice == choices[5]: self.setupPluginsSettings() self.setupEnd()
def setupOutput(self): """ Config: output section """ config = self.config config.assertSection("output") print() console.writeln(_("Output"), console.color("G", True, "")) templates = self.detectTemplates() print(" " + _( "Templates are looked up in these directories (consecutively):") + "\n * " + "\n * ".join(self.templateDirs)) config.update("output", "template", _("Template ({CHOICES}):"), validate=templates) themes = self.detectThemes() print(" " + _("Themes are looked up in these directories (consecutively):") + "\n * " + "\n * ".join(self.themeDirs)) config.update("output", "theme", _("Theme ({CHOICES}):"), validate=themes) config.update("output", "directory", _("Output directory:"), validate=lambda val: None if os.path.isdir(os.path.expanduser(val)) else _( "You have to input existing directory.")) config.save()
def setupGeneral(self): """ Config: general section """ config = self.config config.assertSection("general") print() console.writeln(_("General options"), console.color("G", True, "")) langs = globals()["langs"] config.update("general", "language", _("Please, select user interface language ({CHOICES})."), validate=list(langs.keys())) langs[config.get("general", "language")].install() print(" " + _( "Enter your home coordinates in degrees as decimal number (N means positive value, S negative; E means positive value, W negative)." )) config.update("general", "homelat", _("Latitude:"), validate=lambda val: None if re.search("^-?[0-9]+\.?[0-9]*$", val) is not None else _("Please, use decimal number.")) config.update("general", "homelon", _("Longitude:"), validate=lambda val: None if re.search("^-?[0-9]+\.?[0-9]*$", val) is not None else _("Please, use decimal number.")) config.save()
def source(self,args): for arg in args: (plugin,list) = self.__find(arg) if plugin == None: console.writeln("No plugin with this name is present in the plugin database.") return None import tempfile dir = "./" rep = self.__repManager.getRepository(list.repository) rep = rep(list.repository) if not rep.getPluginSource(list,plugin,dir): console.writeln ("Errors retriving the source package: %s-%s-src.tar.gz" % (plugin["name"][0]["value"],plugin["version"][0]["value"])) return None filename = dir + "/%s-%s-src.tar.gz" % (plugin["name"][0]["value"],plugin["version"][0]["value"]) import tarfile console.writeln("Exctracting source package..") try: tarf = tarfile.open(filename.encode("ascii"),"r|gz") tarf.extractall (dir) except Exception: console.writeln("Error while exctracting source package!") return None console.writeln("%s source installed." % (plugin["name"][0]["value"]))
def search(self,arg): arg = " ".join(arg) if config.verbose: results = ["- " + plugin["name"][0]["value"] + " (compatible with GNU MyServer version ["+plugin.getMyServerMinVersion() + "," + plugin.getMyServerMinVersion() + "])\n " + plugin["description"][0]["value"] + "\n Dependences: " + " ".join(dep["value"] + "[" + dep["min-version"] + "," + dep["max-version"] + "]" for dep in plugin["depends"]) for plugin in self.__search(arg)] else: results = [plugin["name"][0]["value"] + " - " + plugin["description"][0]["value"] for plugin in self.__search(arg)] console.writeln("\n".join(results))
def setupPluginsSettings(self): """ Config of every enabled plugin """ config = self.config choices = [] choices.append(_("Exit")) plugins = config.options("plugins") plugins.sort() for plugin in list(plugins): self.loadPlugin(plugin) if hasattr(self.plugins[plugin], "setup"): choices.append("{0:25s} {1}".format( plugin, self.plugins[plugin].about)) else: plugins.remove(plugin) while True: print() console.writeln(" " + _("Plugins settings menu"), console.color("RB", False, "")) choice = console.menu(_("Plugins:"), choices, padding=1) if choice == choices[0]: break plugin = plugins[choices.index(choice) - 1] console.write(" " + _("Configuration of") + " ", console.color("GB", False, "")) console.writeln(plugin, console.color("GB", True, "")) self.plugins[plugin].setup() config.save()
def source(self, args): for arg in args: (plugin, list) = self.__find(arg) if plugin == None: console.writeln( "No plugin with this name is present in the plugin database." ) return None import tempfile dir = "./" rep = self.__repManager.getRepository(list.repository) rep = rep(list.repository) if not rep.getPluginSource(list, plugin, dir): console.writeln( "Errors retriving the source package: %s-%s-src.tar.gz" % (plugin["name"][0]["value"], plugin["version"][0]["value"])) return None filename = dir + "/%s-%s-src.tar.gz" % ( plugin["name"][0]["value"], plugin["version"][0]["value"]) import tarfile console.writeln("Exctracting source package..") try: tarf = tarfile.open(filename.encode("ascii"), "r|gz") tarf.extractall(dir) except Exception: console.writeln("Error while exctracting source package!") return None console.writeln("%s source installed." % (plugin["name"][0]["value"]))
def __getRemoteFile(self, url,filename): import os (filepath, file) = os.path.split(filename) console.writeln("Downloading %s..\n" % (file)) try: urllib.urlretrieve(url, filename) except Exception: console.writeln("Error while retriving remote file!") return False return True
def setupEnd(self): """ Save config, etc """ self.config.save() with open(os.path.join(self.workDir, "pyggs", "version"), "w") as fp: fp.write(__version__) with open(os.path.join(self.workDir, "pyggs" , "profiles", self.profile, "version"), "w") as fp: fp.write(__version__) print() console.writeln(_("Note: You can always edit these setings by running pyggs with --setup (-s) switch."), console.color("G", True, ""))
def __getRemoteFile(self, url, filename): import os (filepath, file) = os.path.split(filename) console.writeln("Downloading %s..\n" % (file)) try: urllib.urlretrieve(url, filename) except Exception: console.writeln("Error while retriving remote file!") return False return True
def fullSetup(self): """ Full setup script. """ print() console.writeln(_("Entering full setup for profile {0}.").format(self.profile), console.color("G", True, "")) self.setupWorkDir() self.setupGeneral() self.setupGeocachingCom() self.setupOutput() self.setupPlugins() self.setupEnd()
def setupGeocachingCom(self): """ Config: geocaching.com section """ config = self.config config.assertSection("geocaching.com") print() console.writeln("Geocaching.com", console.color("G", True, "")) config.update("geocaching.com", "username", _("Username:"******"geocaching.com", "password", _("Password:"), validate=True) config.save()
def fullSetup(self): """ Full setup script. """ print() console.writeln( _("Entering full setup for profile {0}.").format(self.profile), console.color("G", True, "")) self.setupWorkDir() self.setupGeneral() self.setupGeocachingCom() self.setupOutput() self.setupPlugins() self.setupEnd()
def setupEnd(self): """ Save config, etc """ self.config.save() with open(os.path.join(self.workDir, "pyggs", "version"), "w") as fp: fp.write(__version__) with open( os.path.join(self.workDir, "pyggs", "profiles", self.profile, "version"), "w") as fp: fp.write(__version__) print() console.writeln( _("Note: You can always edit these setings by running pyggs with --setup (-s) switch." ), console.color("G", True, ""))
def setupGeneral(self): """ Config: general section """ config = self.config config.assertSection("general") print() console.writeln(_("General options"), console.color("G", True, "")) langs = globals()["langs"] config.update("general", "language", _("Please, select user interface language ({CHOICES})."), validate=list(langs.keys())) langs[config.get("general", "language")].install() print(" " + _("Enter your home coordinates in degrees as decimal number (N means positive value, S negative; E means positive value, W negative).")) config.update("general", "homelat", _("Latitude:"), validate=lambda val: None if re.search("^-?[0-9]+\.?[0-9]*$", val) is not None else _("Please, use decimal number.")) config.update("general", "homelon", _("Longitude:"), validate=lambda val: None if re.search("^-?[0-9]+\.?[0-9]*$", val) is not None else _("Please, use decimal number.")) config.save()
def setupOutput(self): """ Config: output section """ config = self.config config.assertSection("output") print() console.writeln(_("Output"), console.color("G", True, "")) templates = self.detectTemplates() print(" " + _("Templates are looked up in these directories (consecutively):") + "\n * " + "\n * ".join(self.templateDirs)) config.update("output", "template", _("Template ({CHOICES}):"), validate=templates) themes = self.detectThemes() print(" " + _("Themes are looked up in these directories (consecutively):") + "\n * " + "\n * ".join(self.themeDirs)) config.update("output", "theme", _("Theme ({CHOICES}):"), validate=themes) config.update("output", "directory", _("Output directory:"), validate=lambda val: None if os.path.isdir(os.path.expanduser(val)) else _("You have to input existing directory.")) config.save()
def setupPluginsEnable(self, plugin): """ Enable and setup plugin with all dependencies """ if hasattr(self.plugins[plugin], "setup"): console.write(" " + _("Configuration of") + " ", console.color("GB", False, "")) console.writeln(plugin, console.color("GB", True, "")) self.plugins[plugin].setup() loaded = [] for plugin in self.config.options("plugins"): if self.config.get("plugins", plugin) == "y": loaded.append(plugin) deps = self.findDeps(loaded) for plugin in deps: self.log.warn(_("Plugin {0} pulled in as dependency.").format(plugin)) self.config.set("plugins", plugin, "y") for plugin in deps: self.setupPluginsEnable(plugin) self.config.save()
def remove(self,args): console.write ("the following plugins will be removed:\n %s\n do you want to continue?[Y|n] " % (", ".join(args))) resp = string.lower(console.readln()) while not resp in ("y\n","n\n","\n"): console.write ("the following plugins will be removed:\n %s\n do you want to continue?[Y|n] " % (", ".join(args))) resp = string.lower(console.readln()) if resp == 'n\n': console.writeln ("Install aborted.") return None console.writeln ("") for arg in args: if not self.__dbManager.isPluginInstalled(arg): console.writeln("Plugin %s already not installed.\n" % (arg)) elif self.__dbManager.removePlugin(arg): console.writeln("Plugin %s removed.\n" % (arg)) else: console.writeln("Error while removing plugin %s.\n" % (arg))
def search(self, arg): arg = " ".join(arg) if config.verbose: results = [ "- " + plugin["name"][0]["value"] + " (compatible with GNU MyServer version [" + plugin.getMyServerMinVersion() + "," + plugin.getMyServerMinVersion() + "])\n " + plugin["description"][0]["value"] + "\n Dependences: " + " ".join(dep["value"] + "[" + dep["min-version"] + "," + dep["max-version"] + "]" for dep in plugin["depends"]) for plugin in self.__search(arg) ] else: results = [ plugin["name"][0]["value"] + " - " + plugin["description"][0]["value"] for plugin in self.__search(arg) ] console.writeln("\n".join(results))
def setupPluginsEnable(self, plugin): """ Enable and setup plugin with all dependencies """ if hasattr(self.plugins[plugin], "setup"): console.write(" " + _("Configuration of") + " ", console.color("GB", False, "")) console.writeln(plugin, console.color("GB", True, "")) self.plugins[plugin].setup() loaded = [] for plugin in self.config.options("plugins"): if self.config.get("plugins", plugin) == "y": loaded.append(plugin) deps = self.findDeps(loaded) for plugin in deps: self.log.warn( _("Plugin {0} pulled in as dependency.").format(plugin)) self.config.set("plugins", plugin, "y") for plugin in deps: self.setupPluginsEnable(plugin) self.config.save()
def sourceAuto(self, args): self.source(args) import os rootpath = os.path.abspath("./") for arg in args: import subprocess path = os.path.join(rootpath, arg) os.chdir(path) try: os.mkdir("bin") except Exception: pass print os.path.abspath("./") retcode = subprocess.call([ "scons", "plugin=" + arg, "command=build", "msheaders=" + config.MSHEADERS ]) if retcode == 0: import shutil os.chdir(rootpath) shutil.copytree(os.path.join(arg, "bin", arg), os.path.join(config.MYSERVER_PLUGIN_DIR, arg)) console.writeln("\n plugin %s installed." % (arg)) console.writeln("WARNING! no dependeces checked!") continue console.writeln( "Error while compiling the source package. check scons error message." )
def setupPlugins(self): """ Config: plugins section """ config = self.config config.assertSection("plugins") print() console.writeln(_("Plugins"), console.color("G", True, "")) # Remove not installed plugins installedPlugins = self.detectPlugins() for plugin in config.options("plugins"): if plugin not in installedPlugins: logging.debug("Removing not installed plugin {0}.".format(plugin)) config.remove_option("plugins", plugin) # Setup new found plugins for plugin in installedPlugins: if plugin not in config.options("plugins"): self.loadPlugin(plugin) console.writeln(" " + _("Plugin") + " " + plugin + ": " + self.plugins[plugin].about, console.color("G", False, "")) config.update("plugins", plugin, _("Enable") + " " + plugin + " ({CHOICES})?", validate=["y", "n"]) if config.get("plugins", plugin) == "y": self.setupPluginsEnable(plugin) print() config.save() plugins = config.options("plugins") plugins.sort() while True: choices = [] choices.append(_("Exit")) for plugin in plugins: self.loadPlugin(plugin) if config.get("plugins", plugin) == "y": choices.append("[x] {0:25s} {1}".format(plugin, self.plugins[plugin].about)) else: choices.append("[ ] {0:25s} {1}".format(plugin, self.plugins[plugin].about)) print() console.writeln(" " + _("Enable/Disable plugins menu"), console.color("RB", False, "")) choice = console.menu(_("Plugins:"), choices, padding=1) if choice == choices[0]: break plugin = plugins[choices.index(choice) - 1] if config.get("plugins", plugin) == "y": block = [] for bl in plugins: if plugin in self.plugins[bl].dependencies: block.append(bl) if len(block) > 0: self.log.error(_("Cannot disable plugin {0}, because {1} depend on it.").format(plugin, ", ".join(block))) else: print(" " + _("Disabling plugin {0}.").format(plugin)) config.set("plugins", plugin, "n") else: print(" " + _("Enabling plugin {0}.").format(plugin)) config.set("plugins", plugin, "y") self.setupPluginsEnable(plugin) config.save()
def remove(self, args): console.write( "the following plugins will be removed:\n %s\n do you want to continue?[Y|n] " % (", ".join(args))) resp = string.lower(console.readln()) while not resp in ("y\n", "n\n", "\n"): console.write( "the following plugins will be removed:\n %s\n do you want to continue?[Y|n] " % (", ".join(args))) resp = string.lower(console.readln()) if resp == 'n\n': console.writeln("Install aborted.") return None console.writeln("") for arg in args: if not self.__dbManager.isPluginInstalled(arg): console.writeln("Plugin %s already not installed.\n" % (arg)) elif self.__dbManager.removePlugin(arg): console.writeln("Plugin %s removed.\n" % (arg)) else: console.writeln("Error while removing plugin %s.\n" % (arg))
def sourceAuto(self,args): self.source(args) import os rootpath = os.path.abspath("./") for arg in args: import subprocess path = os.path.join(rootpath,arg) os.chdir(path) try: os.mkdir("bin") except Exception: pass print os.path.abspath("./") retcode = subprocess.call(["scons", "plugin="+arg,"command=build", "msheaders="+ config.MSHEADERS]) if retcode==0: import shutil os.chdir(rootpath) shutil.copytree(os.path.join(arg,"bin",arg),os.path.join(config.MYSERVER_PLUGIN_DIR,arg)) console.writeln("\n plugin %s installed." % (arg)) console.writeln("WARNING! no dependeces checked!") continue console.writeln("Error while compiling the source package. check scons error message.")
def setupPlugins(self): """ Config: plugins section """ config = self.config config.assertSection("plugins") print() console.writeln(_("Plugins"), console.color("G", True, "")) # Remove not installed plugins installedPlugins = self.detectPlugins() for plugin in config.options("plugins"): if plugin not in installedPlugins: logging.debug( "Removing not installed plugin {0}.".format(plugin)) config.remove_option("plugins", plugin) # Setup new found plugins for plugin in installedPlugins: if plugin not in config.options("plugins"): self.loadPlugin(plugin) console.writeln( " " + _("Plugin") + " " + plugin + ": " + self.plugins[plugin].about, console.color("G", False, "")) config.update("plugins", plugin, _("Enable") + " " + plugin + " ({CHOICES})?", validate=["y", "n"]) if config.get("plugins", plugin) == "y": self.setupPluginsEnable(plugin) print() config.save() plugins = config.options("plugins") plugins.sort() while True: choices = [] choices.append(_("Exit")) for plugin in plugins: self.loadPlugin(plugin) if config.get("plugins", plugin) == "y": choices.append("[x] {0:25s} {1}".format( plugin, self.plugins[plugin].about)) else: choices.append("[ ] {0:25s} {1}".format( plugin, self.plugins[plugin].about)) print() console.writeln(" " + _("Enable/Disable plugins menu"), console.color("RB", False, "")) choice = console.menu(_("Plugins:"), choices, padding=1) if choice == choices[0]: break plugin = plugins[choices.index(choice) - 1] if config.get("plugins", plugin) == "y": block = [] for bl in plugins: if plugin in self.plugins[bl].dependencies: block.append(bl) if len(block) > 0: self.log.error( _("Cannot disable plugin {0}, because {1} depend on it." ).format(plugin, ", ".join(block))) else: print(" " + _("Disabling plugin {0}.").format(plugin)) config.set("plugins", plugin, "n") else: print(" " + _("Enabling plugin {0}.").format(plugin)) config.set("plugins", plugin, "y") self.setupPluginsEnable(plugin) config.save()
def install(self,args): for arg in args: (plugin,list) = self.__find(arg) if plugin == None: console.writeln("No plugin with this name is present in the plugin database.") return None myserverVersion = self.__versionConverter(config.MYSERVER_VERSION) minversion = self.__versionConverter(plugin.getMyServerMinVersion()) maxversion = self.__versionConverter(plugin.getMyServerMaxVersion()) if myserverVersion < minversion or myserverVersion > maxversion: console.writeln("Plugin incompatible with GNU MyServer installed version.") return None toInstall = [(plugin,list)] (result,errors) = self.__recursiveDependencesChecker(plugin) if len(errors) != 0: for (plugin,msg) in errors: console.writeln("Error while install %s: %s" % (plugin["name"][0]["value"],msg)) return None toInstall.extend(result) console.write ("the following plugins will be installed:\n %s\n do you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"] for (plugin,list) in toInstall))) resp = string.lower(console.readln()) while not resp in ("y\n","n\n","\n"): console.write ("the following plugins will be installed:\n %s\n do you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"] for (plugin,list) in toInstall))) resp = string.lower(console.readln()) if resp == 'n\n': console.writeln ("Install aborted.") return None downloadErrors = [] for (plugin,list) in toInstall: if self.__dbManager.isPluginInstalled(plugin["name"][0]["value"]): console.writeln ("plugin %s already installed." % (plugin["name"][0]["value"])) continue rep = self.__repManager.getRepository(list.repository) rep = rep(list.repository) if not rep.getPluginBinary(list,plugin): downloadErrors.append(plugin) if len(downloadErrors) != 0: console.writeln ("Errors retriving the follow plugins packages: %s" % (" ".join("%s-%s-%s.tar.gz" % (plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch) for plugin in downloadErrors))) return None for (plugin,list) in toInstall: if self.__dbManager.isPluginInstalled(plugin["name"][0]["value"]): continue filename = config.MYSERVER_PLUGIN_DIR + "/%s-%s-%s.tar.gz" % (plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch) import tarfile console.writeln("Exctracting plugin package..") try: tarf = tarfile.open(filename.encode("ascii"),"r|gz") tarf.extractall (config.MYSERVER_PLUGIN_DIR) except Exception: console.writeln("Error while exctracting plugin package!") return None import os os.remove(filename) console.writeln("plugin %s installed.\n" % (plugin["name"][0]["value"]))
def install(self, args): for arg in args: (plugin, list) = self.__find(arg) if plugin == None: console.writeln( "No plugin with this name is present in the plugin database." ) return None myserverVersion = self.__versionConverter(config.MYSERVER_VERSION) minversion = self.__versionConverter( plugin.getMyServerMinVersion()) maxversion = self.__versionConverter( plugin.getMyServerMaxVersion()) if myserverVersion < minversion or myserverVersion > maxversion: console.writeln( "Plugin incompatible with GNU MyServer installed version.") return None toInstall = [(plugin, list)] (result, errors) = self.__recursiveDependencesChecker(plugin) if len(errors) != 0: for (plugin, msg) in errors: console.writeln("Error while install %s: %s" % (plugin["name"][0]["value"], msg)) return None toInstall.extend(result) console.write( "the following plugins will be installed:\n %s\n do you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"] for (plugin, list) in toInstall))) resp = string.lower(console.readln()) while not resp in ("y\n", "n\n", "\n"): console.write( "the following plugins will be installed:\n %s\n do you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"] for (plugin, list) in toInstall))) resp = string.lower(console.readln()) if resp == 'n\n': console.writeln("Install aborted.") return None downloadErrors = [] for (plugin, list) in toInstall: if self.__dbManager.isPluginInstalled( plugin["name"][0]["value"]): console.writeln("plugin %s already installed." % (plugin["name"][0]["value"])) continue rep = self.__repManager.getRepository(list.repository) rep = rep(list.repository) if not rep.getPluginBinary(list, plugin): downloadErrors.append(plugin) if len(downloadErrors) != 0: console.writeln( "Errors retriving the follow plugins packages: %s" % (" ".join("%s-%s-%s.tar.gz" % (plugin["name"][0]["value"], plugin["version"][0]["value"], config.arch) for plugin in downloadErrors))) return None for (plugin, list) in toInstall: if self.__dbManager.isPluginInstalled( plugin["name"][0]["value"]): continue filename = config.MYSERVER_PLUGIN_DIR + "/%s-%s-%s.tar.gz" % ( plugin["name"][0]["value"], plugin["version"][0]["value"], config.arch) import tarfile console.writeln("Exctracting plugin package..") try: tarf = tarfile.open(filename.encode("ascii"), "r|gz") tarf.extractall(config.MYSERVER_PLUGIN_DIR) except Exception: console.writeln("Error while exctracting plugin package!") return None import os os.remove(filename) console.writeln("plugin %s installed.\n" % (plugin["name"][0]["value"]))