Ejemplo n.º 1
0
def switch(db, timesheet, verbose=False):
    """Switch to a new timesheet

    Usage: t switch [options] <timesheet>

    Switch to a new timesheet. This causes all future operation (except switch)
    to operate on that timesheet. The default timesheet is called
    "default".

    Options:
      -v, --verbose  Print the name and number of entries of the timesheet.
    """
    # optimization: check that the given timesheet is not already
    # current. updates are far slower than selects.
    if dbutil.get_current_sheet(db) != timesheet:
        db.execute('''
        update
            meta
        set
            value = ?
        where
            key = 'current_sheet'
        ''', (timesheet,))

    if verbose:
        entry_count = dbutil.get_entry_count(db, timesheet)
        if entry_count == 0:
            print('switched to empty timesheet "%s"' % timesheet)
        else:
            print(ngettext(
                'switched to timesheet "%s" (1 entry)' % timesheet,
                'switched to timesheet "%s" (%s entries)' % (
                    timesheet, entry_count), entry_count))
Ejemplo n.º 2
0
def now(db, args):
    parser = 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.')
    parser.add_option('-n',
                      '--notes',
                      dest='notes',
                      action='store_true',
                      help='Only display the notes \
associated with the current period.')
    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)
    notes = ''
    if running is None:
        active = 'not active'
    else:
        duration = str(timedelta(seconds=running[0]))
        if running[1]:
            notes = running[1].rstrip('.')
            active = '%s (%s)' % (duration, notes)
        else:
            active = duration
    if opts.notes:
        print notes
    else:
        print '%s: %s' % (sheet, active)
Ejemplo n.º 3
0
def now(db, args):
    parser = 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.')
    parser.add_option('-n', '--notes', dest='notes',
                      action='store_true', help='Only display the notes \
associated with the current period.')
    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)
    notes = ''
    if running is None:
        active = 'not active'
    else:
        duration = str(timedelta(seconds=running[0]))
        if running[1]:
            notes = running[1].rstrip('.')
            active = '%s (%s)' % (duration, notes)
        else:
            active = duration
    if opts.notes:
        print notes
    else:
        print '%s: %s' % (sheet, active)
Ejemplo n.º 4
0
def now(db, timesheet=None, simple=False, notes=False):
    """Show the status of the current timesheet

    Usage: t (now | info) [options] [<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.

    Options:
      -s, --simple  Only display the name of the current timesheet.
      -n, --notes   Only display the notes associated with the current period.
    """
    if simple:
        print(dbutil.get_current_sheet(db))
        return

    if timesheet:
        sheet = cmdutil.complete(dbutil.get_sheet_names(db), timesheet,
                                 '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)
    _notes = ''
    if running is None:
        active = 'not active'
    else:
        duration = str(timedelta(seconds=running[0]))
        if running[1]:
            _notes = running[1].rstrip('.')
            active = '%s (%s)' % (duration, _notes)
        else:
            active = duration
    if notes:
        print(_notes)
    else:
        print('%s: %s' % (sheet, active))
Ejemplo n.º 5
0
def switch(db, args):
    parser = OptionParser(usage='''usage: %prog switch TIMESHEET

Switch to a new timesheet. This causes all future operation (except switch)
to operate on that timesheet. The default timesheet is called
"default".''')
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='Print the name and \
number of entries of the timesheet.')
    opts, args = parser.parse_args(args=args)
    if len(args) != 1:
        parser.error('no timesheet given')

    sheet = args[0]

    # optimization: check that the given timesheet is not already
    # current. updates are far slower than selects.
    if dbutil.get_current_sheet(db) != sheet:
        db.execute(
            u'''
        update
            meta
        set
            value = ?
        where
            key = 'current_sheet'
        ''', (args[0], ))

    if opts.verbose:
        entry_count = dbutil.get_entry_count(db, sheet)
        if entry_count == 0:
            print u'switched to empty timesheet "%s"' % sheet
        else:
            print ngettext(
                u'switched to timesheet "%s" (1 entry)' % sheet,
                u'switched to timesheet "%s" (%s entries)' %
                (sheet, entry_count), entry_count)
Ejemplo n.º 6
0
def switch(db, args):
    parser = OptionParser(usage='''usage: %prog switch TIMESHEET

Switch to a new timesheet. This causes all future operation (except switch)
to operate on that timesheet. The default timesheet is called
"default".''')
    parser.add_option('-v', '--verbose', dest='verbose',
                      action='store_true', help='Print the name and \
number of entries of the timesheet.')
    opts, args = parser.parse_args(args=args)
    if len(args) != 1:
        parser.error('no timesheet given')

    sheet = args[0]

    # optimization: check that the given timesheet is not already
    # current. updates are far slower than selects.
    if dbutil.get_current_sheet(db) != sheet:
        db.execute(u'''
        update
            meta
        set
            value = ?
        where
            key = 'current_sheet'
        ''', (args[0],))

    if opts.verbose:
        entry_count = dbutil.get_entry_count(db, sheet)
        if entry_count == 0:
            print u'switched to empty timesheet "%s"' % sheet
        else:
            print ngettext(
                u'switched to timesheet "%s" (1 entry)' % sheet,
                u'switched to timesheet "%s" (%s entries)' % (
                    sheet, entry_count), entry_count)