コード例 #1
0
ファイル: waskrc.py プロジェクト: pombredanne/waskr
def main():
    """Handle all options"""
    parser = OptionParser(description="""WASKR Command Line Utility""",
                          version=__version__)
    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('--conf', help="""Pass a INI configuration file""")
    parser.add_option('--add-user',
                      help="""Adds a user email for the web interface""")
    parser.add_option('--remove-user',
                      help="""Removes a user email from the web interface""")

    options, arguments = parser.parse_args()

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

    if options.server:
        if options.conf and path.isfile(options.conf):
            configuration = config.options(options.conf)
            server.CONF = configuration
            server.main(configuration)
        else:
            server.main()

    if options.add_user and options.conf:
        try:
            config = config.options(options.conf)
            db = database.Stats(config)
            db.add_user(options.add_user)
            print "User %s was added to the DB" % options.add_user
        except Exception, e:
            print 'waskrc could not add user: %s' % e
コード例 #2
0
ファイル: main.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('--conf', help="""Pass a INI configuration file""")
        parser.add_option('--add-user', help="""Adds a user email for the web interface""")
        parser.add_option('--remove-user', help="""Removes a user email from the web interface""")

        options, arguments = parser.parse_args()

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

   
        if options.server:
            if options.conf and path.isfile(options.conf):
                configuration = config.options(options.conf)
                server.CONF = configuration
                server.main(configuration)
            else:        
                server.main()

        if options.add_user and options.conf:
            try:
                config = config.options(options.conf)
                db = database.Stats(config)
                db.add_user(options.add_user)
                print "User %s was added to the DB" % options.add_user
            except Exception, e:
                print 'waskrc could not add user: %s' % e
コード例 #3
0
ファイル: waskrc.py プロジェクト: pombredanne/waskr
def main():
    """Handle all options"""
    parser = OptionParser(description="""WASKR Command Line Utility""", version=__version__)
    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("--conf", help="""Pass a INI configuration file""")
    parser.add_option("--add-user", help="""Adds a user email for the web interface""")
    parser.add_option("--remove-user", help="""Removes a user email from the web interface""")

    options, arguments = parser.parse_args()

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

    if options.server:
        if options.conf and path.isfile(options.conf):
            configuration = config.options(options.conf)
            server.CONF = configuration
            server.main(configuration)
        else:
            server.main()

    if options.add_user and options.conf:
        try:
            config = config.options(options.conf)
            db = database.Stats(config)
            db.add_user(options.add_user)
            print "User %s was added to the DB" % options.add_user
        except Exception, e:
            print "waskrc could not add user: %s" % e
コード例 #4
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)
コード例 #5
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)