Пример #1
0
def display(db, args):
    # arguments
    parser = OptionParser(usage='''usage: %prog display [TIMESHEET]

Display the data from a timesheet in the range of dates specified, either
in the normal timebook fashion (using --format=plain) or as
comma-separated value format spreadsheet (using --format=csv), which
ignores the final entry if active.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s',
                      '--start',
                      dest='start',
                      type='string',
                      metavar='DATE',
                      help='Show only entries \
starting after 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-e',
                      '--end',
                      dest='end',
                      type='string',
                      metavar='DATE',
                      help='Show only entries \
ending before 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-f',
                      '--format',
                      dest='format',
                      type='string',
                      default='plain',
                      help="Select whether to output in the normal timebook \
style (--format=plain) or csv --format=csv")
    opts, args = parser.parse_args(args=args)

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

    #calculate "where"
    where = ''
    fmt = '%Y-%m-%d'
    if opts.start is not None:
        start = cmdutil.parse_date_time(opts.start)
        where += ' and start_time >= %s' % start
    if opts.end is not None:
        end = cmdutil.parse_date_time(opts.end)
        where += ' and end_time <= %s' % end
    if opts.format == 'plain':
        format_timebook(db, sheet, where)
    elif opts.format == 'csv':
        format_csv(db, sheet, where)
    else:
        raise SystemExit, 'Invalid format: %s' % opts.format
Пример #2
0
def display(db, args):
    # arguments
    parser = optparse.OptionParser(usage='''usage: %prog display [TIMESHEET]

Display the data from a timesheet in the range of dates specified, either
in the normal timebook fashion (using --format=plain) or as
comma-separated value format spreadsheet (using --format=csv), which
ignores the final entry if active.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s', '--start', dest='start', type='string',
                      metavar='DATE', help='Show only entries \
starting after 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-e', '--end', dest='end', type='string',
                      metavar='DATE', help='Show only entries \
ending before 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-f', '--format', dest='format', type='string',
                  default='plain',
                  help="Select whether to output in the normal timebook \
style (--format=plain) or csv --format=csv")
    parser.add_option('-i', '--show-ids', dest='show_ids',
            action='store_true', default=False)
    parser.add_option('--summary', dest='summary',
            action='store_true', default=False)
    opts, args = parser.parse_args(args=args)

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

    #calculate "where"
    where = ''
    if opts.start is not None:
        start = cmdutil.parse_date_time(opts.start)
        where += ' and start_time >= %s' % start
    else:
        where += ''' and start_time >
            STRFTIME(\'%s\', \'now\', \'-6 days\', \'start of day\')
        '''
    if opts.end is not None:
        end = cmdutil.parse_date_time(opts.end)
        where += ' and end_time <= %s' % end
    if opts.format == 'plain':
        format_timebook(
            db, sheet, where, show_ids=opts.show_ids, summary=opts.summary
        )
    elif opts.format == 'csv':
        format_csv(db, sheet, where, show_ids=opts.show_ids)
    else:
        raise SystemExit('Invalid format: %s' % opts.format)
Пример #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)
Пример #4
0
def display(db, args):
    # arguments
    parser = OptionParser(usage='''usage: %prog display [TIMESHEET]

Display the data from a timesheet in the range of dates specified, either
in the normal timebook fashion (using --format=plain) or as
comma-separated value format spreadsheet (using --format=csv), which
ignores the final entry if active.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s', '--start', dest='start', type='string',
                      metavar='DATE', help='Show only entries \
starting after 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-e', '--end', dest='end', type='string',
                      metavar='DATE', help='Show only entries \
ending before 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-f', '--format', dest='format', type='string',
                  default='plain',
                  help='''Select whether to output in the normal timebook
style (--format=plain), csv --format=csv or group --format=group (groups 
periods by custom words in description and calculates total hours per group)''')
    opts, args = parser.parse_args(args=args)

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

    #calculate "where"
    where = ''
    fmt = '%Y-%m-%d'
    if opts.start is not None:
        start = cmdutil.parse_date_time(opts.start)
        where += ' and start_time >= %s' % start
    if opts.end is not None:
        end = cmdutil.parse_date_time(opts.end)
        where += ' and end_time <= %s' % end
    if opts.format == 'plain':
        format_timebook(db, sheet, where)
    elif opts.format == 'csv':
        format_csv(db, sheet, where)
    elif opts.format == 'group':
        format_timebook(db, sheet, where, group='on')
    else:
        raise SystemExit, 'Invalid format: %s' % opts.format
Пример #5
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)
Пример #6
0
def display(db, timesheet=None, format='plain', start=None, end=None):
    """Display a timesheet, by default the current one

    Usage: t (display | export | format | show) [options] [<timesheet>]

    Display the data from a timesheet in the range of dates specified, either
    in the normal timebook fashion (using --format=plain) or as
    comma-separated value format spreadsheet (using --format=csv), which
    ignores the final entry if active.

    If a specific timesheet is given, display the same information for that
    timesheet instead.

    Options:
      -s <date>, --start <date>
                        Show only entries starting after 00:00 on this date.
                        The date should be of the format YYYY-MM-DD.
      -e <date>, --end <date>
                        Show only entries ending before 00:00 on this date.
                        The date should be of the format YYYY-MM-DD.
      -f (plain|csv), --format=(plain|csv)
                        Select whether to output in the normal timebook style
                        (--format=plain) or CSV (--format=csv) [default: plain].

    """
    # grab correct sheet
    if timesheet:
        sheet = cmdutil.complete(dbutil.get_sheet_names(db), timesheet,
                                 'timesheet')
    else:
        sheet = dbutil.get_current_sheet(db)

    #calculate "where"
    where = ''
    if start is not None:
        start_date = cmdutil.parse_date_time(start)
        where += ' and start_time >= %s' % start_date
    if end is not None:
        end_date = cmdutil.parse_date_time(end)
        where += ' and end_time <= %s' % end_date
    if format == 'plain':
        format_timebook(db, sheet, where)
    elif format == 'csv':
        format_csv(db, sheet, where)
    else:
        raise SystemExit('Invalid format: %s' % format)
Пример #7
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))
Пример #8
0
def display(db, args):
    # arguments
    parser = optparse.OptionParser(usage='''usage: %prog display [TIMESHEET]

Display the data from a timesheet in the range of dates specified, either
in the normal timebook fashion (using --format=plain) or as
comma-separated value format spreadsheet (using --format=csv), which
ignores the final entry if active.

If a specific timesheet is given, display the same information for that
timesheet instead.''')
    parser.add_option('-s',
                      '--start',
                      dest='start',
                      type='string',
                      metavar='DATE',
                      help='Show only entries \
starting after 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-e',
                      '--end',
                      dest='end',
                      type='string',
                      metavar='DATE',
                      help='Show only entries \
ending before 00:00 on this date. The date should be of the format \
YYYY-MM-DD.')
    parser.add_option('-f',
                      '--format',
                      dest='format',
                      type='string',
                      default='plain',
                      help="Select whether to output in the normal timebook \
style (--format=plain) or csv --format=csv or eu timesheet csv --format=eu")
    parser.add_option('-i',
                      '--show-ids',
                      dest='show_ids',
                      action='store_true',
                      default=False)
    parser.add_option('--summary',
                      dest='summary',
                      action='store_true',
                      default=False)
    parser.add_option('-m',
                      '--month',
                      dest='month',
                      type='int',
                      default=0,
                      help='Month to export int[1 .. 12]')
    opts, args = parser.parse_args(args=args)

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

    # calculate "where"
    where = ''
    if opts.month > 0:
        # if month option is used, overwrite start and end date
        y = datetime.now().year
        opts.start = "%d-%d-01" % (y, opts.month)
        opts.end = "%d-%d-%d" % (y, opts.month,
                                 calendar.monthrange(y, opts.month)[1])

    if opts.start is not None:
        start = cmdutil.parse_date_time(opts.start)
        where += ' and start_time >= %s' % start
    else:
        where += ''' and start_time >
            STRFTIME(\'%s\', \'now\', \'-6 days\', \'start of day\')
        '''
    if opts.end is not None:
        end = cmdutil.parse_date_time(opts.end)
        where += ' and end_time <= %s' % end
    if opts.format == 'plain':
        format_timebook(db,
                        sheet,
                        where,
                        show_ids=opts.show_ids,
                        summary=opts.summary)
    elif opts.format == 'csv':
        format_csv(db, sheet, where, show_ids=opts.show_ids)
    elif opts.format == 'eu':
        format_eu(db,
                  sheet,
                  where,
                  show_ids=opts.show_ids,
                  sdate=datetime.strptime(opts.start, '%Y-%m-%d'),
                  edate=datetime.strptime(opts.end, '%Y-%m-%d'))
    else:
        raise SystemExit('Invalid format: %s' % opts.format)