コード例 #1
0
ファイル: commands.py プロジェクト: itsamenathan/timebook
def in_(db, args, extra=None):
    parser = 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('-d', '--db', dest='database', type='string',
                      help='Switch to another databae from config file')
    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('-r', '--resume', dest='resume', action='store_true',
                      default=False, help='''Clocks in with status of \
last active period''')
    opts, args = parser.parse_args(args=args)
    if opts.switch:
        sheet = opts.switch
        switch(db, [sheet])
    else:
        sheet = dbutil.get_current_sheet(db)
    if opts.resume and args:
        parser.error('"--resume" already sets a note, and is incompatible \
with arguments.')
    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:
        (previous_timestamp, previous_description) = most_recent_clockout
        if timestamp < previous_timestamp:
            raise SystemExit, \
                  'error: time periods could end up overlapping'
        if opts.resume:
            description = previous_description
    db.execute(u'''
    insert into entry (
        sheet, start_time, description, extra
    ) values (?,?,?,?)
    ''', (sheet, timestamp, description, extra))
コード例 #2
0
ファイル: commands.py プロジェクト: imiric/timebook
def in_(db, description='', switch=None, out=False, at=None, resume=False,
        extra=None):
    """Start the timer for the current timesheet

    Usage: t (in | start) [options] [<description>...]

    Start the timer for the current timesheet. Must be called before out.
    Notes may be specified for this period. This is exactly equivalent to
    `t in; t alter`.

    Options:
      -s <timesheet>, --switch <timesheet>
                    Switch to another timesheet before starting the timer.
      -o, --out     Clock out before clocking in.
      -a <time>, --at <time>
                    Set time of clock-in.
      -r, --resume  Clock in with description of last active period.
    """
    sheet = switch
    if sheet:
        commands['switch'](db, timesheet=sheet)
    else:
        sheet = dbutil.get_current_sheet(db)
    if resume and description:
        raise SystemExit('"--resume" already sets a description')
    timestamp = cmdutil.parse_date_time_or_now(at)
    if 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 = ' '.join(description) or None
    if most_recent_clockout:
        (previous_timestamp, previous_description) = most_recent_clockout
        if timestamp < previous_timestamp:
            raise SystemExit('error: time periods could end up overlapping')
        if resume:
            description = previous_description
    db.execute('''
    insert into entry (
        sheet, start_time, description, extra
    ) values (?,?,?,?)
    ''', (sheet, timestamp, description, extra))
コード例 #3
0
ファイル: commands.py プロジェクト: trevorc/timebook
def in_(db, args, extra=None):
    parser = 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('-r',
                      '--resume',
                      dest='resume',
                      action='store_true',
                      default=False,
                      help='''Clocks in with status of \
last active period''')
    opts, args = parser.parse_args(args=args)
    if opts.switch:
        sheet = opts.switch
        switch(db, [sheet])
    else:
        sheet = dbutil.get_current_sheet(db)
    if opts.resume and args:
        parser.error('"--resume" already sets a note, and is incompatible \
with arguments.')
    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:
        (previous_timestamp, previous_description) = most_recent_clockout
        if timestamp < previous_timestamp:
            raise SystemExit, \
                  'error: time periods could end up overlapping'
        if opts.resume:
            description = previous_description
    db.execute(
        u'''
    insert into entry (
        sheet, start_time, description, extra
    ) values (?,?,?,?)
    ''', (sheet, timestamp, description, extra))
コード例 #4
0
ファイル: commands.py プロジェクト: amdemas/timebook
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)
コード例 #5
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)