Esempio n. 1
0
def alter(db, args):
    parser = optparse.OptionParser(usage='''usage: %prog alter NOTES...

Inserts a note associated with the currently active period in the \
timesheet. For example, ``t alter Documenting timebook.``''')
    parser.add_option('-t',
                      '--ticket',
                      dest='ticket_number',
                      type='string',
                      default=None,
                      help='Set ticket number')
    parser.add_option('--billable',
                      dest='billable',
                      action='store_true',
                      default=None,
                      help='Marks entry as billable')
    parser.add_option('--non-billable',
                      dest='billable',
                      action='store_false',
                      default=None,
                      help='Marks entry as billable')
    parser.add_option('--id',
                      dest='entry_id',
                      type='string',
                      default=None,
                      help='Entry ID number (defaults to current)')
    cmdutil.add_user_specified_attributes(db, parser)
    opts, args = parser.parse_args(args=args)

    if not opts.entry_id:
        active = dbutil.get_current_active_info(db)
        if active is None:
            raise SystemExit('error: timesheet not active')
        entry_id = active[0]
    else:
        entry_id = opts.entry_id
    if args:
        db.execute(
            u'''
        update
            entry
        set
            description = ?
        where
            entry.id = ?
        ''', (' '.join(args), entry_id))
    meta = cmdutil.collect_user_specified_attributes(db, opts)
    if opts.billable != None:
        meta['billable'] = 'yes' if opts.billable else 'no'
    if opts.ticket_number != None:
        meta['ticket_number'] = opts.ticket_number
    dbutil.update_entry_meta(db, entry_id, meta)
Esempio n. 2
0
def alter(db, args):
    parser = optparse.OptionParser(usage='''usage: %prog alter NOTES...

Inserts a note associated with the currently active period in the \
timesheet. For example, ``t alter Documenting timebook.``''')
    parser.add_option('-t', '--ticket', dest='ticket_number', type='string',
            default=None, help='Set ticket number'
            )
    parser.add_option('--billable', dest='billable', action='store_true',
            default=None, help='Marks entry as billable'
            )
    parser.add_option('--non-billable', dest='billable', action='store_false',
            default=None, help='Marks entry as billable'
            )
    parser.add_option('--id', dest='entry_id', type='string',
            default=None, help='Entry ID number (defaults to current)'
            )
    cmdutil.add_user_specified_attributes(db, parser)
    opts, args = parser.parse_args(args=args)

    if not opts.entry_id:
        active = dbutil.get_current_active_info(db)
        if active is None:
            raise SystemExit('error: timesheet not active')
        entry_id = active[0]
    else:
        entry_id = opts.entry_id
    if args:
        db.execute(u'''
        update
            entry
        set
            description = ?
        where
            entry.id = ?
        ''', (' '.join(args), entry_id))
    meta = cmdutil.collect_user_specified_attributes(db, opts)
    if opts.billable != None:
        meta['billable'] = 'yes' if opts.billable else 'no'
    if opts.ticket_number != None:
        meta['ticket_number'] = opts.ticket_number
    dbutil.update_entry_meta(db, entry_id, meta)
Esempio n. 3
0
def in_(db, args, extra=None, change=False):
    parser = optparse.OptionParser(usage='''usage: %prog in [NOTES...]

Start the timer for the current timesheet. Must be called before out.
Notes may be specified for this period. This is exactly equivalent to
%prog in; %prog alter''')
    parser.add_option('-s', '--switch', dest='switch', type='string',
            help='Switch to another timesheet before starting the timer.'
            )
    parser.add_option('-o', '--out', dest='out', action='store_true',
            default=False, help='Clocks out before clocking in'
            )
    parser.add_option('-a', '--at', dest='at', type='string',
            help='Set time of clock-in'
            )
    parser.add_option('-t', '--ticket', dest='ticket_number', type='string',
            default=None, help='Set ticket number'
            )
    parser.add_option('--billable', dest='billable', action='store_true',
            default=True, help='Marks entry as billable'
            )
    parser.add_option('--non-billable', dest='billable', action='store_false',
            default=True, help='Marks entry as non-billable'
            )
    cmdutil.add_user_specified_attributes(db, parser)
    opts, args = parser.parse_args(args=args)
    metadata = cmdutil.collect_user_specified_attributes(db, opts)
    metadata['billable'] = 'yes' if opts.billable else 'no'
    if opts.ticket_number:
        metadata['ticket_number'] = opts.ticket_number
    if opts.switch:
        sheet = opts.switch
        switch(db, [sheet])
    else:
        sheet = dbutil.get_current_sheet(db)
    timestamp = cmdutil.parse_date_time_or_now(opts.at)
    if opts.out:
        clock_out(db, timestamp=timestamp)
    running = dbutil.get_active_info(db, sheet)
    if running is not None:
        raise SystemExit('error: timesheet already active')
    most_recent_clockout = dbutil.get_most_recent_clockout(db, sheet)
    description = u' '.join(args) or None
    if most_recent_clockout:
        (id, start_time, prev_timestamp, prev_desc) = most_recent_clockout
        prev_meta = dbutil.get_entry_meta(db, id)
        if timestamp < prev_timestamp:
            raise SystemExit('error: time periods could end up overlapping')
        current_sheet = dbutil.get_current_sheet(db)
        if change and db.config.has_option(current_sheet, 'autocontinue'):
            if not description:
                description = prev_desc
            for p_key, p_value in prev_meta.items():
                if p_key not in metadata.keys() or not metadata[p_key]:
                    metadata[p_key] = p_value

    db.execute(u'''
    insert into entry (
        sheet, start_time, description, extra
    ) values (?,?,?,?)
    ''', (sheet, timestamp, description, extra))
    entry_id = db.cursor.lastrowid
    dbutil.update_entry_meta(db, entry_id, metadata)
Esempio n. 4
0
def in_(db, args, extra=None, change=False):
    parser = optparse.OptionParser(usage='''usage: %prog in [NOTES...]

Start the timer for the current timesheet. Must be called before out.
Notes may be specified for this period. This is exactly equivalent to
%prog in; %prog alter''')
    parser.add_option(
        '-s',
        '--switch',
        dest='switch',
        type='string',
        help='Switch to another timesheet before starting the timer.')
    parser.add_option('-o',
                      '--out',
                      dest='out',
                      action='store_true',
                      default=False,
                      help='Clocks out before clocking in')
    parser.add_option('-a',
                      '--at',
                      dest='at',
                      type='string',
                      help='Set time of clock-in')
    parser.add_option('-t',
                      '--ticket',
                      dest='ticket_number',
                      type='string',
                      default=None,
                      help='Set ticket number')
    parser.add_option('--billable',
                      dest='billable',
                      action='store_true',
                      default=True,
                      help='Marks entry as billable')
    parser.add_option('--non-billable',
                      dest='billable',
                      action='store_false',
                      default=True,
                      help='Marks entry as non-billable')
    cmdutil.add_user_specified_attributes(db, parser)
    opts, args = parser.parse_args(args=args)
    metadata = cmdutil.collect_user_specified_attributes(db, opts)
    metadata['billable'] = 'yes' if opts.billable else 'no'
    if opts.ticket_number:
        metadata['ticket_number'] = opts.ticket_number
    if opts.switch:
        sheet = opts.switch
        switch(db, [sheet])
    else:
        sheet = dbutil.get_current_sheet(db)
    timestamp = cmdutil.parse_date_time_or_now(opts.at)
    if opts.out:
        clock_out(db, timestamp=timestamp)
    running = dbutil.get_active_info(db, sheet)
    if running is not None:
        raise SystemExit('error: timesheet already active')
    most_recent_clockout = dbutil.get_most_recent_clockout(db, sheet)
    description = u' '.join(args) or None
    if most_recent_clockout:
        (id, start_time, prev_timestamp, prev_desc) = most_recent_clockout
        prev_meta = dbutil.get_entry_meta(db, id)
        if timestamp < prev_timestamp:
            raise SystemExit('error: time periods could end up overlapping')
        current_sheet = dbutil.get_current_sheet(db)
        if change and db.config.has_option(current_sheet, 'autocontinue'):
            if not description:
                description = prev_desc
            for p_key, p_value in prev_meta.items():
                if p_key not in metadata.keys() or not metadata[p_key]:
                    metadata[p_key] = p_value

    db.execute(
        u'''
    insert into entry (
        sheet, start_time, description, extra
    ) values (?,?,?,?)
    ''', (sheet, timestamp, description, extra))
    entry_id = db.cursor.lastrowid
    dbutil.update_entry_meta(db, entry_id, metadata)