diff --git a/styrene/bundle.py b/styrene/bundle.py index 7f5155e..50327c9 100644 --- a/styrene/bundle.py +++ b/styrene/bundle.py @@ -203,6 +203,8 @@ def write_distributables(self, output_dir, options): distfiles.extend(self._write_nsis_distfile(distroot, output_dir)) if options.build_zip: distfiles.extend(self._write_zip_distfile(distroot, output_dir)) + if options.build_7z: + distfiles.extend(self._write_7z_distfile(distroot, output_dir)) return distfiles @property @@ -713,30 +715,66 @@ def _delete_surplus_files(self, root, options): for a, p in removed: print("{action} {path}".format(action=a, path=p), file=fp) - def _write_zip_distfile(self, root, output_dir): - """Package a frozen bundle as a standalone zipfile. + def _write_generic_distfile(self, root, output_dir, ext, cmd_function): + """Generic helper for packaing frozen bundles into archives :param str root: Frozen bundle location. - :param str output_dir: Where to write the output zipfile. + :param str output_dir: Where to write the output file. + :param str ext: File extension of the output file + :param function cmd_function: Function creating the compression command """ - output_file_basename = "{stub_name}-{version}-standalone.zip".format( + output_file_basename = "{stub_name}-{version}-standalone.{ext}".format( stub_name=self.stub_name, version=self.version, + ext=ext, ) logger.info("Writing ā€œ%sā€ā€¦", output_file_basename) output_file_path = os.path.join(output_dir, output_file_basename) - cmd = [ - "zip", "-Xq9r", + cmd = cmd_function( os.path.abspath(output_file_path), os.path.curdir, - ] + ) subprocess.check_call( cmd, cwd=root, ) return [output_file_path] + def _write_zip_distfile(self, root, output_dir): + """Package a frozen bundle as a standalone zipfile. + + :param str root: Frozen bundle location. + :param str output_dir: Where to write the output zipfile. + + """ + def cmd_array(output_file_path, root_relative_input_path): + return [ + "zip", "-Xq9r", + output_file_path, + root_relative_input_path, + ] + return self._write_generic_distfile( + root, output_dir, "zip", cmd_array + ) + + def _write_7z_distfile(self, root, output_dir): + """Package a frozen bundle as a standalone 7z archive. + + :param str root: Frozen bundle location. + :param str output_dir: Where to write the output 7z file. + + """ + def cmd_array(output_file_path, root_relative_input_path): + return [ + "7z", "a", "-bd", "-mx=9", + output_file_path, + root_relative_input_path, + ] + return self._write_generic_distfile( + root, output_dir, "7z", cmd_array + ) + def _write_nsis_distfile(self, root, output_dir): """Package a frozen bundle as an NSIS installer executable. diff --git a/styrene/cmdline.py b/styrene/cmdline.py index 92eecd4..da4ec58 100644 --- a/styrene/cmdline.py +++ b/styrene/cmdline.py @@ -108,9 +108,14 @@ def process_spec_file(spec, options): bundle.check_runtime_dependencies() output_dir = options.output_dir if not output_dir: - if not (options.build_zip or options.build_exe): + output_generating_options = [ + options.build_zip, + options.build_exe, + options.build_7z, + ] + if not any(output_generating_options): logger.warning( - "Both --no-zip and --no-exe were specified, with no " + "No output is enabled and there is no specified " "--output-dir to write and keep the remaining " "intermediate files in." ) @@ -205,6 +210,13 @@ def main(): dest="build_zip", default=True, ) + parser.add_option( + "--7z", + help="create a standalone .7z archive", + action="store_true", + dest="build_7z", + default=False, + ) parser.add_option( "--colour", "--color", help="colourize output: yes/no/auto",