Пример #1
0
def build_doc_context(include_dir, default_context):
    headers = ["oleg.h", "defs.h"]
    headers = map(lambda x: "{}/{}".format(include_dir, x), headers)
    for header_file in headers:
        oleg_header = open(header_file)
        docstring_special = ["DEFINE", "ENUM", "STRUCT", "DESCRIPTION",
                "RETURNS", "TYPEDEF"]

        reading_docs = False
        raw_code = ""
        doc_object = {}
        for line in oleg_header:
            docline = False
            stripped = line.strip()
            if stripped == '*/':
                continue

            # ThIs iS sOmE wEiRd FaLlThRouGh BuLlShIt
            if reading_docs and stripped.startswith("/*"):
                raise Exception("Yo I think you messed up your formatting. Read too far.")
            if "xXx" in line and "*" in stripped[:2]:
                (variable, value) = parse_variable(stripped)

                docline = True
                if not reading_docs:
                    doc_object["name"] = value
                    doc_object["type"] = variable
                    doc_object["params"] = []
                    reading_docs = True
                else:
                    if variable in docstring_special:
                        # SpEcIaL
                        doc_object[variable] = value
                    else:
                        doc_object["params"].append((variable, value))
            if reading_docs and not docline and stripped != "":
                raw_code = raw_code + line
            if stripped == "" and reading_docs:
                reading_docs = False
                doc_object["raw_code"] = raw_code
                if default_context.get(doc_object["type"], False):
                    default_context[doc_object["type"]].append(doc_object)
                else:
                    default_context[doc_object["type"]] = [doc_object]
                doc_object = {}
                raw_code = ""

        oleg_header.close()

    key_raw_code = [x for x in default_context['DEFINE'] if x['name'] == 'KEY_SIZE'][0]['raw_code']
    version_raw_code = [x for x in default_context['DEFINE'] if x['name'] == 'VERSION'][0]['raw_code']
    extracted_ks = key_raw_code.split(' ')[2].strip()
    extracted_version = version_raw_code.split(' ')[2].strip()
    extracted_version = extracted_version.replace('"', '')
    default_context['EXTRACTED_KEY_SIZE'] = extracted_ks
    default_context['EXTRACTED_VERSION'] = extracted_version

    return default_context
Пример #2
0
def parse_file(context, radical_file):
    tfile = open(TEMPLATE_DIR + radical_file, "r")
    file_meta = {}
    file_meta['file'] = TEMPLATE_DIR + radical_file
    file_meta['filename'] = radical_file
    file_meta['vars'] = {}
    file_meta['blocks'] = {}
    file_meta['loops'] = []

    reading_block = False
    block_str = ""
    end_str = ""
    block_name = ""

    loop_stack = None
    active_loops = 0
    for line in tfile:
        stripped = line.strip()
        if "xXx" in stripped and "=" in stripped.split("xXx")[1]:
            var = parse_variable(line)
            file_meta['vars'][var[0]] = var[1]
        elif "xXx TTYL xXx" == stripped:
            file_meta['blocks'][block_name] = block_str + end_str
            reading_block = False
            block_str = ""
            block_name = ""
            end_str = ""
        # We LoOpIn BaBy
        elif "xXx LOOP " in stripped:
            variables = stripped.split("xXx")[1].strip().replace("LOOP ",
                                                                 "").split(" ")
            active_loops = active_loops + 1
            print "We've entered timeskip {}!".format(variables[1])
            if loop_stack is None:
                loop_stack = {
                    "loop_depth": active_loops,
                    "loop_variable": variables[0],
                    "loop_str": "",
                    "loop_list": variables[1],
                    "loop_subloop": None
                }
            else:
                #ThIs WoRkS FoR MoRe ThAn TwO LoOpS
                def recurse_bro(item):
                    if item is None:
                        loop_stack["loop_subloop"] = {
                            "loop_depth": active_loops,
                            "loop_variable": variables[0],
                            "loop_str": "",
                            "loop_list": variables[1],
                            "loop_subloop": None
                        }
                    else:
                        recurse_bro(item["loop_subloop"])

                recurse_bro(loop_stack)

        elif "xXx BBL xXx" == stripped:
            active_loops = active_loops - 1
            if active_loops == 0:
                temp_loop_str = _render_loop(loop_stack, context)
                # AsSuMe WeRe In A bLoCk
                block_str = block_str + temp_loop_str
                # wE DoNe LoOpIn NoW
                loop_stack = None
        elif "xXx" in stripped and reading_block is True:
            if '@' in stripped:
                line = stripped = interpolate(stripped.replace("@", ""), {},
                                              context)
        elif "xXx" in stripped and reading_block is False:
            reading_block = True
            lstripped = line.split("xXx")
            block_name = lstripped[1].strip()
            block_str = lstripped[0]
            end_str = lstripped[2]
        if active_loops == 0 and reading_block is True and "xXx" not in stripped:
            block_str = block_str + line
        if active_loops > 0:

            def recurse_bro(item):
                if item is not None:
                    if item["loop_depth"] <= active_loops:
                        if "xXx LOOP" in stripped and item[
                                "loop_depth"] != active_loops:
                            item["loop_str"] = item["loop_str"] + stripped
                        elif "xXx LOOP" not in stripped:
                            item["loop_str"] = item["loop_str"] + stripped
                        recurse_bro(item["loop_subloop"])

            recurse_bro(loop_stack)

    return file_meta
def parse_file(context, radical_file):
    tfile = open(TEMPLATE_DIR + radical_file, "r")
    file_meta = {}
    file_meta['file'] = TEMPLATE_DIR + radical_file
    file_meta['filename'] = radical_file
    file_meta['vars'] = {}
    file_meta['blocks'] = {}
    file_meta['loops'] = []

    reading_block = False
    block_str = ""
    end_str = ""
    block_name = ""

    loop_stack = None
    active_loops = 0
    for line in tfile:
        stripped = line.strip()
        if "xXx" in stripped and "=" in stripped.split("xXx")[1]:
            var = parse_variable(line)
            file_meta['vars'][var[0]] = var[1]
        elif "xXx TTYL xXx" == stripped:
            file_meta['blocks'][block_name] = block_str + end_str
            reading_block = False
            block_str = ""
            block_name = ""
            end_str = ""
        # We LoOpIn BaBy
        elif "xXx LOOP " in stripped:
            variables = stripped.split("xXx")[1].strip().replace("LOOP ", "").split(" ")
            active_loops = active_loops + 1
            print "We've entered timeskip {}!".format(variables[1])
            if loop_stack is None:
                loop_stack = {
                    "loop_depth": active_loops,
                    "loop_variable": variables[0],
                    "loop_str": "",
                    "loop_list": variables[1],
                    "loop_subloop": None
                }
            else:
                #ThIs WoRkS FoR MoRe ThAn TwO LoOpS
                def recurse_bro(item):
                    if item is None:
                        loop_stack["loop_subloop"] = {
                            "loop_depth": active_loops,
                            "loop_variable": variables[0],
                            "loop_str": "",
                            "loop_list": variables[1],
                            "loop_subloop": None
                        }
                    else:
                        recurse_bro(item["loop_subloop"])
                recurse_bro(loop_stack)

        elif "xXx BBL xXx" == stripped:
            active_loops = active_loops - 1
            if active_loops == 0:
                temp_loop_str = _render_loop(loop_stack, context)
                # AsSuMe WeRe In A bLoCk
                block_str = block_str + temp_loop_str
                # wE DoNe LoOpIn NoW
                loop_stack = None
        elif "xXx" in stripped and reading_block is True:
            if '@' in stripped:
                line = stripped = interpolate(stripped.replace("@", ""), {}, context)
        elif "xXx" in stripped and reading_block is False:
            reading_block = True
            lstripped = line.split("xXx")
            block_name = lstripped[1].strip()
            block_str = lstripped[0]
            end_str = lstripped[2]
        if active_loops == 0 and reading_block is True and "xXx" not in stripped:
            block_str = block_str + line
        if active_loops > 0:
            def recurse_bro(item):
                if item is not None:
                    if item["loop_depth"] <= active_loops:
                        if "xXx LOOP" in stripped and item["loop_depth"] != active_loops:
                            item["loop_str"] = item["loop_str"] + stripped
                        elif "xXx LOOP" not in stripped:
                            item["loop_str"] = item["loop_str"] + stripped
                        recurse_bro(item["loop_subloop"])
            recurse_bro(loop_stack)

    return file_meta
Пример #4
0
def build_doc_context(default_context):
    output = subprocess.check_output("cd OlegDB && git tag --list", shell=True)
    default_context['docs'] = {}
    default_context['ALL_VERSIONS'] = []
    versions = sorted(output.strip().split("\n"))
    versions.append("master")

    # Prepare a default documentation for versions pre 0.1.2
    default_documentation_html = open("./templates/documentation_default.html")
    default_documentation_nav_html = open("./templates/documentation_default_nav.html")
    DEFAULT_DOCUMENTATION = to_return = [{
        "children": [],
        "name": "Overview",
        "body": default_documentation_html.read(),
        "nav": default_documentation_nav_html.read()
    }]
    default_documentation_html.close()
    default_documentation_nav_html.close()

    for version in versions:
        print "Checking out {}".format(version)
        cmd = "cd OlegDB && git checkout {} &> /dev/null".format(version)
        subprocess.check_output(cmd, shell=True)
        headers = ["oleg.h", "defs.h"]
        headers = map(lambda x: "{}/{}".format(INCLUDE_DIR, x), headers)
        version_context = {}
        for header_file in headers:
            try:
                oleg_header = open(header_file)
            except IOError as e:
                print e
                continue

            docstring_special = ["DEFINE", "ENUM", "STRUCT", "DESCRIPTION",
                    "RETURNS", "TYPEDEF"]

            reading_docs = False
            raw_code = ""
            doc_object = {}

            for line in oleg_header:
                docline = False
                stripped = line.strip()
                if stripped == '*/':
                    continue

                # ThIs iS sOmE wEiRd FaLlThRouGh BuLlShIt
                if reading_docs and stripped.startswith("/*"):
                    raise Exception("Yo I think you messed up your formatting. Read too far.")
                if "xXx" in line and "*" in stripped[:2]:
                    (variable, value) = parse_variable(stripped)

                    docline = True
                    if not reading_docs:
                        doc_object["name"] = value
                        doc_object["type"] = variable
                        doc_object["params"] = []
                        reading_docs = True
                    else:
                        if variable in docstring_special:
                            # SpEcIaL
                            doc_object[variable] = value
                        else:
                            doc_object["params"].append((variable, value))
                if reading_docs and not docline and stripped != "":
                    raw_code = raw_code + line
                if stripped == "" and reading_docs:
                    reading_docs = False
                    doc_object["raw_code"] = raw_code
                    if version_context.get(doc_object["type"], False):
                        version_context[doc_object["type"]].append(doc_object)
                    else:
                        version_context[doc_object["type"]] = [doc_object]
                    doc_object = {}
                    raw_code = ""

            oleg_header.close()

        key_raw_code = [x for x in version_context['DEFINE'] if x['name'] == 'KEY_SIZE'][0]['raw_code']
        version_raw_code = [x for x in version_context['DEFINE'] if x['name'] == 'VERSION'][0]['raw_code']
        extracted_ks = key_raw_code.split(' ')[2].strip()
        extracted_version = version_raw_code.split(' ')[2].strip()
        extracted_version = extracted_version.replace('"', '')
        if version == 'master':
            default_context['EXTRACTED_KEY_SIZE'] = extracted_ks
            default_context['EXTRACTED_VERSION'] = extracted_version
        default_context['docs'][extracted_version] = version_context
        default_context['ALL_VERSIONS'].append(extracted_version)
        handwritten = try_to_build_documentation_tree(default_context)
        if len(handwritten) != 0:
            default_context["docs"][extracted_version]["DEFAULT_DOCUMENTATION"] = handwritten
        else:
            default_context["docs"][extracted_version]["DEFAULT_DOCUMENTATION"] = DEFAULT_DOCUMENTATION

    return default_context
Пример #5
0
def build_doc_context(default_context):
    output = subprocess.check_output("cd 38-Moths && git tag --list", shell=True)
    default_context['docs'] = {}
    default_context['ALL_VERSIONS'] = []
    versions = sorted(output.strip().split("\n"))
    versions.append("master")

    for version in versions:
        print "Checking out {}".format(version)
        cmd = "cd 38-Moths && git checkout {} &> /dev/null".format(version)
        subprocess.check_output(cmd, shell=True)
        headers = ["38-moths.h", "server.h", "grengine.h", "greshunkel.h", "utils.h", "vector.h"]
        headers = map(lambda x: "{}/{}".format(INCLUDE_DIR, x), headers)
        version_context = {}
        for header_file in headers:
            try:
                oleg_header = open(header_file)
            except IOError as e:
                print e
                continue

            docstring_special = ["DEFINE", "ENUM", "STRUCT", "DESCRIPTION",
                    "RETURNS", "TYPEDEF"]

            reading_docs = False
            raw_code = ""
            doc_object = {}

            for line in oleg_header:
                docline = False
                stripped = line.strip()
                if stripped == '*/':
                    continue

                # ThIs iS sOmE wEiRd FaLlThRouGh BuLlShIt
                if reading_docs and stripped.startswith("/*"):
                    raise Exception("Yo I think you messed up your formatting. Read too far.")
                if "xXx" in line and "*" in stripped[:2]:
                    (variable, value) = parse_variable(stripped)

                    docline = True
                    if not reading_docs:
                        doc_object["name"] = value
                        doc_object["type"] = variable
                        doc_object["params"] = []
                        reading_docs = True
                    else:
                        if variable in docstring_special:
                            # SpEcIaL
                            doc_object[variable] = value
                        else:
                            doc_object["params"].append((variable, value))
                if reading_docs and not docline and stripped != "":
                    raw_code = raw_code + line
                if stripped == "" and reading_docs:
                    reading_docs = False
                    doc_object["raw_code"] = raw_code
                    if version_context.get(doc_object["type"], False):
                        version_context[doc_object["type"]].append(doc_object)
                    else:
                        version_context[doc_object["type"]] = [doc_object]
                    doc_object = {}
                    raw_code = ""

            oleg_header.close()

        version_raw_code = [x for x in version_context['DEFINE'] if x['name'] == 'VERSION'][0]['raw_code']
        extracted_version = version_raw_code.split(' ')[2].strip()
        extracted_version = extracted_version.replace('"', '')
        if version == 'master':
            default_context['EXTRACTED_VERSION'] = extracted_version
        default_context['docs'][extracted_version] = version_context
        default_context['ALL_VERSIONS'].append(extracted_version)
        handwritten = try_to_build_documentation_tree(default_context)
        default_context["docs"][extracted_version]["DEFAULT_DOCUMENTATION"] = handwritten

    return default_context
Пример #6
0
def build_doc_context(default_context):
    include_dir = "./OlegDB/include/"
    output = subprocess.check_output("cd OlegDB && git tag --list", shell=True)
    default_context['docs'] = {}
    default_context['ALL_VERSIONS'] = []
    versions = [output.strip()]
    versions.append("master")

    for version in versions:
        print "Checking out {}".format(version)
        cmd = "cd OlegDB && git checkout {} &> /dev/null".format(version)
        subprocess.call(cmd, shell=True)
        headers = ["oleg.h", "defs.h"]
        headers = map(lambda x: "{}/{}".format(include_dir, x), headers)
        version_context = {}
        for header_file in headers:
            try:
                oleg_header = open(header_file)
            except IOError as e:
                print e
                continue

            docstring_special = [
                "DEFINE", "ENUM", "STRUCT", "DESCRIPTION", "RETURNS", "TYPEDEF"
            ]

            reading_docs = False
            raw_code = ""
            doc_object = {}

            for line in oleg_header:
                docline = False
                stripped = line.strip()
                if stripped == '*/':
                    continue

                # ThIs iS sOmE wEiRd FaLlThRouGh BuLlShIt
                if reading_docs and stripped.startswith("/*"):
                    raise Exception(
                        "Yo I think you messed up your formatting. Read too far."
                    )
                if "xXx" in line and "*" in stripped[:2]:
                    (variable, value) = parse_variable(stripped)

                    docline = True
                    if not reading_docs:
                        doc_object["name"] = value
                        doc_object["type"] = variable
                        doc_object["params"] = []
                        reading_docs = True
                    else:
                        if variable in docstring_special:
                            # SpEcIaL
                            doc_object[variable] = value
                        else:
                            doc_object["params"].append((variable, value))
                if reading_docs and not docline and stripped != "":
                    raw_code = raw_code + line
                if stripped == "" and reading_docs:
                    reading_docs = False
                    doc_object["raw_code"] = raw_code
                    if version_context.get(doc_object["type"], False):
                        version_context[doc_object["type"]].append(doc_object)
                    else:
                        version_context[doc_object["type"]] = [doc_object]
                    doc_object = {}
                    raw_code = ""

            oleg_header.close()

        key_raw_code = [
            x for x in version_context['DEFINE'] if x['name'] == 'KEY_SIZE'
        ][0]['raw_code']
        version_raw_code = [
            x for x in version_context['DEFINE'] if x['name'] == 'VERSION'
        ][0]['raw_code']
        extracted_ks = key_raw_code.split(' ')[2].strip()
        extracted_version = version_raw_code.split(' ')[2].strip()
        extracted_version = extracted_version.replace('"', '')
        if version == 'master':
            default_context['EXTRACTED_KEY_SIZE'] = extracted_ks
            default_context['EXTRACTED_VERSION'] = extracted_version
        default_context['docs'][extracted_version] = version_context
        default_context['ALL_VERSIONS'].append(extracted_version)

    return default_context
Пример #7
0
def main(context):
    all_templates = []
    for radical_file in listdir(TEMPLATE_DIR):
        if not radical_file.endswith(".html"):
            continue

        tfile = open(TEMPLATE_DIR + radical_file, "r")
        file_meta = {}
        file_meta['file'] = TEMPLATE_DIR + radical_file
        file_meta['filename'] = radical_file
        file_meta['vars'] = {}
        file_meta['blocks'] = {}
        file_meta['loops'] = []

        reading_block = False
        block_str = ""
        end_str = ""
        block_name = ""

        loop_stack = None
        active_loops = 0
        for line in tfile:
            stripped = line.strip()
            if "xXx" in stripped and "=" in stripped.split("xXx")[1]:
                var = parse_variable(line)
                file_meta['vars'][var[0]] = var[1]
            elif "xXx TTYL xXx" == stripped:
                file_meta['blocks'][block_name] = block_str + end_str
                reading_block = False
                block_str = ""
                block_name = ""
                end_str = ""
            # We LoOpIn BaBy
            elif "xXx LOOP " in stripped:
                variables = stripped.split("xXx")[1].strip().replace("LOOP ", "").split(" ")
                active_loops = active_loops + 1
                print "We've entered timeskip {}!".format(variables[1])
                if loop_stack is None:
                    loop_stack = {
                        "loop_depth": active_loops,
                        "loop_variable": variables[0],
                        "loop_str": "",
                        "loop_list": variables[1],
                        "loop_subloop": None
                    }
                else:
                    #ThIs WoRkS FoR MoRe ThAn TwO LoOpS
                    def recurse_bro(item):
                        if item is None:
                            loop_stack["loop_subloop"] = {
                                "loop_depth": active_loops,
                                "loop_variable": variables[0],
                                "loop_str": "",
                                "loop_list": variables[1],
                                "loop_subloop": None
                            }
                        else:
                            recurse_bro(item["loop_subloop"])
                    recurse_bro(loop_stack)

            elif "xXx BBL xXx" == stripped:
                active_loops = active_loops - 1
                if active_loops == 0:
                    temp_loop_str = _render_loop(loop_stack, context)
                    # AsSuMe WeRe In A bLoCk
                    block_str = block_str + temp_loop_str
                    # wE DoNe LoOpIn NoW
                    loop_stack = None
            elif "xXx" in stripped and reading_block is True:
                if '@' in stripped:
                    line = stripped = interpolate(stripped.replace("@", ""), {}, context)
            elif "xXx" in stripped and reading_block is False:
                reading_block = True
                lstripped = line.split("xXx")
                block_name = lstripped[1].strip()
                block_str = lstripped[0]
                end_str = lstripped[2]
            if active_loops == 0 and reading_block is True and "xXx" not in stripped:
                block_str = block_str + line
            if active_loops > 0:
                def recurse_bro(item):
                    if item is not None:
                        if item["loop_depth"] <= active_loops:
                            if "xXx LOOP" in stripped and item["loop_depth"] != active_loops:
                                item["loop_str"] = item["loop_str"] + stripped
                            elif "xXx LOOP" not in stripped:
                                item["loop_str"] = item["loop_str"] + stripped
                            recurse_bro(item["loop_subloop"])
                recurse_bro(loop_stack)

        all_templates.append(file_meta)

    # BuIlD a SiCk TrEe oF TeMpLaTeS yO
    tree = {}
    for tfile in all_templates:
        if tfile['vars'].get('PARENT'):
            parent = tfile['vars']['PARENT']
            if tree.get(parent):
                tree[parent]['children'].append(tfile)
            else:
                tree[parent] = {
                        'children': [tfile]
                    }

    for base_file in tree:
        if base_file != BLOGPOST_TEMPLATE:
            _render_file(tree[base_file])

    #for post in listdir(POSTS_DIR):
    #    import ipdb; ipdb.set_trace()
    #    "ASDF"

    # BeCaUsE WhY NoT
    return 0
Пример #8
0
def build_doc_context(default_context):
    include_dir = "./OlegDB/include/"
    output = subprocess.check_output("cd OlegDB && git tag --list", shell=True)
    default_context['docs'] = {}
    default_context['ALL_VERSIONS'] = []
    versions = [output.strip()]
    versions.append("master")

    for version in versions:
        print "Checking out {}".format(version)
        cmd = "cd OlegDB && git checkout {} &> /dev/null".format(version)
        subprocess.call(cmd, shell=True)
        headers = ["oleg.h", "defs.h"]
        headers = map(lambda x: "{}/{}".format(include_dir, x), headers)
        version_context = {}
        for header_file in headers:
            try:
                oleg_header = open(header_file)
            except IOError as e:
                print e
                continue

            docstring_special = ["DEFINE", "ENUM", "STRUCT", "DESCRIPTION",
                    "RETURNS", "TYPEDEF"]

            reading_docs = False
            raw_code = ""
            doc_object = {}

            for line in oleg_header:
                docline = False
                stripped = line.strip()
                if stripped == '*/':
                    continue

                # ThIs iS sOmE wEiRd FaLlThRouGh BuLlShIt
                if reading_docs and stripped.startswith("/*"):
                    raise Exception("Yo I think you messed up your formatting. Read too far.")
                if "xXx" in line and "*" in stripped[:2]:
                    (variable, value) = parse_variable(stripped)

                    docline = True
                    if not reading_docs:
                        doc_object["name"] = value
                        doc_object["type"] = variable
                        doc_object["params"] = []
                        reading_docs = True
                    else:
                        if variable in docstring_special:
                            # SpEcIaL
                            doc_object[variable] = value
                        else:
                            doc_object["params"].append((variable, value))
                if reading_docs and not docline and stripped != "":
                    raw_code = raw_code + line
                if stripped == "" and reading_docs:
                    reading_docs = False
                    doc_object["raw_code"] = raw_code
                    if version_context.get(doc_object["type"], False):
                        version_context[doc_object["type"]].append(doc_object)
                    else:
                        version_context[doc_object["type"]] = [doc_object]
                    doc_object = {}
                    raw_code = ""

            oleg_header.close()

        key_raw_code = [x for x in version_context['DEFINE'] if x['name'] == 'KEY_SIZE'][0]['raw_code']
        version_raw_code = [x for x in version_context['DEFINE'] if x['name'] == 'VERSION'][0]['raw_code']
        extracted_ks = key_raw_code.split(' ')[2].strip()
        extracted_version = version_raw_code.split(' ')[2].strip()
        extracted_version = extracted_version.replace('"', '')
        if version == 'master':
            default_context['EXTRACTED_KEY_SIZE'] = extracted_ks
            default_context['EXTRACTED_VERSION'] = extracted_version
        default_context['docs'][extracted_version] = version_context
        default_context['ALL_VERSIONS'].append(extracted_version)

    return default_context