コード例 #1
0
ファイル: views.py プロジェクト: nakee/Sefaria-Project
def create_commentator_version(request, commentator, book, lang, vtitle,
                               vsource):
    from sefaria.helper.text import create_commentator_and_commentary_version
    create_commentator_and_commentary_version(commentator, book, lang, vtitle,
                                              vsource)
    scache.reset_texts_cache()
    return HttpResponseRedirect("/add/%s" % commentator)
コード例 #2
0
ファイル: views.py プロジェクト: ngocthanhit/Sefaria-Project
def create_commentator_version(request, commentator, book, lang, vtitle, vsource):
    from sefaria.helper.text import create_commentator_and_commentary_version

    ht = request.GET.get("heTitle", None)
    create_commentator_and_commentary_version(commentator, book, lang, vtitle, vsource, ht)
    scache.reset_texts_cache()
    return HttpResponseRedirect("/add/%s" % commentator)
コード例 #3
0
def resize_text(title, new_structure, upsize_in_place=False):
    # todo: Needs to be converted to objects, but no usages seen in the wild.
    """
    Change text structure for text named 'title'
    to 'new_structure' (a list of strings naming section names)

    Changes index record as well as restructuring any text that is currently saved.

    When increasing size, any existing text will become the first segment of the new level
    ["One", "Two", "Three"] -> [["One"], ["Two"], ["Three"]]

    If upsize_in_place==True, existing text will stay in tact, but be wrapped in new depth:
    ["One", "Two", "Three"] -> [["One", "Two", "Three"]]

    When decreasing size, information is lost as any existing segments are concatenated with " "
    [["One1", "One2"], ["Two1", "Two2"], ["Three1", "Three2"]] - >["One1 One2", "Two1 Two2", "Three1 Three2"]

    """
    index = db.index.find_one({"title": title})
    if not index:
        return False

    old_structure = index["sectionNames"]
    index["sectionNames"] = new_structure
    db.index.save(index)

    delta = len(new_structure) - len(old_structure)
    if delta == 0:
        return True

    texts = db.texts.find({"title": title})
    for text in texts:
        if delta > 0 and upsize_in_place:
            resized = text["chapter"]
            for i in range(delta):
                resized = [resized]
        else:
            resized = JaggedTextArray(text["chapter"]).resize(delta).array()

        text["chapter"] = resized
        db.texts.save(text)

    # TODO Rewrite any existing Links
    # TODO Rewrite any exisitng History items

    summaries.update_summaries_on_change(title)
    scache.reset_texts_cache()

    return True
コード例 #4
0
ファイル: text.py プロジェクト: bachrach44/Sefaria-Project
def resize_text(title, new_structure, upsize_in_place=False):
    # todo: Needs to be converted to objects, but no usages seen in the wild.
    """
    Change text structure for text named 'title'
    to 'new_structure' (a list of strings naming section names)

    Changes index record as well as restructuring any text that is currently saved.

    When increasing size, any existing text will become the first segment of the new level
    ["One", "Two", "Three"] -> [["One"], ["Two"], ["Three"]]

    If upsize_in_place==True, existing text will stay in tact, but be wrapped in new depth:
    ["One", "Two", "Three"] -> [["One", "Two", "Three"]]

    When decreasing size, information is lost as any existing segments are concatenated with " "
    [["One1", "One2"], ["Two1", "Two2"], ["Three1", "Three2"]] - >["One1 One2", "Two1 Two2", "Three1 Three2"]

    """
    index = db.index.find_one({"title": title})
    if not index:
        return False

    old_structure = index["sectionNames"]
    index["sectionNames"] = new_structure
    db.index.save(index)

    delta = len(new_structure) - len(old_structure)
    if delta == 0:
        return True

    texts = db.texts.find({"title": title})
    for text in texts:
        if delta > 0 and upsize_in_place:
            resized = text["chapter"]
            for i in range(delta):
                resized = [resized]
        else:
            resized = JaggedTextArray(text["chapter"]).resize(delta).array()

        text["chapter"] = resized
        db.texts.save(text)

    # TODO Rewrite any existing Links
    # TODO Rewrite any exisitng History items

    summaries.update_summaries_on_change(title)
    scache.reset_texts_cache()

    return True
コード例 #5
0
ファイル: summaries.py プロジェクト: rneiss/Sefaria-Project
def update_summaries():
    """
    Update all stored documents which summarize known and available texts
    """
    update_table_of_contents()
    scache.reset_texts_cache()
コード例 #6
0
def reset_cache(request):
    scache.reset_texts_cache()
    global user_links
    user_links = {}
    return HttpResponseRedirect("/?m=Cache-Reset")
コード例 #7
0
ファイル: summaries.py プロジェクト: spenhos/Sefaria-Project
def update_summaries():
    """
    Update all stored documents which summarize known and available texts
    """
    update_table_of_contents()
    scache.reset_texts_cache()
コード例 #8
0
# -*- coding: utf-8 -*-

import argparse


""" The main function, runs when called from the CLI"""
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("commentator_name", help="commentator's name")
    parser.add_argument("existing_book", help="title of existing index record for the comemntary")
    parser.add_argument("language", help="version language", choices=['en', 'he'])
    parser.add_argument("version_title", help="version title for the new version")
    parser.add_argument("version_source", help="version source for the new version")
    args = parser.parse_args()
    print args
    try:
        from sefaria.helper.text import create_commentator_and_commentary_version
        from sefaria.system import cache as scache
        create_commentator_and_commentary_version(args.commentator_name, args.existing_book, args.language, args.version_title,
                                                  args.version_source)
        scache.reset_texts_cache()
    except Exception as e:
        print "{} exiting.".format(e)