def main(root):
    # Directory stuff
    dir_path = root
    dir_path = os.path.join(cd_up(root, 2), "Current Test Version", "FrameLib")
    tutorial_path = os.path.join(dir_path, "docs", "tutorial-patchers")
    coll_output_path = os.path.join(tutorial_path, "tutorial_names.txt")

    # If dir doesnt exist make, otherwise edit existing
    coll = open(coll_output_path, "w+")
    coll.truncate(0)

    # Find File Names
    all_files = os.listdir(
        tutorial_path
    )  # store all the file names of the tutorial path in an array

    # Only get the tutorial names
    tutorial_names = []

    # Have to do an additional loop here to sort all the tutorials alpha-numerically
    for item in all_files:
        if item.startswith("_"):
            tutorial_names.append(item)
    tutorial_names.sort()

    # Write the contents of tutorial_names to the coll with some f strings
    idx = 0
    for item in tutorial_names:  # each item loop over all tutorial names list
        coll.write(f"{idx}, {item};\n")  # write that item into the buffer
        idx += 1

    coll.close()
Exemplo n.º 2
0
def main():

    root = cd_up(get_path(), 1)

    sign_off()
    space()

    ## Stage 0
    ## There is a prior stage here where make_object_list.py is called by Xcode.
    ## This produces the header file which Build_Max_Docs.cpp uses to know about FrameLib objects and types.

    ## Creates a category database in .json format.
    ## The JSON file is used by edit_raw_XML.py to assign object categories to the xml files.
    print("1. Building Category Database")
    create_category_database.main(root)
    hyp()

    ## The purpose of this script is to set the categories for the Raw_XML files.
    ## C++ doesnt know about the categories at XML creation and its easier to iterate file structures in python.
    ## Edited XML files are copied from /tmp/ to the refpages directory
    print("2. Editing XML Files")
    edit_raw_XML.main(root)
    hyp()

    ## This script creates a dictionary used to display specific object info in the extras Max Patch.
    ## Similar to the qlookup, but is specifically used to display the digest with mouse hovering
    print("3. Building dlookup")
    parse_to_dlookup.main(root)
    hyp()

    ## This script creates a dictionary that contains specific object information.
    ## This provides the dynamic hover behaviour
    print("4. Building qlookup")
    parse_to_qlookup.main(root)
    hyp()

    ## Creates a dictionary used to display names and descriptions of tutorials in the extras Max Patch.
    ## The tutorials are categorised by difficulty. {Beginner, Intermediate, Advanced}
    print("5. Building tlookup")
    parse_to_tlookup.main(root)
    hyp()

    ## Creates a dict containing information about object parameters. This is used by the help file template.
    print("6. Building jlookup")
    parse_to_jlookup.main(root)

    ## Creates a coll containing the file names of the tutorials. Makes it a bit easier to load them.
    print("7. Building tutorial name coll")
    create_tutorial_coll.main(root)
    hyp()

    ## Deletes all temporay files and cleans up process
    print("8. Cleaning up")
    cleanup.main(root)
    hyp()
    print(" ")
    print("Completed all python scripts.")
def main(root):
    """
    Creates a dict for the Max Documentation system.
    This dict contains is essential for maxObjectLauncher/Refpages to pull the right info.

    Args:
        arg1: passes the root of the python files from the master script. Creates relative directories.
    """

    yaml_file = os.path.join(root, "object_relationships.yaml")
    object_info = None

    with open(yaml_file, "r") as stream:
        try:
            object_info = yaml.safe_load(stream)
        except yaml.YAMLError as exc:
            print(exc)

    bad_entries = [".DS_Store", "_c74_ref_modules.xml"]

    dir_path = root
    dir_path = os.path.join(cd_up(root, 2), "Current Test Version", "FrameLib")
    ref_dir = os.path.join(dir_path, "docs", "refpages")
    obj_lookup = os.path.join(dir_path, "interfaces",
                              "FrameLib-obj-qlookup.json")

    worker = qParseAndBuild()

    # Make a list of file names and remove bad entries
    refpages = thin_list(os.listdir(ref_dir), bad_entries)

    # Check if any files were found and do your thing
    if refpages:
        for filename in refpages:
            current_category = filename
            source_file_name = os.path.join(ref_dir, filename)

            for filename in os.listdir(source_file_name):
                source_file = os.path.join(ref_dir, current_category, filename)
                worker.extract_from_refpage(source_file)
                worker.extract_keywords(object_info)
                worker.extract_seealso(object_info)
                worker.build_json_file()

            # Write out to JSON
        write_json(obj_lookup, worker.d_master_dict)
Exemplo n.º 4
0
def main(root):
    """
    This creates a category database in .json format.
    This is used by edit_raw_XML.py to assign object categories to the xml files.
    """
    dir_path = root
    object_path = os.path.join(cd_up(root, 2), "FrameLib_Max_Objects")
    output_path = os.path.join(dir_path, "__tmp__", "db",
                               "category_database.json")

    file_categories = os.listdir(object_path)

    try:
        file_categories.remove("_MaxSDK_")
    except ValueError:
        print("No _MaxSDK_ to delete")
        pass

    try:
        file_categories.remove(".DS_Store")
    except ValueError:
        print("No .DS_Store")
        pass

    try:
        file_categories.remove("Common")
    except ValueError:
        print("No common folder")
        pass

    file_categories.sort()
    category_dict = {}

    for item in file_categories:
        files = os.listdir(os.path.join(object_path, item))
        if "ibuffer" in files:
            files.remove("ibuffer")
        # some max categories already overlap with framelib categories (timing for example). This just maps Timing -> fl_timing to avoid any duplication issues
        item = f"FrameLib {item}"
        for i in range(len(files)):
            files[i] = strip_extension(files[i], 1)
        category_dict[item] = files

    ## Write dict into JSON file
    write_json(output_path, category_dict)
Exemplo n.º 5
0
def main(root):
    """
    Creates tutorial information and stores it in a dictionary format. 
    This information is displayed to the user in a umenu.

    Args:
        arg1: passes the root of the python files from the master script. Creates relative directories.
    """

    # Directory stuff #
    dir_path = root
    dir_path = os.path.join(cd_up(root, 2), "Current Test Version", "FrameLib")
    ref_dir = os.path.join(dir_path, "docs", "tutorials", "FrameLib-tut",
                           "00_fl_index.maxtut.xml")
    obj_lookup = os.path.join(dir_path, "interfaces",
                              "FrameLib-obj-tlookup.json")

    worker = tParseAndBuild()

    worker.extract_from_refpage(ref_dir)

    write_json(obj_lookup, worker.d_skeleton)
def main(root):
    """
    Creates a dict for the Max Documentation system.
    This dict contains more detailed information displayed in real-time when hovering over a certain tutorial in the umenu.

    Args:
        arg1: passes the root of the python files from the master script. Creates relative directories.
    """

    bad_entries = [".DS_Store", "_c74_ref_modules.xml"]

    dir_path = root
    dir_path = os.path.join(cd_up(root, 2), "Current Test Version", "FrameLib")
    ref_dir = os.path.join(dir_path, "docs", "refpages")
    obj_lookup = os.path.join(dir_path, "interfaces",
                              "FrameLib-obj-jlookup.json")

    worker = jParseAndBuild()  # make an instance of the class

    # Make a list of file names and remove bad entries
    refpages = os.listdir(ref_dir)
    for badness in bad_entries:
        if badness in refpages:
            refpages.remove(badness)

    # Check if any files were found and do your thing
    if refpages:
        for filename in refpages:
            current_category = filename
            source_file_name = os.path.join(ref_dir, filename)

            for filename in os.listdir(source_file_name):
                if filename != ".DS_Store":
                    source_file = os.path.join(ref_dir, current_category,
                                               filename)
                    worker.extract_from_refpage(source_file)

        write_json(obj_lookup, worker.j_master_dict)
def main(root):
    """
    A simplified version of the qlookup used to display information about specific objects when hovered over in the umenu.
    The qlookup might replace this entire script.

    Args:
        arg1: passes the root of the python files from the master script. Creates relative directories.
    """
    bad_entries = [".DS_Store", "_c74_ref_modules.xml"]
    # Directory stuff #
    dir_path = root
    dir_path = os.path.join(cd_up(root, 2), "Current Test Version", "FrameLib")
    ref_dir = os.path.join(dir_path, "docs", "refpages")
    obj_lookup = os.path.join(dir_path, "interfaces",
                              "FrameLib-obj-dlookup.json")

    worker = dParseAndBuild()

    # Make a list of file names and remove bad entries
    refpages = remove_ds(os.listdir(ref_dir))
    for badness in bad_entries:
        if badness in refpages:
            refpages.remove(badness)

    # Check if any files were found and do your thing
    if refpages:
        for filename in refpages:
            current_category = filename
            source_file_name = os.path.join(ref_dir, filename)

            for filename in os.listdir(source_file_name):
                source_file = os.path.join(ref_dir, current_category, filename)
                worker.extract_from_refpage(source_file)

        write_json(obj_lookup, worker.d_master_dict)
    else:
        print("Found no XML files to parse. Moving on to next stage.")
Exemplo n.º 8
0
def main(root):
    """
    The purpose of this script is to set the categories for the Raw_XML files. C++ doesnt know about the categories and its easier to iterate file structures in python. So we do it here after the xml has been generated.
    It also copies the xml files to the refpages directory.
    """
    ### directories ###
    dir_path = root
    raw_xml_path = os.path.join(dir_path, "__tmp__", "raw_xml")
    move_to_path = os.path.join(cd_up(root, 2), "Current Test Version",
                                "FrameLib", "docs", "refpages")
    category_database_path = os.path.join(dir_path, "__tmp__", "db",
                                          "category_database.json")
    yaml_file = os.path.join(root, "object_relationships.yaml")
    object_info = None

    with open(yaml_file, "r") as stream:
        try:
            object_info = yaml.safe_load(stream)
        except yaml.YAMLError as exc:
            print(exc)

    ### Load the category_database.json ###
    category_database = read_json(category_database_path)

    ### Get category of file ###
    def find_object_category(obj_string):
        """
        Finds the dictionary name for an object inside of that dictionary.
        Is used to work backwards and find which category each object belongs to.
        """
        for key in category_database:
            category_object_list = category_database[key]
            for obj in category_object_list:
                if obj == obj_string:
                    return key

    def indent(elem, level=0):
        i = "\n" + level * "  "
        if len(elem):
            if not elem.text or not elem.text.strip():
                elem.text = i + "  "
            if not elem.tail or not elem.tail.strip():
                elem.tail = i
            for elem in elem:
                indent(elem, level + 1)
            if not elem.tail or not elem.tail.strip():
                elem.tail = i
        else:
            if level and (not elem.tail or not elem.tail.strip()):
                elem.tail = i

    try:
        raw_xml_list = remove_ds(os.listdir(
            raw_xml_path))  # make a list with all the raw xml files in them
    except FileNotFoundError:
        print(
            "Unable to find any xml files to parse. Moving on without parsing object references."
        )
    else:
        for raw_xml in raw_xml_list:
            obj_name = strip_extension(raw_xml, 2)  # just get the file name
            category = find_object_category(
                obj_name)  # get the category of the object name
            tree = et.parse(os.path.join(raw_xml_path,
                                         raw_xml))  # parse the xml file
            root = tree.getroot()  # get root and assign to root var
            root.set(
                "category", category
            )  # set category attribute of root to the category found in json
            ### This replaces the meta data tag. It produces a lot of errors which are filtered by the try/except structure but it should be changed to something else ###
            if category != None:
                for (elem) in (root.getiterator(
                )):  # for all the elements in the root of the xml tree
                    try:
                        elem.text = elem.text.replace(
                            "!@#@#$", category
                        )  # try to replace specific text with category found in json
                    except AttributeError:
                        pass  # else pass because it will throw some errors
            if not os.path.exists(os.path.join(move_to_path, category)):
                try:
                    os.makedirs(os.path.join(move_to_path))
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise  # if directory is made between os.path.exists and os.makedirs calls this will fail with an OSError. This raises an error to warn the user rather than pushing on

            # Create seealso and keywords
            details = object_info[obj_name]
            for elem in root:
                if elem.tag == "seealsolist":
                    for seealso in details["seealso"]:
                        new_element = et.Element("seealso")
                        new_element.set("Name", seealso)
                        elem.append(new_element)
                if elem.tag == "misc" and elem.attrib["name"] == "Discussion":
                    for sub_elem in elem:
                        if (sub_elem.tag == "entry"
                                and sub_elem.attrib["name"] == "Keywords"):
                            for desc in sub_elem:
                                temp_string = ",".join(details["keywords"])
                                desc.text = temp_string
            # Pretty Print #
            indent(root)
            out_path = os.path.join(move_to_path, category, raw_xml)
            try:
                os.makedirs(os.path.join(move_to_path, category))
            except OSError as e:
                if e.errno != errno.EEXIST:
                    raise
            tree.write(out_path)  # write out to new XML
Exemplo n.º 9
0
import os
from FrameLibDocs.utils import get_path, check_make, cd_up

root = cd_up(get_path(), 1)

# Directories
temporary = os.path.join(root, "__tmp__")
databases = os.path.join(temporary, "db")
raw_xml   = os.path.join(temporary, "raw_xml")

# Check and make
check_make(temporary)
check_make(databases)
check_make(raw_xml)
Exemplo n.º 10
0
import os
import re
from FrameLibDocs.utils import get_path, cd_up
from FrameLibDocs.strippers import strip_space, strip_extension

root = cd_up(get_path(), 1)
print(root)

# Create the Max_Object_list.h and add skeleton
op = open(os.path.join(root, "Max_Object_List.h"), "w+")
op.write('#include "FrameLib_TypeList.h"')
op.write("\n \n")
op.write("using FrameLib_DSPList = detail::FrameLib_Typelist<")
op.write("\n \n")

# Directory formation
max_source_folder = os.path.join(
    cd_up(root, 2),
    'FrameLib_Max_Objects',
)
# A list of the categories. Is used to find all the source files.
max_source_categories = os.listdir(
    max_source_folder
)  

# Try removing unnecessary stuff, otherwise throw some info that it was not there
try:
    max_source_categories.remove("_MaxSDK_")
except ValueError:
    print("No _MaxSDK_ to delete")
    pass
Exemplo n.º 11
0
# Check if the help_file_templates folder exists if not mk
def check_make(path_to_check):
    if not os.path.isdir(path_to_check):
        os.mkdir(path_to_check)
        print(f"Creating {path_to_check}.\n ")
    else:
        print(f"{path_to_check} already exists. \n")


def make_help_file(template, object_name):
    copyfile(
        template,
        os.path.join(this_script, "help_file_templates",
                     f"{object_name}.maxhelp"),
    )


check_make(help_file_folder)

root = cd_up(this_script, 2)
externals = os.path.join(root, "Current Test Version", "FrameLib", "externals")

template = os.path.join(this_script, "fl.template.maxhelp")

# Create Help Files
print("Creating templated help files. \n")
for obj in remove_ds(os.listdir(externals)):
    obj = strip_extension(obj, 1)
    make_help_file(template, obj)