def _wrapped_view_func(*args, **kwargs): try: user = request.environ.get('TIMEBOOK_USER') human_username = get_human_username(user) config_file = os.path.expanduser("~%s/.config/timebook/timebook.ini" % user) timesheet_db = os.path.expanduser("~%s/.config/timebook/sheets.db" % user) config = parse_config(config_file) config.add_section('temp') config.set('temp', 'human_name', human_username) cursor = Database( timesheet_db, config, ) if("TIMEBOOK_LOG_FILE" in request.environ.keys()): from logging.handlers import RotatingFileHandler file_handler = RotatingFileHandler( request.environ.get('TIMEBOOK_LOG_FILE'), maxBytes=2 ** 20, backupCount=1, ) file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler) logger.addHandler(file_handler) logger.info(cursor.config) return view_func(cursor, config, *args, **kwargs) except Exception as e: import traceback return error_view("Error encountered: %s" % traceback.format_exc())
def _wrapped_view_func(*args, **kwargs): try: user = request.environ.get('TIMEBOOK_USER') human_username = get_human_username(user) config_file = os.path.expanduser( "~%s/.config/timebook/timebook.ini" % user) timesheet_db = os.path.expanduser( "~%s/.config/timebook/sheets.db" % user) config = parse_config(config_file) config.add_section('temp') config.set('temp', 'human_name', human_username) cursor = Database( timesheet_db, config, ) if ("TIMEBOOK_LOG_FILE" in request.environ.keys()): from logging.handlers import RotatingFileHandler file_handler = RotatingFileHandler( request.environ.get('TIMEBOOK_LOG_FILE'), maxBytes=2**20, backupCount=1, ) file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler) logger.addHandler(file_handler) logger.info(cursor.config) return view_func(cursor, config, *args, **kwargs) except Exception as e: import traceback return error_view("Error encountered: %s" % traceback.format_exc())
def run_from_cmdline(): parser = make_parser() options, args = parse_options(parser) config = parse_config(options.config) db = Database(options.timebook, config) cmd, args = args[0], args[1:] try: run_command(db, cmd, args) except NoMatch, e: parser.error('%s' % e.args[0])
def run_from_cmdline(argv=[]): args = parse_args(argv) config = parse_config(os.path.expanduser(args['--config'])) db = Database(os.path.expanduser(args['--timebook']), config) cmd, args = args['<command>'], args['<args>'] try: run_command(db, cmd, args) except NoMatch as e: raise SystemExit(e.args[0]) except AmbiguousLookup as e: raise SystemExit('%s\n %s' % (e.args[0], ' '.join(e.args[1])))
def run_from_cmdline(): parser = make_parser() options, args = parse_options(parser) config = parse_config(options.config) db = Database(options.timebook, config) cmd, args = args[0], args[1:] try: run_command(db, cmd, args) except NoMatch as e: parser.error('%s' % e.args[0]) except AmbiguousLookup as e: parser.error('%s\n %s' % (e.args[0], ' '.join(e.args[1]))) except CommandError as e: parser.error("%s" % e)
def test_parse_config(capsys): seed = binascii.hexlify(os.urandom(4)) fname = os.path.join(tempfile.gettempdir(), 'test-%s' % seed, 'test_timebook_config.ini') parse_config(fname) shutil.rmtree(os.path.dirname(fname))