コード例 #1
0
ファイル: generateCode.py プロジェクト: niko-rodrigue/deviser
def generate_bindings_files_for_other(name, ob):
    this_dir = os.getcwd()
    csharp_dir = '{0}{1}src{1}bindings{1}csharp'.format(name, os.sep)
    java_dir = '{0}{1}src{1}bindings{1}java'.format(name, os.sep)
    javascript_dir = '{0}{1}src{1}bindings{1}javascript'.format(name, os.sep)
    perl_dir = '{0}{1}src{1}bindings{1}perl'.format(name, os.sep)
    php_dir = '{0}{1}src{1}bindings{1}php'.format(name, os.sep)
    python_dir = '{0}{1}src{1}bindings{1}python'.format(name, os.sep)
    r_dir = '{0}{1}src{1}bindings{1}r'.format(name, os.sep)
    ruby_dir = '{0}{1}src{1}bindings{1}ruby'.format(name, os.sep)
    swig_dir = '{0}{1}src{1}bindings{1}swig'.format(name, os.sep)

    # os.chdir(java_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'java', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(javascript_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'javascript', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(perl_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'perl', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(php_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'php', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(python_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'python', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(r_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'r', True)
    # bind.write_files()
    # os.chdir(this_dir)
    #
    # os.chdir(ruby_dir)
    # bind = BindingsFiles.BindingFiles(ob, 'ruby', True)
    # bind.write_files()
    # os.chdir(this_dir)

    os.chdir(swig_dir)
    bind = BindingsFiles.BindingFiles(ob, 'swig', True)
    bind.write_swig_library_files()
    os.chdir(this_dir)

    os.chdir(csharp_dir)
    bind = BindingsFiles.BindingFiles(ob, 'csharp', True)
    bind.write_files()
    os.chdir(this_dir)
コード例 #2
0
def generate_bindings_files_for_other(name, ob):
    """
    Called when we're not generating code for a package.

    :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()
    languages = [
        'csharp',
        'java',
        'python',
    ]
    # 'javascript', 'perl', 'php', 'r', 'ruby', 'swig']

    for lang in languages:
        generate_bindings_files_in_dir(name, this_dir, lang, ob)

    swig_dir = '{0}{1}src{1}bindings{1}swig'.format(name, os.sep)
    os.chdir(swig_dir)
    bind = BindingsFiles.BindingFiles(ob, 'swig', True)
    # This line doesn't appear in generate_bindings_files():
    bind.write_swig_library_files()
    os.chdir(this_dir)
コード例 #3
0
def generate_bindings_files_in_dir(name, start_dir, language, ob):
    """
    cd into a directory, write out files, then cd back to initial directory.

    :param name: `name` attribute node value, e.g. "dyn" for samples/dyn.xml
    :param start_dir: dictionary we started from.
    :param language: a string like "csharp" or "java".
    :param ob: the large dictionary structure of node information.
    :return: returns nothing.

    This function is to replace blocks of code like this:

    csharp_dir = '{0}{1}src{1}bindings{1}csharp'.format(name, os.sep)
    os.chdir(csharp_dir)
    bind = BindingsFiles.BindingFiles(ob, 'csharp', True)
    bind.write_files()
    os.chdir(this_dir)

    We could add an option for swig. But we would then have to check it worked
    for the swig call in both generate_bindings_files() and
    generate_bindings_files_for_other(); the latter has a call to
    write_swig_library_files(), but the latter has the usual write_files()
    call.
    """
    lang_dir = '{0}{1}src{1}bindings{1}{2}'.format(name, os.sep, language)
    os.chdir(lang_dir)
    bind = BindingsFiles.BindingFiles(ob, language, True)
    bind.write_files()
    os.chdir(start_dir)
コード例 #4
0
def generate_bindings_downcast_plugins(filename, binding):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    if os.path.isdir(binding):
        os.chdir(binding)
    else:
        os.makedirs(binding)
        os.chdir(binding)
    all_files = BindingsFiles.BindingFiles(ob, binding, True)
    all_files.write_downcast_plugins()
    os.chdir('../.')
    os.chdir('../.')
コード例 #5
0
def generate_binding(filename, binding):
    """
    Generate the "binding" files.

    :param filename: the XML file to parse.
    :param binding: binding to use, e.g. 'swig', 'cmake', 'csharp'.
    :return: nothing
    """
    ob = common_set_up(filename)
    go_into_new_directory()

    if not os.path.isdir(binding):
        os.mkdir(binding)
    os.chdir(binding)
    all_files = BindingsFiles.BindingFiles(ob, binding, True)
    all_files.write_files()
    os.chdir('../.')
    os.chdir('../../.')
コード例 #6
0
def generate_binding(filename, binding):
    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
    os.chdir('./temp')
    if os.path.isdir(binding):
        os.chdir(binding)
    else:
        os.makedirs(binding)
        os.chdir(binding)
    all_files = BindingsFiles.BindingFiles(ob, binding, True)
    all_files.write_files()
    os.chdir('../.')
    os.chdir('../.')
コード例 #7
0
def generate_bindings_downcast_pkgs(filename, binding, local):
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir('./temp')
    if os.path.isdir(binding):
        os.chdir(binding)
    else:
        os.makedirs(binding)
        os.chdir(binding)
    all_files = BindingsFiles.BindingFiles(ob, binding, True)
    if binding == 'swig':
        all_files.write_swig_files()
    elif local:
        all_files.write_local()
    else:
        all_files.write_downcast_packages()
    os.chdir('../.')
    os.chdir('../.')
コード例 #8
0
def set_up(filename, binding):
    """
    Generic set-up code used by all the specific generation functions.
    Parse XML file and use the big dictionary structure obtained to
    generate a bindings file of the required binding.

    :param filename: the XML file to parse
    :param binding: the required binding, e.g. 'csharp', 'java', etc.
    :return: the new file object
    """
    parser = ParseXML.ParseXML(filename)
    ob = parser.parse_deviser_xml()
    os.chdir(os.path.normpath('./temp'))
    if os.path.isdir(binding):
        os.chdir(binding)
    else:
        os.makedirs(binding)
        os.chdir(binding)
    all_files = BindingsFiles.BindingFiles(ob, binding, True)
    return all_files