Пример #1
0
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
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
Пример #3
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('--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
 def __init__(self, config=None, test=False):
     config = options(config)
     try:
         self.connection = Connection(
                 config['db_host'], 
                 int(config['db_port']))
     except Exception, error:
         log.database.critical("Could not connect to MongoDB: %s" % error)
Пример #5
0
 def config_values(self):
     try:
         config_list = [i for i in self.db.get_config_path()]
         config_file = config_list[0][0]
         config = config.options(config_file)
         print "\nConfiguration file: %s\n" % config_file
         for i in config.items():
             print "%-15s= %-4s" % (i[0], i[1])
     except Exception, error:
         print "Could not complete command: %s" % error 
Пример #6
0
 def check_config(self):
     # if any commands are run, check for a MASTER config file Location
     config_db = self.db.get_config_path()
     config_file = None
     try:
         config_list = [i for i in self.db.get_config_path()]
         config_file = config_list[0][0]
         config = config.options(config_file)
         return config
     except IndexError:
         self.msg(msg=WARNING, std="err")
Пример #7
0
 def check_config(self):
     # if any commands are run, check for a MASTER config file Location
     config_db = self.db.get_config_path()
     config_file = None
     try:
         config_list = [i for i in self.db.get_config_path()]
         config_file = config_list[0][0]
         conf = options(config_file)
         self.config = conf
         return conf
     except IndexError:
         return False
Пример #8
0
 def check_config(self):
     # if any commands are run, check for a MASTER config file Location
     config_db = self.db.get_config_path()
     config_file = None
     try:
         config_list = [i for i in self.db.get_config_path()]
         config_file = config_list[0][0]
         conf = options(config_file)
         self.config = conf
         return conf
     except IndexError:
         return False
Пример #9
0
 def __init__(self, config=None, test=False):
     config = options(config)
     self.db = self._location_verify(config['db_location'])
     self.table = 'stats'
     if test:
         self.table = 'test_stats'    
    
     self.conn = sqlite3.connect(self.db)
     self.c = self.conn.cursor()
     self.c.execute(STATS_TABLE % self.table)
     self.conn.commit()
     
     log.database.debug("database connection initialized Sqlite3")
Пример #10
0
    def __init__(self, app, config=None, framework_config=None):
        """Initialize the RequestStats Middleware
        Every single request will get logged with a unix timestamp
        the time it took to respond and the url that was requested.
        The dictionary is passed on the RequestParser that deals
        with building the cache and submitting the data to 
        the queue.
        """
        self.app = app

        self.config = options(config, framework_config)
        self.parser = RequestParser(self.config)

        setlogging(self.config)
        log.middleware.debug('middleware Initialized')
Пример #11
0
 def test_options_ini_no_webport(self):
     actual = options('conf_seven.ini')
     expected = {
             'db_engine':'sqlite',
             'db_location':'/tmp',
             'web_password': False,
             'plugins': None,
             'plugin_path': False,
             'server_id': '2',
             'db_host': 'remote.example.com',
             'db_port': '00000',
             'application': 'secondary',
             'web_host': 'web.example.com',
             'cache': '10',
             'web_port': '8080',
             'log_level': 'DEBUG',
             'log_format': '%(asctime)s %(levelname)s %(name)s  %(message)s',
             'log_datefmt' : '%H:%M:%S'
             }    
     self.assertEqual(actual, expected)
Пример #12
0
 def test_framework_config(self):
     actual = options(framework_config=self.pylons_config)
     expected ={
         'server_id': 2,
         'db_engine':'sqlite',
         'db_location':'/tmp',
         'db_host': 'remote.example.com',
         'db_port': 4444,
         'application': 'secondary',
         'web_host': 'web.example.com',
         'web_port': '8080',
         'web_password': False,
         'plugins': None,
         'plugin_path': False,
         'cache': 20,
         'log_level': 'DEBUG',
         'log_format': '%(asctime)s %(levelname)s %(name)s  %(message)s',
         'log_datefmt' : '%H:%M:%S'
         } 
     self.assertEqual(actual, expected) 
Пример #13
0
 def test_custom_plugin_none(self):
     """When bad configured it will not display or get parsed"""
     actual = options('conf_nine.ini')
     expected = {
             'db_engine':'sqlite',
             'db_location':'/tmp',
             'web_password': False,
             'plugins': None,
             'plugin_path': False,
             'server_id': '2',
             'db_host': 'remote.example.com',
             'db_port': '00000',
             'application': 'secondary',
             'web_host': 'web.example.com',
             'cache': '10',
             'web_port': '8080',
             'log_level': 'DEBUG',
             'log_format': '%(asctime)s %(levelname)s %(name)s  %(message)s',
             'log_datefmt' : '%H:%M:%S'
             }    
     self.assertEqual(actual, expected)
Пример #14
0
 def test_options_empty(self):
     actual = options()
     expected = self.defaults
     self.assertEqual(actual, expected)
Пример #15
0
 def __init__(self, config=None, test=False):
     self.config = options(config)
     self.engine = self._load_engine()
     self.stats = self.engine.Stats(config, test)
Пример #16
0
 def __init__(self, config=None, test=False):
     self.config = options(config)
     self.engine = self._load_engine()
     self.stats = self.engine.Stats(config, test)
Пример #17
0
from os import path

from bottle import response, request, redirect, route, run, view, send_file, local, TEMPLATE_PATH 
from waskr import log
from waskr.config import options, setlogging
from waskr.database import Stats

# Fixes a call from a different path
CWD = path.abspath(__file__)
APP_CWD = path.dirname(CWD)
view_dir = APP_CWD+'/views'
TEMPLATE_PATH.append(view_dir)

# Initialize the CONF with proper values
CONF = options()

# Initialize logging
setlogging(CONF)
log.server.debug("initialized logging")


@route('/')
@view('index')
def index():
    logged_in()
    return dict(last_received=local.db.last_insert(),
                apps=local.db.apps_nodes())


@route('/application/:name/:type')
@route('/application/:name/:type/:minutes')
Пример #18
0
 def test_options_typeError(self):
     actual = options(['a list should never be passed'])
     expected = self.defaults
     self.assertEqual(actual, expected)
Пример #19
0
from os import path

from bottle import response, request, redirect, route, run, view, send_file, local, TEMPLATE_PATH
from waskr import log
from waskr.config import options, setlogging
from waskr.database import Stats

# Fixes a call from a different path
CWD = path.abspath(__file__)
APP_CWD = path.dirname(CWD)
view_dir = APP_CWD + '/views'
TEMPLATE_PATH.append(view_dir)

# Initialize the CONF with proper values
CONF = options()

# Initialize logging
setlogging(CONF)
log.server.debug("initialized logging")


@route('/')
@view('index')
def index():
    logged_in()
    return dict(last_received=local.db.last_insert(),
                apps=local.db.apps_nodes())


@route('/application/:name/:type')
@route('/application/:name/:type/:minutes')
Пример #20
0
    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

    if options.remove_user and options.conf:
        try:
            config = config.options(options.conf)
            db = database.Stats(config)
            db.remove_user(options.add_user)
            print "User %s removed from DB" % options.remove_user
        except Exception, e:
            print 'waskrc could not remove user: %s' % e


if __name__ == "__main__":
    main()
Пример #21
0
    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

    if options.remove_user and options.conf:
        try:
            config = config.options(options.conf)
            db = database.Stats(config)
            db.remove_user(options.add_user)
            print "User %s removed from DB" % options.remove_user
        except Exception, e:
            print "waskrc could not remove user: %s" % e


if __name__ == "__main__":
    main()
Пример #22
0
 def test_options_invalid_file(self):
     actual = options('/path/to/invalid/file.txt')
     expected = self.defaults
     self.assertEqual(actual, expected)
Пример #23
0
 def test_options_TypeError(self):
     actual = options(config={})
     expected = self.defaults
     self.assertEqual(actual, expected)
Пример #24
0
                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
        
        if not options.conf:
            config = config.options('app.ini')
            db = database.Stats(config)

        if options.remove_user and options.conf:
            try:
                config = config.options(options.conf)
                db = database.Stats(config)
                db.remove_user(options.add_user)
                print "User %s removed from DB" % options.remove_user
            except Exception, e:
                print 'waskrc could not remove user: %s' % e

 

main = WaskrCommands
Пример #25
0
 def test_options_Error_string(self):
     actual = options('a string should never be passed')
     expected = self.defaults
     self.assertEqual(actual, expected)