Exemple #1
0
def cmd_start(tl, args):
    """sets the 'started' property of an item or lists all started items.
    
    :description: If a todo item is picked to be worked on, this command
        allows setting the started time. Thus, the time it took to work
        on that item can be derived from 'started' and 'done' time.
    
    Required fields of :param:`args`:
    * item: the index number or id of the todo item which is started
    """
    with ColorRenderer() as cr:
        if not args.item:
            for item in tl.list_items(lambda x: True
                                      if conf.STARTED in x.properties and not (
                                          x.done or x.is_report) else False):
                print(u" ", cr.render(item))
        else:
            item = tl.get_item_by_index(args.item)
            if not item:
                print(u"No item found with number or ID '{item_id}'".format(
                    item_id=args.item))
                return
            if item.done:
                print(u"Todo item has already been set to 'done':")
                print(u" ", cr.render(item))
                return
            if conf.STARTED in item.properties:
                print(u"Todo item has already been started on {date}".format(
                    date=from_date(item.properties[conf.STARTED])))
                print(u" ", cr.render(item))
                return
            now = datetime.datetime.now()
            tl.replace_or_add_prop(item, conf.STARTED, from_date(now), now)
def cmd_delay(tl, args):
    """delays the due date of one or more todo items
    """
    with ColorRenderer() as cr:
        item = tl.get_item_by_index(args.item)
        if not item:
            print(u"Could not find item '{item_id}'".format(item_id = args.item))
            return
        if item.due_date:
            new_date = to_date(args.date, item.due_date)
            if isinstance(new_date, basestring):
                # remove first character, as it is "?" with a non-parsable date
                print(u"The given relative date could not be parsed: {date}".format(date = new_date[1:]))
            else:
                # ask for confirmation
                if not args.force:
                    print(" ", cr.render(item))
                    if not confirm_action(u"Delaying the preceding item's date from {from_date} to {to_date} (y/N)?".format(
                        from_date = from_date(item.due_date), to_date = from_date(new_date))):
                        return
                # do the actual replacement
                tl.replace_or_add_prop(item, conf.DUE, from_date(new_date), new_date)
        else:
            new_date = to_date(args.date)
            if not args.force:
                print(u" ", cr.render(item))
                if not confirm_action(u"The preceding item has no due date set, set to {date} (y/N)?".format(date = from_date(new_date))):
                    return
                tl.replace_or_add_prop(item, conf.DUE, from_date(new_date), new_date)
        suppress_if_quiet(u"  {item}".format(item = cr.render(item)), args)
Exemple #3
0
def cmd_start(tl, args):
    """sets the 'started' property of an item or lists all started items.
    
    :description: If a todo item is picked to be worked on, this command
        allows setting the started time. Thus, the time it took to work
        on that item can be derived from 'started' and 'done' time.
    
    Required fields of :param:`args`:
    * item: the index number or id of the todo item which is started
    """
    with ColorRenderer() as cr:
        if not args.item:
            for item in tl.list_items(lambda x: True if conf.STARTED in x.properties 
                    and not (x.done or x.is_report) else False):
                print(u" ", cr.render(item))
        else:
            item = tl.get_item_by_index(args.item)
            if not item:
                print(u"No item found with number or ID '{item_id}'".format(item_id = args.item))
                return
            if item.done:
                print(u"Todo item has already been set to 'done':")
                print(u" ", cr.render(item))
                return
            if conf.STARTED in item.properties:
                print(u"Todo item has already been started on {date}".format(date = from_date(item.properties[conf.STARTED])))
                print(u" ", cr.render(item))
                return
            now = datetime.datetime.now()
            tl.replace_or_add_prop(item, conf.STARTED, from_date(now), now)
Exemple #4
0
def cmd_delay(tl, args):
    """delays the due date of one or more todo items
    
    Required fields of :param:`args`:
    * item: the index number of the item to delay
    * date: either a date or a string like 'tomorrow', default '1d' (delays for 1 day)
    * force: if given, confirmation is not requested
    """
    with ColorRenderer() as cr:
        item = tl.get_item_by_index(args.item)
        if not item:
            print(u"Could not find item '{item_id}'".format(item_id=args.item))
            return
        if item.due_date:
            new_date = to_date(args.date, item.due_date)
            if isinstance(new_date, basestring):
                # remove first character, as it is "?" with a non-parsable date
                print(u"The given relative date could not be parsed: {date}".
                      format(date=new_date[1:]))
            else:
                # ask for confirmation
                if not args.force:
                    print(" ", cr.render(item))
                    if not confirm_action(
                            u"Delaying the preceding item's date from {from_date} to {to_date} (y/N)?"
                            .format(from_date=from_date(item.due_date),
                                    to_date=from_date(new_date))):
                        return
                # do the actual replacement
                tl.replace_or_add_prop(item, conf.DUE, from_date(new_date),
                                       new_date)
        else:
            new_date = to_date(args.date)
            if not args.force:
                print(u" ", cr.render(item))
                if not confirm_action(
                        u"The preceding item has no due date set, set to {date} (y/N)?"
                        .format(date=from_date(new_date))):
                    return
                tl.replace_or_add_prop(item, conf.DUE, from_date(new_date),
                                       new_date)
        suppress_if_quiet(u"  {item}".format(item=cr.render(item)), args)
def cmd_start(tl, args):
    """sets the 'started' property of an item or lists all started items.
    """
    with ColorRenderer() as cr:
        if not args.item:
            for item in tl.list_items(lambda x: True if conf.STARTED in x.properties 
                    and not (x.done or x.is_report) else False):
                print(u" ", cr.render(item))
        else:
            item = tl.get_item_by_index(args.item)
            if not item:
                print(u"No item found with number or ID '{item_id}'".format(item_id = args.item))
                return
            if item.done:
                print(u"Todo item has already been set to 'done':")
                print(u" ", cr.render(item))
                return
            if conf.STARTED in item.properties:
                print(u"Todo item has already been started on {date}".format(date = from_date(item.properties[conf.STARTED])))
                print(u" ", cr.render(item))
                return
            now = datetime.datetime.now()
            tl.replace_or_add_prop(item, conf.STARTED, from_date(now), now)