Exemple #1
0
def route_search():
    query = request.params.get('q')
    last_query = query

    logger.warn("ROUTE: /Search")
    print "query " + query

    html = ""

    #    import ipdb; ipdb.set_trace()

    if query != "":
        query = format_query(query)
        itemids = zotero.text_search(query)
        html = html_item_link_list(itemids)

    search_form = '''
    <br />
    <form action="/search" method="GET">
            Search Library <br /><input name="q" type="text" value="%s" autofocus />
            <input value="Search" type="submit" />
        </form>
    <br />            
    '''

    search_form = search_form % (last_query)

    content_ = search_form + html
    return template(base_template,
                    subtitle="Search Library",
                    content=content_,
                    backlink="index")
Exemple #2
0
def route_tags():
    """
    In this page all tags are showed
    when some tag is clicked only the files
    related to this tag will be showed to the user
    
    """
    logger.warn("ROUTE: /tags")
    html = ""

    tags = zotero.get_tags()

    table = []

    for tag in tags:
        tagid, tagname = tag
        url = "".join(["/tagid/", str(tagid)])
        link = link_tpl(url, tagname)

        _tags = zotero.get_related_tags(tagid)
        tags_links = [
            link_tpl("/tagid/%s" % tagid, tagname) for tagid, tagname in _tags
        ]
        related_tags = " ".join(tags_links)
        #related_tags = "   Related: %s<br />" % related_tags

        table.append([link, related_tags])
        #html = html + link + related_tags + "<br />\n"

    html = py2html.html_table(table=table)

    return template(base_template,
                    subtitle="Tags",
                    content=html,
                    backlink="index")
def route_collectionid(collid):
    # Find all subcollections from a given collecion
    # which  collID is known.
    #
    # subcollections =  [ ( collIDx, collNameX ), ( ....) ... ]
    #
    logger.warn("ROUTE: /collectionid/<collid:int> = %s" % collid )

    subcollections = zotero.get_subcollections(collid)
    html_subcolls = html_collections_link(subcollections)

    collname = zotero.get_collection_name(collid)

    items = zotero.get_item_from_collections(collid)

    html_items = html_item_link_list(items)

    html = html_subcolls + "<br \><br />"# + '\n<hr width=35% color="black" align="left" >\n'
    html = html + html_items

    logger.debug("collname = %s" % collname)
    logger.debug("items = %s" % items)
    logger.debug("html_items %s" %html_items )

    subtilte_ = "Collection: " + collname
    return template(base_template, subtitle=subtilte_, content=html, backlink="collections")
def route_tags():
    """
    In this page all tags are showed
    when some tag is clicked only the files
    related to this tag will be showed to the user
    
    """
    logger.warn("ROUTE: /tags")
    html = ""

    tags = zotero.get_tags()

    table = []

    for tag in tags:
        tagid, tagname = tag
        url = "".join(["/tagid/", str(tagid)])
        link = link_tpl(url, tagname)

        _tags = zotero.get_related_tags(tagid)
        tags_links = [link_tpl("/tagid/%s" % tagid, tagname ) for tagid, tagname in _tags]
        related_tags = " ".join(tags_links)
        #related_tags = "   Related: %s<br />" % related_tags

        table.append([link, related_tags])
        #html = html + link + related_tags + "<br />\n"

    html = py2html.html_table(table=table)

    return template(base_template, subtitle="Tags", content=html, backlink="index")
Exemple #5
0
def route_collectionid(collid):
    # Find all subcollections from a given collecion
    # which  collID is known.
    #
    # subcollections =  [ ( collIDx, collNameX ), ( ....) ... ]
    #
    logger.warn("ROUTE: /collectionid/<collid:int> = %s" % collid)

    subcollections = zotero.get_subcollections(collid)
    html_subcolls = html_collections_link(subcollections)

    collname = zotero.get_collection_name(collid)

    items = zotero.get_item_from_collections(collid)

    html_items = html_item_link_list(items)

    html = html_subcolls + "<br \><br />"  # + '\n<hr width=35% color="black" align="left" >\n'
    html = html + html_items

    logger.debug("collname = %s" % collname)
    logger.debug("items = %s" % items)
    logger.debug("html_items %s" % html_items)

    subtilte_ = "Collection: " + collname
    return template(base_template,
                    subtitle=subtilte_,
                    content=html,
                    backlink="collections")
def route_search():
    query = request.params.get('q')
    last_query = query

    logger.warn("ROUTE: /Search")
    print "query " + query

    html = ""

    #    import ipdb; ipdb.set_trace()


    if query != "":
        query = format_query(query)
        itemids = zotero.text_search(query)
        html = html_item_link_list(itemids)

    search_form = '''
    <br />
    <form action="/search" method="GET">
            Search Library <br /><input name="q" type="text" value="%s" autofocus />
            <input value="Search" type="submit" />
        </form>
    <br />            
    '''

    search_form = search_form % ( last_query )

    content_ = search_form + html
    return template(base_template, subtitle="Search Library", content=content_, backlink="index")
def route_collections():
    """
    Show links to the parent collections

    """
    logger.warn("ROUTE: /collections")
    collections = zotero.get_collections_parents()
    html = html_collections_link(collections)
    return template(base_template, subtitle="Collections", content=html, backlink="index")
Exemple #8
0
def route_status():
    """
    Shows the status of the server
    """
    import subprocess
    logger.warn("ROUTE: /status")

    response.content_type = "text/plain"
    return open(Config.LOG, "r").read()
def route_status():
    """
    Shows the status of the server
    """
    import subprocess
    logger.warn("ROUTE: /status")

    response.content_type = "text/plain"
    return open(Config.LOG,"r").read()
Exemple #10
0
def main():
    data = {"PORT": PORT, "HOST": HOST}
    logger.warn("Starting server %s" % data)

    run(app=logged_app,
        host=HOST,
        port=PORT,
        server=SERVER,
        debug=DEBUG,
        reloader=True)
Exemple #11
0
def route_collections():
    """
    Show links to the parent collections

    """
    logger.warn("ROUTE: /collections")
    collections = zotero.get_collections_parents()
    html = html_collections_link(collections)
    return template(base_template,
                    subtitle="Collections",
                    content=html,
                    backlink="index")
Exemple #12
0
def route_items():
    """
    In this page all Zotero collection
    items are printed with a download 
    link.

    """
    logger.warn("ROUTE: /items")
    items = zotero.get_item_ids()

    html = html_item_link_list(items)

    return template(base_template, subtitle="Items", content=html, backlink="index")
Exemple #13
0
def route_library(path):

    logger.warn("ROUTE: /files = %s" % path)

    _path = os.path.join(zotero.storage, path)

    if os.path.isfile(_path):
        path_, file_ = os.path.split(_path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_)
    else:
        logger.debug("Error: File don't exist on server.")
        return "Error: File don't exist on server."
Exemple #14
0
def route_items():
    """
    In this page all Zotero collection
    items are printed with a download 
    link.

    """
    logger.warn("ROUTE: /items")
    items = zotero.get_item_ids()

    html = html_item_link_list(items)

    return template(base_template,
                    subtitle="Items",
                    content=html,
                    backlink="index")
Exemple #15
0
def route_help():
    logger.warn("ROUTE: help")

    html = \
    """
    The ZOTSERVER - ZOTERO SERVER - Is a http web server that uses bottle framework. <br />
    This simple and lightweight and self contained web server allows to access the     <br />
    Zotero data from anywhere or from anywhere, any device, tablet, smartphone, PC ... <br />


    See updates on: %s
    """
    link = link_tpl("https://github.com/wolfprogrammer/zotserver", "Zotserver Repository"
                    ,linktofile=False, newtab=True)
    html = html % link

    return template(base_template, subtitle="HELP", content=html, backlink="index")
Exemple #16
0
def route_tagid(tagid):
    logger.warn("ROUTE: /tagid = %s" % tagid)

    tagname = zotero.get_tagname(tagid)
    items = zotero.filter_tag(tagid)

    subtilte_ = "Tag: " + tagname

    tags = zotero.get_related_tags(tagid)
    tags_links = [link_tpl("/tagid/%s" % tagid, tagname ) for tagid, tagname in tags]
    item_tag_links = " ".join(tags_links)
    related_tags = "Related Tags: %s<br />" % item_tag_links


    html = related_tags + html_item_link_list(items)

    return template(base_template, subtitle=subtilte_, content=html, backlink="tags")
Exemple #17
0
def route_library(path):


    logger.warn("ROUTE: /files = %s" % path)

    _path = os.path.join(zotero.storage, path)

    if os.path.isfile(_path):
        path_, file_ = os.path.split(_path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_)
    else:
        logger.debug("Error: File don't exist on server.")
        return "Error: File don't exist on server."
Exemple #18
0
def route_updatelib():
    logger.warn("ROUTE: /updatelib")
    from subprocess import Popen, PIPE

    script = os.path.join(this_dir(), 'scripts/update.sh')

    logger.warn("Executing %s" % script)

    update_log = os.path.join(Config.ZOTDIR, 'log', "update.log")
    out_err = Popen([script], stdout=PIPE, stderr=PIPE).communicate()
    open(update_log, 'w').write("".join(out_err))

    # os.system("./update.sh")
    # open_database("zotero.sqlite");
    zotero.create_text_index()
    create_thumbnails()
    redirect("/index")
Exemple #19
0
def route_updatelib():
    logger.warn("ROUTE: /updatelib")
    from subprocess import Popen, PIPE

    script = os.path.join(this_dir(), 'scripts/update.sh')

    logger.warn("Executing %s" % script)

    update_log = os.path.join(Config.ZOTDIR, 'log', "update.log")
    out_err = Popen([script], stdout=PIPE, stderr=PIPE).communicate()
    open(update_log, 'w').write("".join(out_err))

    # os.system("./update.sh")
    # open_database("zotero.sqlite");
    zotero.create_text_index()
    create_thumbnails()
    redirect("/index")
Exemple #20
0
def route_resource(path):
    """
    Get the files inside template directory
    :param path:
    :return:
    """
    filename = path

    this_dir_ = this_dir()
    _path = os.path.join(this_dir_, 'resource')

    print "path = %s" % _path
    print "file = %s " % filename

    logger.warn("ROUTE: /resource = %s" % filename)
    logger.warn("_path = %s" % _path)

    return static_file(filename, root=_path)
Exemple #21
0
def route_resource(path):
    """
    Get the files inside template directory
    :param path:
    :return:
    """
    filename = path

    this_dir_ = this_dir()
    _path =  os.path.join(this_dir_, 'resource')

    print "path = %s" % _path
    print "file = %s " % filename

    logger.warn("ROUTE: /resource = %s" % filename)
    logger.warn("_path = %s" % _path)

    return static_file(filename, root=_path)
Exemple #22
0
def route_fileid(itemid):
    """
    Retrives file that matches itemid

    """
    logger.warn("ROUTE: /fileid = %s" % itemid)
    path = zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        path_, file_ = os.path.split(path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_, download=file_)
    # return "File was  " + str(itemid) + " " + path
    else:
        return "Error: File not found"
Exemple #23
0
def route_fileid(itemid):
    """
    Retrives file that matches itemid

    """
    logger.warn("ROUTE: /fileid = %s" % itemid)
    path = zotero.get_attachment(itemid)
    logger.debug("path = %s" % path)

    if path is not None:
        path_, file_ = os.path.split(path)

        logger.debug("path_ = %s" % path_)
        logger.debug("file_ = %s" % file_)

        return static_file(file_, path_, download=file_)
    # return "File was  " + str(itemid) + " " + path
    else:
        return "Error: File not found"
Exemple #24
0
def route_all_collections_():
    """
    Show the user all Zotero collections 
    with a link to the items in the collections

    Page code
    ---------
    link-to-collection-id1    http://site-host/collectionid/id1
    link-to-collection-id2 :  http://site-host/collectionid/id2
    ...
    ...

    """
    logger.warn("ROUTE: /all_collections")
    collections = zotero.get_collections()

    html = html_collections_link(collections)

    return template(base_template, subtitle="Collections", content=html, backlink="index")
Exemple #25
0
def route_tagid(tagid):
    logger.warn("ROUTE: /tagid = %s" % tagid)

    tagname = zotero.get_tagname(tagid)
    items = zotero.filter_tag(tagid)

    subtilte_ = "Tag: " + tagname

    tags = zotero.get_related_tags(tagid)
    tags_links = [
        link_tpl("/tagid/%s" % tagid, tagname) for tagid, tagname in tags
    ]
    item_tag_links = " ".join(tags_links)
    related_tags = "Related Tags: %s<br />" % item_tag_links

    html = related_tags + html_item_link_list(items)

    return template(base_template,
                    subtitle=subtilte_,
                    content=html,
                    backlink="tags")
Exemple #26
0
def route_all_collections_():
    """
    Show the user all Zotero collections 
    with a link to the items in the collections

    Page code
    ---------
    link-to-collection-id1    http://site-host/collectionid/id1
    link-to-collection-id2 :  http://site-host/collectionid/id2
    ...
    ...

    """
    logger.warn("ROUTE: /all_collections")
    collections = zotero.get_collections()

    html = html_collections_link(collections)

    return template(base_template,
                    subtitle="Collections",
                    content=html,
                    backlink="index")
Exemple #27
0
def route_help():
    logger.warn("ROUTE: help")

    html = \
    """
    The ZOTSERVER - ZOTERO SERVER - Is a http web server that uses bottle framework. <br />
    This simple and lightweight and self contained web server allows to access the     <br />
    Zotero data from anywhere or from anywhere, any device, tablet, smartphone, PC ... <br />


    See updates on: %s
    """
    link = link_tpl("https://github.com/wolfprogrammer/zotserver",
                    "Zotserver Repository",
                    linktofile=False,
                    newtab=True)
    html = html % link

    return template(base_template,
                    subtitle="HELP",
                    content=html,
                    backlink="index")
Exemple #28
0
def route_index():

    logger.warn("ROUTE: /index")
    redirect("/collections")
Exemple #29
0
def get_favicon():
    logger.warn("ROUTE: /favicon")
    return static_file(favicon, ".")
Exemple #30
0
def get_favicon():
    logger.warn("ROUTE: /favicon")
    return static_file(favicon, ".")
Exemple #31
0
def main():
    data = {"PORT": PORT, "HOST": HOST}
    logger.warn("Starting server %s" % data)

    run(app=logged_app, host=HOST, port=PORT,  server=SERVER , debug=DEBUG, reloader=True)
Exemple #32
0
def route_index():

    logger.warn("ROUTE: /index")
    redirect("/collections")