

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 += '.'

    def use_template_file(path):
        '\n        :param path: relative path from template_dir\n        '
        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_template = "<!-- dx-header -->\n# {app_title} (DNAnexus Platform App)\n\n{summary}\n\nThis is the source code for an app that runs on the DNAnexus Platform.\nFor more information about how to run or modify it, see\nhttps://wiki.dnanexus.com/.\n<!-- /dx-header -->\n\n{description}\n\n<!--\nTODO: This app directory was automatically generated by dx-app-wizard;\nplease edit this Readme.md file to include essential documentation about\nyour app that would be helpful to users. (Also see the\nReadme.developer.md.) Once you're done, you can remove these TODO\ncomments.\n\nFor more info, see https://wiki.dnanexus.com/Developer-Portal.\n-->\n"
    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_template = '# {app_name} Developer Readme\n\n<!--\nTODO: Please edit this Readme.developer.md file to include information\nfor developers or advanced users, for example:\n\n* Information about app internals and implementation details\n* How to report bugs or contribute to development\n-->\n\n## Running this app with additional computational resources\n\nThis app has the following entry points:\n\n{entry_points_list}\n\n{instance_type_override_message}\n\n    {{\n      systemRequirements: {{\n        {entry_points_hash}\n      }},\n      [...]\n    }}\n\nSee <a\nhref="https://wiki.dnanexus.com/API-Specification-v1.0.0/IO-and-Run-Specifications#Run-Specification">Run\nSpecification</a> in the API documentation for more information about the\navailable instance types.\n'
    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\nentry point by providing the ``systemRequirements`` field to\n```/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\nproviding the ``systemRequirements`` field to ```/applet-XXXX/run``` or\n```/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