예제 #1
0
def run_command(db, cmd, args):
    func = get_command_by_name(db, cmd)
    try:
        if commands[func].locking:
            db.execute(u'begin')
        commands[func](db, args)
        if commands[func].locking:
            db.execute(u'commit')
        current_sheet = dbutil.get_current_sheet(db)
        if not commands[func].read_only:
            if db.config.has_option(current_sheet, 'reporting_url'):
                current_info = dbutil.get_active_info(db, current_sheet)
                status_string = dbutil.get_status_string(db,
                                                         current_sheet,
                                                         exclude=['billable'])
                report_to_url(
                    db.config.get(current_sheet,
                                  'reporting_url'), None, status_string,
                    (datetime.utcnow() - timedelta(seconds=current_info[0])
                     ).strftime("%Y-%m-%d %H:%M:%S") if current_info else '',
                    datetime.now() - timedelta(seconds=current_info[0])
                    if current_info else timedelta(seconds=0),
                    current_info[0] if current_info else 0, cmd, args)
    except Exception:
        import traceback
        traceback.print_exc()
        if commands[func].locking:
            db.execute(u'rollback')
        raise
예제 #2
0
def now(db, args):
    parser = optparse.OptionParser(usage='''usage: %prog now [TIMESHEET]

Print the current sheet, whether it's active, and if so, how long it
has been active and what notes are associated with the current
period.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s', '--simple', dest='simple',
                      action='store_true', help='Only display the name \
of the current timesheet.')
    opts, args = parser.parse_args(args=args)

    if opts.simple:
        print dbutil.get_current_sheet(db)
        return

    if args:
        sheet = cmdutil.complete(dbutil.get_sheet_names(db), args[0],
                                 'timesheet')
    else:
        sheet = dbutil.get_current_sheet(db)

    entry_count = dbutil.get_entry_count(db, sheet)
    if entry_count == 0:
        raise SystemExit('%(prog)s: error: sheet is empty. For program \
usage, see "%(prog)s --help".' % {'prog': os.path.basename(sys.argv[0])})
    running = dbutil.get_active_info(db, sheet)
    if running:
        duration = str(timedelta(seconds=running[0]))
    status_string = dbutil.get_status_string(db, sheet)
    if status_string:
        print '%s: %s (%s)' % (
            sheet,
            duration,
            status_string
        )
    elif running:
        print '%s: (active)' % sheet
    else:
        print '%s: (inactive)' % sheet
예제 #3
0
def now(db, args):
    parser = optparse.OptionParser(usage='''usage: %prog now [TIMESHEET]

Print the current sheet, whether it's active, and if so, how long it
has been active and what notes are associated with the current
period.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s',
                      '--simple',
                      dest='simple',
                      action='store_true',
                      help='Only display the name \
of the current timesheet.')
    opts, args = parser.parse_args(args=args)

    if opts.simple:
        print dbutil.get_current_sheet(db)
        return

    if args:
        sheet = cmdutil.complete(dbutil.get_sheet_names(db), args[0],
                                 'timesheet')
    else:
        sheet = dbutil.get_current_sheet(db)

    entry_count = dbutil.get_entry_count(db, sheet)
    if entry_count == 0:
        raise SystemExit('%(prog)s: error: sheet is empty. For program \
usage, see "%(prog)s --help".' % {'prog': os.path.basename(sys.argv[0])})
    running = dbutil.get_active_info(db, sheet)
    if running:
        duration = str(timedelta(seconds=running[0]))
    status_string = dbutil.get_status_string(db, sheet)
    if status_string:
        print '%s: %s (%s)' % (sheet, duration, status_string)
    elif running:
        print '%s: (active)' % sheet
    else:
        print '%s: (inactive)' % sheet
예제 #4
0
def run_command(db, cmd, args):
    func = get_command_by_name(db, cmd)
    try:
        if commands[func].locking:
            db.execute(u'begin')
        commands[func](db, args)
        if commands[func].locking:
            db.execute(u'commit')
        current_sheet = dbutil.get_current_sheet(db)
        if not commands[func].read_only:
            if db.config.has_option(
                        current_sheet,
                        'reporting_url'
                    ):
                current_info = dbutil.get_active_info(db, current_sheet)
                status_string = dbutil.get_status_string(
                    db,
                    current_sheet,
                    exclude=['billable']
                )
                report_to_url(
                        db.config.get(current_sheet, 'reporting_url'),
                        None,
                        status_string,
                        (
                            datetime.utcnow()
                            - timedelta(seconds=current_info[0])
                        ).strftime("%Y-%m-%d %H:%M:%S")
                        if current_info else '',
                        datetime.now() - timedelta(seconds=current_info[0]) if current_info else timedelta(seconds=0),
                        current_info[0] if current_info else 0,
                        cmd,
                        args
                    )
    except Exception:
        import traceback
        traceback.print_exc()
        if commands[func].locking:
            db.execute(u'rollback')
        raise