Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 4
0
def generate_constraints(filename):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_constraints()
    os.chdir('../.')
Ejemplo n.º 5
0
def generate_error_header(filename):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_error_header()
    all_files.write_error_table_header()
    os.chdir('../.')
Ejemplo n.º 6
0
def generate_constraints(filename):
    """
    Generate the 'constraints' files.

    :param filename: XML file to parse
    :return: nothing.
    """
    ob = common_setup(filename)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_constraints()
    os.chdir('../.')
Ejemplo n.º 7
0
def generate_validator(filename):
    """
    Generate the set of Validation files.

    :param filename: XML file to parse.
    :return: nothing
    """
    ob = common_setup(filename)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_validator_files()
    os.chdir('../.')
Ejemplo n.º 8
0
def generate_error_header(filename):
    """
    Generate error header files.

    :param filename: XML file to parse
    :return: nothing
    """
    ob = common_setup(filename)
    all_files = ValidationFiles.ValidationFiles(ob, True)
    all_files.write_error_header()
    all_files.write_error_table_header()
    os.chdir('../.')
def generate_templates(filename):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    prefix = global_variables.prefix
    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)
    ValidationFiles.ValidationFiles(ob, True)
    os.chdir('./temp')
    base_files = BaseClassFiles.BaseClassFiles(prefix,  ob['baseElements'], True)
    base_files.write_files()
    os.chdir('../.')
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def generate_templates(filename):
    """
    Several of the files for other libraries are generated using
    templates with appropriate names etc added. See
    generator/code_files/templates.
    This function tests these

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

    Validation class causes the errors for things to be enumerated and strings
    added. These will be needed by templates so with testing we have to
    create them first
    """
    ob = common_set_up(filename)
    gv.populate_error_list(ob)
    ValidationFiles.ValidationFiles(ob, True)
    go_into_new_directory()

    prefix = gv.prefix
    base_files = BaseClassFiles.BaseClassFiles(prefix, ob['baseElements'],
                                               True)
    base_files.write_files()
    os.chdir('../../.')
Ejemplo n.º 12
0
def populate_error_list(lib_object):
    from code_files import ValidationFiles
    ValidationFiles.ValidationFiles(lib_object)