Exemplo n.º 1
0
def main(args):
    configure_logging(stdout_level=logging.ERROR)

    from samovar import options
    from samovar.config import Configuration
    from samovar.parsing import StatusStyle, StatusLexer

    class Samovar(Application):
        def __init__(self):
            super(Samovar, self).__init__(args, ['samovar.commands'], {
                'description'        : 'Samovar',
                'options'            : options.OPTIONS,
                'defaults'           : options.DEFAULTS,
                'check_and_set_func' : options.check_and_set_func,
            }, os.path.join(system.get_appdata(), 'Samovar', 'Samovar.json'),
            Configuration)
            self._ui.formatter.style = StatusStyle
            self._ui.formatter.lexer = StatusLexer()

        # HACK: This is a hack for configuring the logging after the
        #       options and configuration file is loaded. Should be
        #       changed somehow :-/
        def preparse(self, *args, **kwargs):
            parser, args, config = super(Samovar, self).preparse(*args, **kwargs)
            logfile = config.get('logfile', config.get('options.logfile'))
            if logfile:
                configure_logging(logfile, initial_file_message='Starting Samovar',
                                  level=logging.INFO, stdout_level=logging.CRITICAL)
            else:
                configure_logging(stdout_level=logging.WARNING)
            return parser, args, config

    app = Samovar()
    app.execute()
Exemplo n.º 2
0
 def preparse(self, *args, **kwargs):
     parser, args, config = super(Samovar, self).preparse(*args, **kwargs)
     logfile = config.get('logfile', config.get('options.logfile'))
     if logfile:
         configure_logging(logfile, initial_file_message='Starting Samovar',
                           level=logging.INFO, stdout_level=logging.CRITICAL)
     else:
         configure_logging(stdout_level=logging.WARNING)
     return parser, args, config
Exemplo n.º 3
0
def main(args=None, port=8000, debug=False):
    ss = Settings()
    configure_logging(os.path.join(ss.paths['log'], 'starlogs.log'))
    try:
        application = Application(ss, debug)
        # Start Web Server
        application.listen(port)
        ioloop.IOLoop.instance().start()
    except:
        logger.exception('Board crashed')
Exemplo n.º 4
0
def main(args=None, port=8000, debug=False):
    ss = Settings()
    configure_logging(os.path.join(ss.paths['log'], 'starlogs.log'))
    try:
        application = Application(ss, debug)
        # Start Web Server
        application.listen(port)
        ioloop.IOLoop.instance().start()
    except:
        logger.exception('Board crashed')
Exemplo n.º 5
0
 def preparse(self, *args, **kwargs):
     parser, args, config = super(Samovar,
                                  self).preparse(*args, **kwargs)
     logfile = config.get('logfile', config.get('options.logfile'))
     if logfile:
         configure_logging(logfile,
                           initial_file_message='Starting Samovar',
                           level=logging.INFO,
                           stdout_level=logging.CRITICAL)
     else:
         configure_logging(stdout_level=logging.WARNING)
     return parser, args, config
Exemplo n.º 6
0
def main(args):
    # Configure logger
    import logging
    from tea.logger import configure_logging

    configure_logging(stdout_level=logging.WARNING)

    if len(args) == 0:
        print_help()
    else:
        command = args[0]
        if command == "help" or command not in commands:
            return print_help()
        else:
            args = args[1:]
            # get specs
            iterable, params, required = commands[command]
            # import function
            from tea import shell

            func = getattr(shell, command)
            if not (required <= len(args) <= len(params)):
                return print_func_help(func, required)
            parsed_args = []
            for i, arg in enumerate(args):
                try:
                    parsed_args.append(params[i](arg))
                except Exception:
                    print("Failed to parse argument: %s" % arg)
                    return 1
            try:
                if iterable:
                    for i in func(*parsed_args):
                        print(i)
                else:
                    if func(*parsed_args):
                        print("OK")
                        return 0
                    else:
                        print("FAILED")
                        return 1
            except Exception as e:
                print("ERROR: %s" % e)
                return 1
            return 0
Exemplo n.º 7
0
def main(args):
    # Configure logger
    import logging
    from tea.logger import configure_logging
    configure_logging(stdout_level=logging.WARNING)

    if len(args) == 0:
        print_help()
    else:
        command = args[0]
        if command == 'help' or command not in commands:
            return print_help()
        else:
            args = args[1:]
            # get specs
            iterable, params, required = commands[command]
            # import function
            from tea import shell
            func = getattr(shell, command)
            if not (required <= len(args) <= len(params)):
                return print_func_help(func, required)
            parsed_args = []
            for i, arg in enumerate(args):
                try:
                    parsed_args.append(params[i](arg))
                except:
                    print('Failed to parse argument: %s' % arg)
                    return 1
            try:
                if iterable:
                    for i in func(*parsed_args):
                        print(i)
                else:
                    if func(*parsed_args):
                        print('OK')
                        return 0
                    else:
                        print('FAILED')
                        return 1
            except Exception as e:
                print('ERROR: %s' % e)
                return 1
            return 0
Exemplo n.º 8
0
def main(args):
    configure_logging(stdout_level=logging.ERROR)

    from samovar import options
    from samovar.config import Configuration
    from samovar.parsing import StatusStyle, StatusLexer

    class Samovar(Application):
        def __init__(self):
            super(Samovar, self).__init__(
                args, ['samovar.commands'], {
                    'description': 'Samovar',
                    'options': options.OPTIONS,
                    'defaults': options.DEFAULTS,
                    'check_and_set_func': options.check_and_set_func,
                }, os.path.join(system.get_appdata(), 'Samovar',
                                'Samovar.json'), Configuration)
            self._ui.formatter.style = StatusStyle
            self._ui.formatter.lexer = StatusLexer()

        # HACK: This is a hack for configuring the logging after the
        #       options and configuration file is loaded. Should be
        #       changed somehow :-/
        def preparse(self, *args, **kwargs):
            parser, args, config = super(Samovar,
                                         self).preparse(*args, **kwargs)
            logfile = config.get('logfile', config.get('options.logfile'))
            if logfile:
                configure_logging(logfile,
                                  initial_file_message='Starting Samovar',
                                  level=logging.INFO,
                                  stdout_level=logging.CRITICAL)
            else:
                configure_logging(stdout_level=logging.WARNING)
            return parser, args, config

    app = Samovar()
    app.execute()
Exemplo n.º 9
0
 def setUp(self):
     self.output_filename = tempfile.mktemp()
     configure_logging(self.output_filename, level=logging.DEBUG)
     self.logger = logging.getLogger(__name__)
     self.output_test_file = open(self.output_filename)
Exemplo n.º 10
0
 def setUp(self):
     self.output_filename = tempfile.mktemp()
     configure_logging(self.output_filename, level=logging.DEBUG)
     self.logger = logging.getLogger(__name__)
     self.output_test_file = open(self.output_filename)