#!/usr/bin/env python

""" 


"""

__author__ = 'Elena "of Valhalla" Grandi'
__version__ = '20090318'
__copyright__ = '2009 Elena Grandi'
__license__ = 'LGPL'

import optparse, os
import dumb

def get_command(hash=None,url=None,directory=os.path.curdir):
    bm = dumb.Bookmark(hash,directory,url)
    bm.load()
    line = ""
    try:
        line = bm.get_parsed_value('cline')
    except KeyError:
        # TODO: add fallback to a known opener + url
        pass
    return line


def main():
    parser = optparse.OptionParser()
    parser.add_option('--hash','-H')
    opts, args = parser.parse_args()
    url = None
    directory = os.path.curdir
    hash = None
    if len(args) > 0 and opts.hash == None:
        url = args[0]
        if len(args) > 1:
            directory = args[1]
    elif len(args) == 0 and opts.hash != None:
        hash = opts.hash
    else:
        exit("Usage: dumb-get-command [-H hash|url [directory]]")
    print get_command(hash,url,directory)


if __name__ == '__main__': main()
