Ejemplo n.º 1
0
def remove(db,args):
    '''Remove item(s) from the db.'''

    if len(args) > 0:
        sub = args[0]
        if sub == "all":
            items = db.grabAll()
        elif sub == 'last':
            items = db.grabMostRecent(1)
        elif sub == 'last^':
            items = db.grabMostRecent(1,1)
        elif sub == 'last^^':
            items = db.grabMostRecent(1,2)
        elif sub[0:5] == 'last~' and len(sub) == 6:
            items = db.grabMostRecent(1,int(sub[5]))
        elif sub[0:4] == 'last' and len(sub) == 5:
            items = db.grabMostRecent(int(sub[4]))
        else:
            items = [db.grabItem(sub)]
        removed = 0 
        for item in items:
            if item is not None:
                item.remove(commit=False) # Don't commit so we can bundle transactions. 
                print 'Removed',util.decorate('WARNING',item.identifier)
                removed += 1
        db.commit()
        if removed > 0:
            print util.decorate('OKGREEN',str(removed) + ' item(s) successfully removed.')
Ejemplo n.º 2
0
def edit(db, args, config):
    if len(args) == 0:
        print util.decorate("FAIL", "Fatal: No reference to item to edit supplied.")
        return False
    for arg in args:
        if arg == "last":
            items = db.grabMostRecent(1)
        elif arg == "last^":
            items = db.grabMostRecent(1, 1)
        elif arg == "last^^":
            items = db.grabMostRecent(1, 2)
        elif arg[0:5] == "last~" and len(arg) == 6:
            items = db.grabMostRecent(1, int(arg[5]))
        elif len(arg) > 0:
            items = [db.grabItem(arg)]
        else:
            print util.decorate("FAIL", "Fatal: No reference to item to edit supplied.")
            return False
    if items is not None:
        item = items[0]
        item.edit()
        item.save()
        print util.decorate("OKGREEN", "Item was successfully modified.\n")
        item.display()
        return True
    return False
Ejemplo n.º 3
0
def edit(db, args, config):
    if len(args) == 0:
        print util.decorate('FAIL',
                            'Fatal: No reference to item to edit supplied.')
        return False
    for arg in args:
        if arg == 'last':
            items = db.grabMostRecent(1)
        elif arg == 'last^':
            items = db.grabMostRecent(1, 1)
        elif arg == 'last^^':
            items = db.grabMostRecent(1, 2)
        elif arg[0:5] == 'last~' and len(arg) == 6:
            items = db.grabMostRecent(1, int(arg[5]))
        elif len(arg) > 0:
            items = [db.grabItem(arg)]
        else:
            print util.decorate(
                'FAIL', 'Fatal: No reference to item to edit supplied.')
            return False
    if items is not None:
        item = items[0]
        item.edit()
        item.save()
        print util.decorate('OKGREEN', 'Item was successfully modified.\n')
        item.display()
        return True
    return False
Ejemplo n.º 4
0
def search(db, args):
    '''Search item content and display matches.'''
    #
    # Methods:
    #   search [query]
    #       --displays all items that match the query.
    #
    if len(args) > 0:
        query = args[0]
        items = db.searchContent(query)
    else:
        print util.decorate(
            'FAIL',
            'Requires a search parameter.\n    usage: jot search [query]')
        return False
    if items is None:
        print util.decorate('WARNING', 'No matches found for "%s"' % query)
    else:
        print util.decorate(
            'OKGREEN',
            '%d matching items found for "%s"\n' % (len(items), query))
        for item in items:
            if item is not None:
                item.display()
        return True
    return False
Ejemplo n.º 5
0
def search(db,args):
    '''Search item content and display matches.'''
    #
    # Methods:
    #   search [query] 
    #       --displays all items that match the query.
    #
    if len(args) > 0:
        query = args[0]
        items = db.searchContent(query)
    else:
        print util.decorate('FAIL', 'Requires a search parameter.\n    usage: jot search [query]')
        return False
    if items is None:
        print util.decorate('WARNING', 'No matches found for "%s"' % query)
    else:
        print util.decorate('OKGREEN', '%d matching items found for "%s"\n' % (len(items),query))
        for item in items:
            if item is not None:
                item.display()
        return True
    return False
Ejemplo n.º 6
0
def add(db, args, config):
    '''Create, fill, save, and display a new jot Item.'''
    #
    # Arguments:
    #   [none]     
    #           opens the default editor with a temp file. 
    #
    #   -m "string"
    #   --manual "string"
    #           uses the supplied string as the item content.
    #
    #   -q
    #   --quiet
    #           suppress output, would really only make sense to
    #           run with -m, but works either way.
    #   -h
    #   --high
    #           attaches a 'high' priority to the item. Priority
    #           defaults to normal when this and the -l option are
    #           omitted.
    #   
    #   -l
    #   --low
    #           attaches a 'low' priority to the item.
    #
    #   -t "string, string, ... "
    #   --tags "string, string, ... "
    #           attaches one or more comma-separated strings as
    #           to the item as tags. These are optional and can
    #           always be added later with the tag command.

    manual = False
    quiet = False
    content = None
    batchMode = False
    priority = 'Normal'
    tags = None
    for tup in args:
        arg1 = tup[0]
        arg2 = tup[1]
        if (arg1 == 'm' or arg1 == '-manual') and arg2 is not None:
            manual = True
            content = arg2
        if arg1 == '-high' or arg1 == 'h':
            priority = 'High'
        if arg1 == '-low' or arg1 == 'l':
            priority = 'Low'
        if arg1 == '-quiet' or arg1 == 'q':
            quiet = True
        if arg1 == '-batch' or arg1 == 'b':
            batchMode = True
        if (arg1 == '-tags' or arg1 == 't') and arg2 is not None:
            tags = arg2.split(',')
            
    if manual:
        item = Item(db, content=content, priority=priority, tags=tags)
    else:
        item = Item(db, priority=priority, tags=tags)
        item.fill()
    item.save()
    if not quiet:
        print util.decorate('OKGREEN','New item addition was successful.\n')
        item.display()
    return True
Ejemplo n.º 7
0
def add(db, args, config):
    '''Create, fill, save, and display a new jot Item.'''
    #
    # Arguments:
    #   [none]
    #           opens the default editor with a temp file.
    #
    #   -m "string"
    #   --manual "string"
    #           uses the supplied string as the item content.
    #
    #   -q
    #   --quiet
    #           suppress output, would really only make sense to
    #           run with -m, but works either way.
    #   -h
    #   --high
    #           attaches a 'high' priority to the item. Priority
    #           defaults to normal when this and the -l option are
    #           omitted.
    #
    #   -l
    #   --low
    #           attaches a 'low' priority to the item.
    #
    #   -t "string, string, ... "
    #   --tags "string, string, ... "
    #           attaches one or more comma-separated strings as
    #           to the item as tags. These are optional and can
    #           always be added later with the tag command.

    manual = False
    quiet = False
    content = None
    batchMode = False
    priority = 'Normal'
    tags = None
    for tup in args:
        arg1 = tup[0]
        arg2 = tup[1]
        if (arg1 == 'm' or arg1 == '-manual') and arg2 is not None:
            manual = True
            content = arg2
        if arg1 == '-high' or arg1 == 'h':
            priority = 'High'
        if arg1 == '-low' or arg1 == 'l':
            priority = 'Low'
        if arg1 == '-quiet' or arg1 == 'q':
            quiet = True
        if arg1 == '-batch' or arg1 == 'b':
            batchMode = True
        if (arg1 == '-tags' or arg1 == 't') and arg2 is not None:
            tags = arg2.split(',')

    if manual:
        item = Item(db, content=content, priority=priority, tags=tags)
    else:
        item = Item(db, priority=priority, tags=tags)
        item.fill()
    item.save()
    if not quiet:
        print util.decorate('OKGREEN', 'New item addition was successful.\n')
        item.display()
    return True