Skip to content

Commit

Permalink
Rename new argument vendorfilename to vendorname
Browse files Browse the repository at this point in the history
This matches the scheme of basename.

Also this fixes a duplication of suffix and fixes the compression
of zst vendor tarballs.
  • Loading branch information
dirkmueller committed Apr 3, 2023
1 parent af5348b commit 8c0242c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
75 changes: 38 additions & 37 deletions go_modules
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,42 @@ app_name = "obs-service-go_modules"
description = __doc__

DEFAULT_COMPRESSION = "gz"
DEFAULT_VENDOR_FILENAME = "vendor.tar"
DEFAULT_VENDOR_STEM = "vendor"


def get_archive_parameters(args):
archive_format = None
archive_compression = None
archive_extension = None

archive = {}
archive["vendorname"] = args.vendorname
archive["compression"] = None
archive["level"] = None
if args.compression == "obscpio" and "cpio" in libarchive.ffi.READ_FORMATS:
archive_format = "cpio_newc"
archive_compression = None
archive_extension = args.compression

elif args.compression == "tar" and "tar" in libarchive.ffi.READ_FORMATS:
archive_format = "gnutar"
archive_compression = None
archive_extension = args.compression

archive["format"] = "cpio_newc"
archive["ext"] = "obscpio"
return archive

archive["format"] = "gnutar"
if args.compression == "tar" and "tar" in libarchive.ffi.READ_FORMATS:
archive["ext"] = "tar"
return archive

archive["level"] = 9
if args.compression == "gz":
archive["compression"] = "gzip"
elif args.compression == "zst":
archive["compression"] = "zstd"
archive["level"] = 19
else:
compression_format = args.compression

if args.compression == "gz":
compression_format = "gzip"

elif args.compression == "zst":
compression_format = "zstd"

if compression_format not in libarchive.ffi.READ_FILTERS:
log.error(
f"The specified compression mode is not supported: {args.compression}"
)
exit(1)
archive["compression"] = args.compression

archive_format = "gnutar"
archive_compression = compression_format
archive_extension = "tar." + (args.compression)
vendor_filename = args.vendorfilename
if archive["compression"] not in libarchive.ffi.READ_FILTERS:
log.error(
f"The specified compression mode is not supported: {args.compression}"
)
exit(1)

return archive_format, archive_compression, archive_extension, vendor_filename
archive["ext"] = "tar." + (args.compression)
return archive


def basename_from_archive_name(archive_name):
Expand Down Expand Up @@ -222,17 +219,15 @@ def main():
parser.add_argument("--outdir")
parser.add_argument("--compression", default=DEFAULT_COMPRESSION)
parser.add_argument("--basename")
parser.add_argument("--vendorfilename", default=DEFAULT_VENDOR_FILENAME)
parser.add_argument("--vendorname", default=DEFAULT_VENDOR_STEM)
parser.add_argument("--subdir")
args = parser.parse_args()

outdir = args.outdir
subdir = args.subdir

archive_format, archive_compression, archive_ext, vendor_filename = get_archive_parameters(
args
)
vendor_tarname = f"{vendor_filename}.{archive_ext}"
archive_args = get_archive_parameters(args)
vendor_tarname = f"{archive_args['vendorname']}.{archive_args['ext']}"
archive = args.archive or archive_autodetect()
log.info(f"Using archive {archive}")

Expand Down Expand Up @@ -298,8 +293,14 @@ def main():
os.chdir(go_mod_dir)
vendor_dir = "vendor"

kwargs = {}
if archive_args["level"]:
kwargs["options"] = f"compression-level={archive_args['level']}"
with libarchive.file_writer(
vendor_tarfile, archive_format, archive_compression
vendor_tarfile,
archive_args["format"],
archive_args["compression"],
**kwargs,
) as new_archive:
new_archive.add_files(vendor_dir)
os.chdir(cwd)
Expand Down
4 changes: 2 additions & 2 deletions go_modules.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parameter name="subdir">
<description>If go.mod is not available in the top directory of the archive, specify its path (relative to the top directory). Default: None.</description>
</parameter>
<parameter name="vendorfilename">
<description>Specify the filename for the generated vendor tarball. Default: vendor.tar</description>
<parameter name="vendorname">
<description>Specify the name for the generated vendor tarball. Default: vendor</description>
</parameter>
</service>

0 comments on commit 8c0242c

Please sign in to comment.