コード例 #1
0
ファイル: commands.py プロジェクト: letroot/bookmax
def list_bookmarks():
    """Print list of all bookmarks stored in chronological order of aliases.
    Args:

    Returns:
        None

    """
    url_map = urldb.load_map()
    if not url_map:
        print "No bookmarks added yet!"
        return

    url_list = []
    for alias, url in url_map.items():
        url_list.append((alias, url))
    url_list.sort()

    head = "{0:<25}|->|{1}".format("BOOKMARK", "URL")
    print head
    print "-" * len(head)
    for alias, url in url_list:
        if alias in groups:
            alias = alias + ' <GROUP>'
        print "{0:<25}|->|{1}".format(alias, ', '.join(url))
コード例 #2
0
ファイル: commands.py プロジェクト: letroot/bookmax
def open_bookmarks():
    """Open bookmarks entered in command.
    Args:

    Returns:
        None

    """
    bookmark_list = sys.argv[2:]
    url_map = urldb.load_map()

    for bkmark in bookmark_list:
        if bkmark not in url_map:                       # if input is not a saved bookmark
            print bkmark, "is not a bookmark, but let's see..."
            print "Opening in browser..."
            webbrowser.open(bkmark, 2)
            print "For next time:"
            print_usage()
        elif bkmark in groups:                          # if the alias is a group name
            alias_list = url_map[bkmark]
            for alias in alias_list:                    # loop through the aliases in the group
                try:
                    for url in url_map[alias]:
                        webbrowser.open(url, 2)         # open the corresponding URL to the alias
                except KeyError:
                    webbrowser.open(alias, 2)
        else:
            for url in url_map[bkmark]:           # else url is an alias, open corresponding URL
                webbrowser.open(url, 2)
コード例 #3
0
ファイル: commands.py プロジェクト: letroot/bookmax
def group_bookmarks(cmd_string):
    """Group all aliases under a name.
    Args:
        cmd_string (str): The command sequence entered by the user.

    Returns:
        None

    """
    url_map = urldb.load_map()
    group_name = cmd_string[0]
    urldb.update_grouplist(group_name)

    bookmark_list = cmd_string[1:]
    if not bookmark_list:
        print "You did not group anything :("
        print_usage()
        return

    if group_name not in groups:
        url_map[group_name] = []

    for bmark in bookmark_list:
        url_map[group_name].append(bmark)

    urldb.update_map(url_map)
コード例 #4
0
ファイル: commands.py プロジェクト: letroot/bookmax
def del_bookmarks(cmd_string):
    """Delete bookmark.
    Args:
        cmd_string (str): The command sequence entered by the user.

    Returns:
        None

    """
    if not cmd_string:
        print "You deleted nothing :)"
        print_usage()
        return

    url_map = urldb.load_map()
    option = cmd_string[0]
    items = cmd_string[1:]
    if option == '-alias':
        for alias in items:
            if alias not in url_map:
                print "Yo, that bookmark does not exist!"
                continue
            else:
                url_map.pop(alias, None)
                print alias, "deleted :("
        urldb.rebuild_map(url_map) # overwrite existing url map

    elif option == '-group':
        for group in items:
            if group not in groups:
                print "Yo, that group does not exist1"
                continue
            else:
                groups.remove(group)        # remove group from group list
                url_map.pop(group, None)    # remove group from url map
                print "Yo, that group has been burnt up!"
                urldb.rebuild_grouplist(groups)
                urldb.rebuild_map(url_map)

    elif option == '-group-item':
        group_name = items[0]
        if group_name not in url_map:
            print "Yo, that group seems to not be in here :("
            return
        else:
            del_items = items[1:] # aliases to delete from group
            for _item in del_items:
                try:
                    url_map[group_name].remove(_item)
                except ValueError:
                    print "I don't think that bookmark belongs to the group. Just sayin'"
            urldb.rebuild_map(url_map)

    else:
        print_usage()