def create_files_from_templates(template_dir, app_json, language,
                                required_file_input_names, optional_file_input_names,
                                required_file_array_input_names, optional_file_array_input_names,
                                file_output_names,
                                pattern, pattern_suffix='',
                                parallelized_input='', parallelized_output='', description='',
                                entry_points=()):
    manifest = []
    name = app_json['name']
    title = app_json.get('title', name)
    summary = app_json.get('summary', '')

    version = app_json['version']
    pattern_suffix += '.'

    # List all files in template_dir (other than dxapp.json) and add
    # those (after passing it through fill_in_name_and_ver).  For the
    # code.* in src,

    def use_template_file(path):
        '''
        :param path: relative path from template_dir
        '''
        with open(os.path.join(template_dir, path), 'r') as template_file:
            file_text = fill_in_name_and_ver(template_file.read(), name, version)
            filled_template_filename = os.path.join(name, path)
            with open(filled_template_filename, 'w') as filled_template_file:
                filled_template_file.write(file_text)
            if filled_template_filename.endswith('.py') or filled_template_filename.endswith('.sh'):
                subprocess.call(["chmod", "+x", filled_template_filename])
            manifest.append(filled_template_filename)

    for template_filename in os.listdir(template_dir):
        if template_filename in ['src', 'test', 'dxapp.json'] or template_filename.endswith('~'):
            continue
        use_template_file(template_filename)

    if os.path.exists(os.path.join(template_dir, 'test')):
        for template_filename in os.listdir(os.path.join(template_dir, 'test')):
            if any(template_filename.endswith(ext) for ext in ('~', '.pyc', '.pyo')):
                continue
            use_template_file(os.path.join('test', template_filename))

    for template_filename in os.listdir(os.path.join(template_dir, 'src')):
        if template_filename.endswith('~'):
            continue
        elif template_filename.startswith('code'):
            if template_filename.startswith('code' + pattern_suffix):
                with open(os.path.join(template_dir, 'src', template_filename), 'r') as code_template_file:
                    code_file_text = fill_in_name_and_ver(code_template_file.read(), name, version)

                    if "outputSpec" in app_json:
                        dummy_output_hash = {output["name"]: None for output in app_json["outputSpec"]}
                    else:
                        dummy_output_hash = {}

                    input_sig_str, init_inputs_str, dl_files_str, ul_files_str, outputs_str = \
                        language_options[language].get_strings(app_json,
                                                               required_file_input_names,
                                                               optional_file_input_names,
                                                               required_file_array_input_names,
                                                               optional_file_array_input_names,
                                                               file_output_names,
                                                               dummy_output_hash)

                    code_file_text = code_file_text.replace('DX_APP_WIZARD_INPUT_SIGNATURE', input_sig_str)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_INITIALIZE_INPUT', init_inputs_str)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_DOWNLOAD_ANY_FILES', dl_files_str)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_UPLOAD_ANY_FILES', ul_files_str)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_OUTPUT', outputs_str)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_PARALLELIZED_INPUT', parallelized_input)
                    code_file_text = code_file_text.replace('DX_APP_WIZARD_PARALLELIZED_OUTPUT', parallelized_output)

                    filled_code_filename = os.path.join(name, 'src', template_filename.replace('code' + pattern_suffix, name + '.'))
                    with open(filled_code_filename, 'w') as filled_code_file:
                        filled_code_file.write(code_file_text)
                    if filled_code_filename.endswith('.sh') or filled_code_filename.endswith('.py'):
                        subprocess.call(["chmod", "+x", os.path.join(filled_code_filename)])
                    manifest.append(filled_code_filename)
        else:
            use_template_file(os.path.join('src', template_filename))

    # Readme file

    readme_template = '''<!-- dx-header -->
# {app_title} (DNAnexus Platform App)

{summary}

This is the source code for an app that runs on the DNAnexus Platform.
For more information about how to run or modify it, see
https://wiki.dnanexus.com/.
<!-- /dx-header -->

{description}

<!--
TODO: This app directory was automatically generated by dx-app-wizard;
please edit this Readme.md file to include essential documentation about
your app that would be helpful to users. (Also see the
Readme.developer.md.) Once you're done, you can remove these TODO
comments.

For more info, see https://wiki.dnanexus.com/Developer-Portal.
-->
'''
    with open(os.path.join(name, 'Readme.md'), 'w') as readme_file:
        readme_file.write(readme_template.format(app_title=title, summary=summary, description=description))
    manifest.append(os.path.join(name, 'Readme.md'))

    # Developer readme

    developer_readme_template = '''# {app_name} Developer Readme

<!--
TODO: Please edit this Readme.developer.md file to include information
for developers or advanced users, for example:

* Information about app internals and implementation details
* How to report bugs or contribute to development
-->

## Running this app with additional computational resources

This app has the following entry points:

{entry_points_list}

{instance_type_override_message}

    {{
      systemRequirements: {{
        {entry_points_hash}
      }},
      [...]
    }}

See <a
href="https://wiki.dnanexus.com/API-Specification-v1.0.0/IO-and-Run-Specifications#Run-Specification">Run
Specification</a> in the API documentation for more information about the
available instance types.
'''

    entry_points_list = '\n'.join(['* {0}'.format(entry_point) for entry_point in entry_points])

    if len(entry_points) > 1:
        instance_type_override_message = '''When running this app, you can override the instance type to be used for each
entry point by providing the ``systemRequirements`` field to
```/applet-XXXX/run``` or ```/app-XXXX/run```, as follows:'''
    else:
        instance_type_override_message = '''When running this app, you can override the instance type to be used by
providing the ``systemRequirements`` field to ```/applet-XXXX/run``` or
```/app-XXXX/run```, as follows:'''

    entry_points_hash = ",\n        ".join(['"{entry_point}": {{"instanceType": "mem2_hdd2_x2"}}'.format(entry_point=entry_point) for entry_point in entry_points])

    with open(os.path.join(name, 'Readme.developer.md'), 'w') as developer_readme_file:
        developer_readme_file.write(developer_readme_template.format(
                app_name=name,
                entry_points_list=entry_points_list,
                entry_points_hash=entry_points_hash,
                instance_type_override_message=instance_type_override_message
                ))
    manifest.append(os.path.join(name, 'Readme.developer.md'))

    return manifest
dataset/ETHPy150Open dnanexus/dx-toolkit/src/python/dxpy/templating/utils.py/create_files_from_templates/original