Skip to content

Add option for 7z archive output #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions styrene/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
16 changes: 14 additions & 2 deletions styrene/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down Expand Up @@ -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",
Expand Down