Example #1
0
 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()
Example #2
0
    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()
Example #3
0
 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()
Example #4
0
    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()
Example #5
0
    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()
Example #6
0
    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()
Example #7
0
    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()
Example #8
0
    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()
Example #9
0
    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()
Example #10
0
    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()
Example #11
0
 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()
Example #12
0
 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, ""))
Example #13
0
    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()
Example #14
0
    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()
Example #15
0
    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()
Example #16
0
 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()
Example #17
0
 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, ""))
Example #18
0
    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()