Beispiel #1
0
def generate_code_files(name, ob):
    """
    Write Extension files (for plugins) and Validation files (for cpp).
    Called by generate_package_code()

    :param name: used in names of directories in which to create the files.
    :param ob: big dictionary structure of info from XML file
    :return: returns nothing.
    """
    this_dir = os.getcwd()
    language = gv.language
    common_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}common'.format(
        name, os.sep, language)
    extension_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}' \
                    'extension'.format(name, os.sep, language)
    valid_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}validator'.format(
        name, os.sep, language)
    constraints_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}validator{1}' \
                      'constraints'.format(name, os.sep, language)
    sbml_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}{2}'.format(
        name, os.sep, language)
    os.chdir(common_dir)
    ext = ExtensionFiles.ExtensionFiles(ob, 'types', True)
    ext.write_files()
    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    os.chdir(this_dir)

    os.chdir(extension_dir)
    ext = ExtensionFiles.ExtensionFiles(ob, '', True)
    ext.write_files()
    for i in range(0, len(ob['plugins']) + 1):
        ext.write_plugin_files(i)
    os.chdir(this_dir)

    os.chdir(valid_dir)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_files()
    os.chdir(this_dir)

    os.chdir(constraints_dir)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_constraint_files()
    os.chdir(this_dir)

    # need to do this last so that the error table is populated
    os.chdir(sbml_dir)
    for working_class in ob['baseElements']:
        all_files = CppFiles.CppFiles(working_class, True)
        all_files.write_files()
    for add_file in gv.add_implementation:
        shutil.copy(add_file, os.getcwd())
    for add_file in gv.add_declaration:
        shutil.copy(add_file, os.getcwd())

    os.chdir(this_dir)
Beispiel #2
0
def generate_code_files(name, ob):
    this_dir = os.getcwd()
    language = global_variables.language
    common_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}common'.format(
        name, os.sep, language)
    extension_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}' \
                    'extension'.format(name, os.sep, language)
    valid_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}validator'.format(
        name, os.sep, language)
    constraints_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}validator{1}' \
                      'constraints'.format(name, os.sep, language)
    sbml_dir = '{0}{1}src{1}{2}{1}packages{1}{0}{1}{2}'.format(
        name, os.sep, language)
    os.chdir(common_dir)
    ext = ExtensionFiles.ExtensionFiles(ob, 'types', True)
    ext.write_files()
    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    os.chdir(this_dir)

    os.chdir(extension_dir)
    ext = ExtensionFiles.ExtensionFiles(ob, '', True)
    ext.write_files()
    for i in range(0, len(ob['plugins']) + 1):
        ext.write_plugin_files(i)
    os.chdir(this_dir)

    os.chdir(valid_dir)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_files()
    os.chdir(this_dir)

    os.chdir(constraints_dir)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_constraint_files()
    os.chdir(this_dir)

    # need to do this last so that the error table is populated
    os.chdir(sbml_dir)
    for working_class in ob['baseElements']:
        all_files = CppFiles.CppFiles(working_class, True)
        all_files.write_files()
    for add_file in global_variables.add_implementation:
        shutil.copy(add_file, os.getcwd())
    for add_file in global_variables.add_declaration:
        shutil.copy(add_file, os.getcwd())

    os.chdir(this_dir)
Beispiel #3
0
def generate_other_library_code_files(name, ob):
    this_dir = os.getcwd()
    language = global_variables.language
    prefix = global_variables.prefix
    main_dir = '{0}{1}src{1}{2}'.format(name, os.sep, language)
    common_dir = '{0}{1}src{1}{2}{1}common'.format(name, os.sep, language)
    binding_dir = '{0}{1}src{1}bindings'.format(name, os.sep)
    os.chdir(main_dir)
    # take these lines out to write without prefix
    for working_class in ob['baseElements']:
        strFunctions.prefix_classes(working_class)
    # this populates the error structures
    valid = ValidationFiles.ValidationFiles(ob, True)
    for working_class in ob['baseElements']:
        if working_class['name'] == global_variables.document_class:
            working_class['document'] = True
        all_files = CppFiles.CppFiles(working_class, True)
        all_files.write_files()
    base_files = BaseClassFiles.BaseClassFiles(prefix, ob['baseElements'],
                                               True)
    base_files.write_files()
    os.chdir(this_dir)
    os.chdir(common_dir)
    base_files.write_common_files()
    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    os.chdir(this_dir)
Beispiel #4
0
def generate_plugin_header(filename, num):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    all_files = ExtensionFiles.ExtensionFiles(ob, '', True)
    all_files.write_plugin_files(num)
    os.chdir('../.')
Beispiel #5
0
def generate_types_header(filename):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    all_files = ExtensionFiles.ExtensionFiles(ob, 'types', True)
    all_files.write_files()
    os.chdir('../.')
Beispiel #6
0
def generate_other_library_code_files(name, ob):
    """
    Used when not generating a package.
    Called by generate_other_library_code()

    :param name: used in names of directories in which to create the files.
    :param ob: big dictionary structure of info from XML file
    :return: returns nothing.
    """
    this_dir = os.getcwd()
    language = gv.language
    prefix = gv.prefix
    main_dir = '{0}{1}src{1}{2}'.format(name, os.sep, language)
    common_dir = '{0}{1}src{1}{2}{1}common'.format(name, os.sep, language)
    # binding_dir = '{0}{1}src{1}bindings'.format(name, os.sep)
    os.chdir(main_dir)

    # take these lines out to write without prefix
    for working_class in ob['baseElements']:
        strFunctions.prefix_classes(working_class)

    # this populates the error structures
    ValidationFiles.ValidationFiles(ob, True)  # Can check retval if required.
    for working_class in ob['baseElements']:
        if working_class['name'] == gv.document_class:
            working_class['document'] = True
        all_files = CppFiles.CppFiles(working_class, True)
        all_files.write_files()
    base_files = BaseClassFiles.\
        BaseClassFiles(prefix, ob['baseElements'], True)
    base_files.write_files()
    os.chdir(this_dir)

    os.chdir(common_dir)
    base_files.write_common_files()
    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    if 'enums' in ob and len(ob['enums']) > 0:
        ext = ExtensionFiles.ExtensionFiles(ob, 'enums', True)
        ext.write_files()
    os.chdir(this_dir)
Beispiel #7
0
def generate_plugin_header(filename, num):
    """
    Generate plugin files.

    :param filename: XML file to parse.
    :param num: plugin #.
    :return: nothing.
    """
    ob = common_setup(filename)
    all_files = ExtensionFiles.ExtensionFiles(ob, '', True)
    all_files.write_plugin_files(num)
    os.chdir('../.')
Beispiel #8
0
def generate_generic_header(filename, package):
    """
    Generate Extension files with specified package.

    :param filename: XML file to parse.
    :param package: required package, e.g. 'types', 'fwd' or ''
    :return: nothing.
    """
    ob = common_setup(filename)
    all_files = ExtensionFiles.ExtensionFiles(ob, package, True)
    all_files.write_files()
    os.chdir('../.')
def generate_forward(filename):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    for wc in ob['baseElements']:
        strFunctions.prefix_classes(wc)
    for working_class in ob['baseElements']:
        if working_class['name'] == global_variables.document_class:
            working_class['document'] = True
    global_variables.populate_error_list(ob)
    os.chdir('./temp')
    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    os.chdir('../.')
Beispiel #10
0
def generate_forward(filename):
    """
    Write extension file with forward declaration of all opaque C types.

    :param filename: the XML file to parse.
    :return: nothing
    """
    ob = common_set_up(filename)
    gv.populate_error_list(ob)
    go_into_new_directory()

    ext = ExtensionFiles.ExtensionFiles(ob, 'fwd', True)
    ext.write_files()
    os.chdir('../../.')
Beispiel #11
0
def generate_enum(filename):
    """
    According to ExtensionFile.py, this writes the extension types file.

    :param filename: the XML file to parse.
    :return: nothing

    For SBML, the extension file includes all the enums that are associated
    with a package. When generating code for a different library we still
    need a file that lists any enums so we create a version of the same file.

    Need to review this issue #44
    """
    ob = common_set_up(filename)
    gv.populate_error_list(ob)
    go_into_new_directory()

    ext = ExtensionFiles.ExtensionFiles(ob, 'enums', True)
    ext.write_files()
    os.chdir('../../.')