Example #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)
Example #2
0
def alter(db, args):
    parser = OptionParser(usage='''usage: %prog alter NOTES...

Inserts a note associated with the currently active period in the \
timesheet. For example, ``t alter Documenting timebook.``''')
    opts, args = parser.parse_args(args=args)

    active = dbutil.get_current_active_info(db)
    if active is None:
        raise SystemExit, 'error: timesheet not active'
    entry_id = active[0]
    db.execute(u'''
    update
        entry
    set
        description = ?
    where
        entry.id = ?
    ''', (' '.join(args), entry_id))
Example #3
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)
Example #4
0
def alter(db, args):
    parser = OptionParser(usage='''usage: %prog alter NOTES...

Inserts a note associated with the currently active period in the \
timesheet. For example, ``t alter Documenting timebook.``''')
    opts, args = parser.parse_args(args=args)

    active = dbutil.get_current_active_info(db)
    if active is None:
        raise SystemExit, 'error: timesheet not active'
    entry_id = active[0]
    db.execute(
        u'''
    update
        entry
    set
        description = ?
    where
        entry.id = ?
    ''', (' '.join(args), entry_id))
Example #5
0
def alter(db, description):
    """Alter the description of the active period

    Usage: t (alter | write) <description>...

    Inserts a note associated with the currently active period in the
    timesheet. For example, ``t alter Documenting timebook.``
    """
    active = dbutil.get_current_active_info(db)
    if active is None:
        raise SystemExit('error: timesheet not active')
    entry_id = active[0]
    db.execute('''
    update
        entry
    set
        description = ?
    where
        entry.id = ?
    ''', (' '.join(description), entry_id))
Example #6
0
def taskwarrior(db, args, extra=None):
    def poll_taskwarrior():
        tasks = []
        results = subprocess.check_output(
            [
                "task",
                "export",
                "status:pending",
                "start.not:",
            ]
        )
        for line in results.splitlines():
            if len(line.strip()) > 0:
                tasks.append(
                    json.loads(line.rstrip(','))
                )
        return (
            tasks,
            hashlib.md5('|'.join([t.get('uuid') for t in tasks])).hexdigest()
        )

    logger.info("Watching taskwarrior output...")
    task_hash_status = ''
    while True:
        tasks, task_hash = poll_taskwarrior()
        args = []
        command = 'change'
        do_change = False
        value = dbutil.get_current_active_info(db)
        if not value and task_hash_status != '':
            logger.error("Clocked-out.")
            task_hash_status = ''
        elif value and task_hash != task_hash_status:
            task_hash_status = task_hash
            if tasks:
                if len(tasks) > 1:
                    logger.warning(
                        "Multiple tasks currently active; using first."
                    )
                task = tasks[0]
                logger.info("Active task changed: %s" % task)

                # Ticket No.
                ticket = task.get('ticket')
                if ticket:
                    args.append('--ticket=%s' % ticket)

                # Pull Request No.
                pr = task.get('pr')
                if pr:
                    args.append('--pr=%s' % pr.replace('/', ':'))

                # Description
                description = task.get('description')
                if description:
                    args.append(description)

                _, duration = value
                logger.error(duration)
                if duration < 60:
                    command = 'alter'

                do_change = True
            else:
                logger.warning("No active tasks; changing to nil.")
                do_change = True

            if do_change:
                logger.info("Running %s %s" % (command, args))
                run_command(db, command, args)
        time.sleep(1)
Example #7
0
def taskwarrior(db, args, extra=None):
    def poll_taskwarrior():
        tasks = []
        results = subprocess.check_output([
            "task",
            "export",
            "status:pending",
            "start.not:",
        ])
        for line in results.splitlines():
            if len(line.strip()) > 0:
                tasks.append(json.loads(line.rstrip(',')))
        return (tasks, hashlib.md5('|'.join([t.get('uuid')
                                             for t in tasks])).hexdigest())

    logger.info("Watching taskwarrior output...")
    task_hash_status = ''
    while True:
        tasks, task_hash = poll_taskwarrior()
        args = []
        command = 'change'
        do_change = False
        value = dbutil.get_current_active_info(db)
        if not value and task_hash_status != '':
            logger.error("Clocked-out.")
            task_hash_status = ''
        elif value and task_hash != task_hash_status:
            task_hash_status = task_hash
            if tasks:
                if len(tasks) > 1:
                    logger.warning(
                        "Multiple tasks currently active; using first.")
                task = tasks[0]
                logger.info("Active task changed: %s" % task)

                # Ticket No.
                ticket = task.get('ticket')
                if ticket:
                    args.append('--ticket=%s' % ticket)

                # Pull Request No.
                pr = task.get('pr')
                if pr:
                    args.append('--pr=%s' % pr.replace('/', ':'))

                # Description
                description = task.get('description')
                if description:
                    args.append(description)

                _, duration = value
                logger.error(duration)
                if duration < 60:
                    command = 'alter'

                do_change = True
            else:
                logger.warning("No active tasks; changing to nil.")
                do_change = True

            if do_change:
                logger.info("Running %s %s" % (command, args))
                run_command(db, command, args)
        time.sleep(1)