def package(ctx, single_file, stage, merge_template, out, pkg_format, template_format, profile): # type: (click.Context, bool, str, str, str, str, str, str) -> None factory = ctx.obj['factory'] # type: CLIFactory factory.profile = profile config = factory.create_config_obj(stage) options = factory.create_package_options() packager = factory.create_app_packager(config, options, pkg_format, template_format, merge_template) if pkg_format == 'terraform' and (merge_template or single_file or template_format != 'json'): # I don't see any reason we couldn't support --single-file for # terraform if we wanted to. click.echo(("Terraform format does not support " "--merge-template, --single-file, or --template-format")) raise click.Abort() if single_file: dirname = tempfile.mkdtemp() try: packager.package_app(config, dirname, stage) create_zip_file(source_dir=dirname, outfile=out) finally: shutil.rmtree(dirname) else: packager.package_app(config, out, stage)
def test_can_zip_single_file(tmpdir): source = tmpdir.mkdir('sourcedir') source.join('hello.txt').write(b'hello world') outfile = str(tmpdir.join('out.zip')) utils.create_zip_file(source_dir=str(source), outfile=outfile) with zipfile.ZipFile(outfile) as f: contents = f.read('hello.txt') assert contents == b'hello world' assert f.namelist() == ['hello.txt']
def package(ctx, single_file, stage, out): # type: (click.Context, bool, str, str) -> None factory = ctx.obj['factory'] # type: CLIFactory config = factory.create_config_obj(stage) packager = factory.create_app_packager(config) if single_file: dirname = tempfile.mkdtemp() try: packager.package_app(config, dirname) create_zip_file(source_dir=dirname, outfile=out) finally: shutil.rmtree(dirname) else: packager.package_app(config, out)
def package(ctx, single_file, stage, out): # type: (click.Context, bool, str, str) -> None factory = ctx.obj['factory'] # type: CLIFactory config = factory.create_config_obj(stage) packager = factory.create_app_packager(config) if single_file: dirname = tempfile.mkdtemp() try: packager.package_app(config, dirname, stage) create_zip_file(source_dir=dirname, outfile=out) finally: shutil.rmtree(dirname) else: packager.package_app(config, out, stage)
def test_can_zip_recursive_contents(tmpdir): source = tmpdir.mkdir('sourcedir') source.join('hello.txt').write(b'hello world') subdir = source.mkdir('subdir') subdir.join('sub.txt').write(b'sub.txt') subdir.join('sub2.txt').write(b'sub2.txt') subsubdir = subdir.mkdir('subsubdir') subsubdir.join('leaf.txt').write(b'leaf.txt') outfile = str(tmpdir.join('out.zip')) utils.create_zip_file(source_dir=str(source), outfile=outfile) with zipfile.ZipFile(outfile) as f: assert f.namelist() == [ 'hello.txt', 'subdir/sub.txt', 'subdir/sub2.txt', 'subdir/subsubdir/leaf.txt', ] assert f.read('subdir/subsubdir/leaf.txt') == b'leaf.txt'
def package(ctx, single_file, stage, merge_template, out, pkg_format): # type: (click.Context, bool, str, str, str, str) -> None factory = ctx.obj['factory'] # type: CLIFactory config = factory.create_config_obj(stage) packager = factory.create_app_packager(config, pkg_format, merge_template) if pkg_format == 'terraform' and (merge_template or single_file): click.echo(("Terraform format does not support " "merge-template or single-file options")) raise click.Abort() if single_file: dirname = tempfile.mkdtemp() try: packager.package_app(config, dirname, stage) create_zip_file(source_dir=dirname, outfile=out) finally: shutil.rmtree(dirname) else: packager.package_app(config, out, stage)