예제 #1
0
파일: __init__.py 프로젝트: AloneRoad/waskr
 def enable_plugins(self):
     try:
         plugin_path = self.config['plugin_path']
         plugins = self.config['plugins'].split(' ')
     except KeyError:
         return False
     except AttributeError:
         return False
     if plugin_path is False or plugins is None:
         return False
     else:
         init_plugin_system({'plugin_path': plugin_path, 'plugins': plugins})
         find_plugins()
예제 #2
0
 def enable_plugins(self):
     try:
         plugin_path = self.config['plugin_path']
         plugins = self.config['plugins'].split(' ')
     except KeyError:
         return False
     except AttributeError:
         return False
     if plugin_path is False or plugins is None:
         return False
     else:
         init_plugin_system({
             'plugin_path': plugin_path,
             'plugins': plugins
         })
         find_plugins()
예제 #3
0
파일: __init__.py 프로젝트: AloneRoad/waskr
    def parseArgs(self, argv):
        parser = OptionParser(description="""
A stats engine for WSGI applications
    """
        ,version='0.0.9')

        parser.add_option('--server', action='store_true', help="""Runs the web server. 
 If no configuration file is passed localhost and port 8080 is used.""")
        parser.add_option('--add-config', 
                help="""Adds (overwrites) a config file to the command line app""")
        parser.add_option('--config-values', action="store_true", 
                help="""Show the current parsed config values""")

        # Plugin Group
        plugin_group = OptionGroup(parser, "Plugin Options", "Extend via\
 plugins that can run with this command line tool. If activated you should see\
 them displayed here.")

        if self.check_config() and self.enable_plugins() is not False:
            from waskr.plugins import find_plugins
            self.got_plugins = True
            plugin_options = {}
            for plugin in find_plugins():
                try:
                    cmd = plugin()
                    cmd.config = self.config
                    info = cmd.command()
                    # register it with OptParse to avoid errors
                    plugin_group.add_option(info['option'], action=info['action'],
                        help=info['description'])

                    # now register with a dict so we now what to call when we hit 
                    # that option 
                    plugin_options[info['option']] = cmd 

                except AttributeError:
                    pass # You may have not added what we need to implement
                         # your plugin

        parser.add_option_group(plugin_group)

        options, arguments = parser.parse_args()

        if options.add_config:
            self.add_config(options.add_config)

        # make sure we have a config to work with 
        if self.check_config() == False:
            self.msg(msg=WARNING, std="err")

        if len(sys.argv) <= 1:
            parser.print_help()

        if options.config_values:
            self.config_values()
   
        if options.server:
            # imports here to avoid db connection errors
            from waskr.web import server
            server.CONF = self.config
            server.main(self.config)

        # if we hit the end of *our* options, loop over the plugin options: 
        elif self.got_plugins:
            for i in plugin_options:
                if i in sys.argv[1:]:
                    obj = plugin_options[i]
                    option_value = None
                    if len(sys.argv) == 3:
                        option_value = sys.argv[2] 
                    obj.run(option_value)
예제 #4
0
    def parseArgs(self, argv):
        parser = OptionParser(description="""
A stats engine for WSGI applications
    """,
                              version='0.0.9')

        parser.add_option('--server',
                          action='store_true',
                          help="""Runs the web server. 
 If no configuration file is passed localhost and port 8080 is used.""")
        parser.add_option(
            '--add-config',
            help="""Adds (overwrites) a config file to the command line app""")
        parser.add_option('--config-values',
                          action="store_true",
                          help="""Show the current parsed config values""")

        # Plugin Group
        plugin_group = OptionGroup(
            parser, "Plugin Options", "Extend via\
 plugins that can run with this command line tool. If activated you should see\
 them displayed here.")

        if self.check_config() and self.enable_plugins() is not False:
            from waskr.plugins import find_plugins
            self.got_plugins = True
            plugin_options = {}
            for plugin in find_plugins():
                try:
                    cmd = plugin()
                    cmd.config = self.config
                    info = cmd.command()
                    # register it with OptParse to avoid errors
                    plugin_group.add_option(info['option'],
                                            action=info['action'],
                                            help=info['description'])

                    # now register with a dict so we now what to call when we hit
                    # that option
                    plugin_options[info['option']] = cmd

                except AttributeError:
                    pass  # You may have not added what we need to implement
                    # your plugin

        parser.add_option_group(plugin_group)

        options, arguments = parser.parse_args()

        if options.add_config:
            self.add_config(options.add_config)

        # make sure we have a config to work with
        if self.check_config() == False:
            self.msg(msg=WARNING, std="err")

        if len(sys.argv) <= 1:
            parser.print_help()

        if options.config_values:
            self.config_values()

        if options.server:
            # imports here to avoid db connection errors
            from waskr.web import server
            server.CONF = self.config
            server.main(self.config)

        # if we hit the end of *our* options, loop over the plugin options:
        elif self.got_plugins:
            for i in plugin_options:
                if i in sys.argv[1:]:
                    obj = plugin_options[i]
                    option_value = None
                    if len(sys.argv) == 3:
                        option_value = sys.argv[2]
                    obj.run(option_value)