コード例 #1
0
def construct_bash_launcher(linker,
                            library_path,
                            executable,
                            full_linker=True):
    linker_dirname, linker_basename = os.path.split(linker)
    full_linker = 'true' if full_linker else 'false'
    return render_template_file('launcher.sh',
                                linker_basename=linker_basename,
                                linker_dirname=linker_dirname,
                                library_path=library_path,
                                executable=executable,
                                full_linker=full_linker)
コード例 #2
0
def construct_binary_launcher(linker,
                              library_path,
                              executable,
                              full_linker=True):
    linker_dirname, linker_basename = os.path.split(linker)
    full_linker = '1' if full_linker else '0'
    code = render_template_file('launcher.c',
                                linker_basename=linker_basename,
                                linker_dirname=linker_dirname,
                                library_path=library_path,
                                executable=executable,
                                full_linker=full_linker)
    return compile(code)
コード例 #3
0
ファイル: bundling.py プロジェクト: rpromyshlennikov/exodus
def create_bundle(executables, output, tarball=False, rename=[], ldd='ldd'):
    """Handles the creation of the full bundle."""
    # Initialize these ahead of time so they're always available for error handling.
    output_filename, output_file, root_directory = None, None, None
    try:

        # Create a temporary unpackaged bundle for the executables.
        root_directory = create_unpackaged_bundle(executables,
                                                  rename=rename,
                                                  ldd=ldd)

        # Populate the filename template.
        output_filename = render_template(
            output,
            executables=('-'.join(
                os.path.basename(executable) for executable in executables)),
            extension=('tgz' if tarball else 'sh'),
        )

        # Store a gzipped tarball of the bundle in memory.
        tar_stream = io.BytesIO()
        with tarfile.open(fileobj=tar_stream, mode='w:gz') as tar:
            tar.add(root_directory, arcname='exodus')

        # Configure the appropriate output mechanism.
        if output_filename == '-':
            output_file = getattr(sys.stdout, 'buffer', sys.stdout)
        else:
            output_file = open(output_filename, 'wb')

        # Construct the installation script and write it out.
        if not tarball:
            if output_filename == '-':
                base64_encoded_tarball = base64.b64encode(
                    tar_stream.getvalue()).decode('utf-8')
                script_content = render_template_file(
                    'install-bundle-noninteractive.sh',
                    base64_encoded_tarball=base64_encoded_tarball)
                output_file.write(script_content.encode('utf-8'))
            else:
                output_file.write(
                    render_template_file('install-bundle.sh').encode('utf-8'))
                output_file.write(tar_stream.getvalue())
        else:
            # Or just write out the tarball.
            output_file.write(tar_stream.getvalue())

        # Write out the success message.
        logger.info('Successfully created "%s".' % output_filename)
        return True
    except:  # noqa: E722
        raise
    finally:
        if root_directory:
            shutil.rmtree(root_directory)
        if output_file and output_filename:
            if output_filename == '-':
                output_file.close()
            else:
                st = os.stat(output_filename)
                os.chmod(output_filename, st.st_mode | stat.S_IEXEC)
コード例 #4
0
def test_render_template_file():
    template_file = os.path.join(data_directory, 'template.txt')
    result = render_template_file(template_file, noun='word', location='here')
    with open(os.path.join(data_directory, 'template-result.txt'), 'r') as f:
        expected_result = f.read()
    assert result == expected_result
コード例 #5
0
def construct_binary_launcher(linker, binary):
    code = render_template_file('launcher.c', linker=linker, binary=binary)
    return compile(code)
コード例 #6
0
def construct_bash_launcher(linker, binary):
    return render_template_file('launcher.sh', linker=linker, binary=binary)