Example #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
Example #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)
Example #3
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
Example #4
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)
Example #5
0
def backdate(db, args):
    try:
        try:
            now_dt = datetime.now()
            offset = cmdutil.get_time_offset(args[0])
            start = datetime(
                now_dt.year,
                now_dt.month,
                now_dt.day,
                now_dt.hour,
                now_dt.minute,
                now_dt.second
            ) - offset
        except ValueError:
            start = datetime.fromtimestamp(cmdutil.parse_date_time(args[0]))
        args = args[1:]

        active = dbutil.get_current_start_time(db)
        if active:
            clock_out(db)

        sql = """
            SELECT id 
            FROM entry
            WHERE 
                sheet = ?
                AND
                end_time > ?
        """
        sql_args = (
            dbutil.get_current_sheet(db),
            int(time.mktime(start.timetuple())),
        )
        db.execute(sql, sql_args)

        rows = db.fetchall()

        if len(rows) > 1:
            raise exceptions.CommandError(
                '%s overlaps %s entries. '
                'Please select a later time to backdate to.' % (
                    start,
                    len(rows)
                )
            )

        sql = """
            UPDATE entry
            SET end_time = ?
            WHERE 
                sheet = ?
                AND
                end_time > ?
        """
        sql_args = (
            int(time.mktime(start.timetuple())),
            dbutil.get_current_sheet(db),
            int(time.mktime(start.timetuple())),
        )
        db.execute(sql, sql_args)

        # Clock in
        args.extend(
            ['--at', str(start)]
        )
        in_(db, args)
    except IndexError as e:
        print (
            "Backdate requires at least one argument: START. "
            "Please use either the format \"YYY-MM-DD HH:MM\" or "
            "a time offset like '1h 20m'."
        )
        logger.exception(e)
Example #6
0
def backdate(db, args):
    try:
        try:
            now_dt = datetime.now()
            offset = cmdutil.get_time_offset(args[0])
            start = datetime(now_dt.year, now_dt.month, now_dt.day,
                             now_dt.hour, now_dt.minute,
                             now_dt.second) - offset
        except ValueError:
            start = datetime.fromtimestamp(cmdutil.parse_date_time(args[0]))
        args = args[1:]

        active = dbutil.get_current_start_time(db)
        if active:
            clock_out(db)

        sql = """
            SELECT id 
            FROM entry
            WHERE 
                sheet = ?
                AND
                end_time > ?
        """
        sql_args = (
            dbutil.get_current_sheet(db),
            int(time.mktime(start.timetuple())),
        )
        db.execute(sql, sql_args)

        rows = db.fetchall()

        if len(rows) > 1:
            raise exceptions.CommandError(
                '%s overlaps %s entries. '
                'Please select a later time to backdate to.' %
                (start, len(rows)))

        sql = """
            UPDATE entry
            SET end_time = ?
            WHERE 
                sheet = ?
                AND
                end_time > ?
        """
        sql_args = (
            int(time.mktime(start.timetuple())),
            dbutil.get_current_sheet(db),
            int(time.mktime(start.timetuple())),
        )
        db.execute(sql, sql_args)

        # Clock in
        args.extend(['--at', str(start)])
        in_(db, args)
    except IndexError as e:
        print(
            "Backdate requires at least one argument: START. "
            "Please use either the format \"YYY-MM-DD HH:MM\" or "
            "a time offset like '1h 20m'.")
        logger.exception(e)
Example #7
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)