Skip to content
Snippets Groups Projects
Commit 36019d1e authored by Felix Gerking's avatar Felix Gerking
Browse files

package_release: Improve md5sums.txt file creation

Now md5sums.txt can be assembled from different copy processes.
parent 7ee49064
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,30 @@ def md5(fname):
return hash_md5.hexdigest()
def write_md5sums_file(md5sums, subdir, output_dir, outlocal_dir):
with tempfile.TemporaryDirectory() as tmp:
source_file = os.path.join(tmp, subdir, "md5sums.txt")
os.makedirs(os.path.dirname(source_file), exist_ok=True)
with open(source_file, "w", encoding="utf-8") as f_md5:
for f, h in md5sums.items():
f_md5.write("{} {}\n".format(h, f))
if output_dir is not None:
target_file = os.path.join(
output_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
if outlocal_dir is not None:
target_file = os.path.join(
outlocal_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
def copy_files(files, input_dir, subdir, output_dir, outlocal_dir):
md5sums = {}
if output_dir is not None:
......@@ -49,28 +73,6 @@ def copy_files(files, input_dir, subdir, output_dir, outlocal_dir):
else:
print("Missing: " + source_file)
# Write md5sums file:
with tempfile.TemporaryDirectory() as tmp:
source_file = os.path.join(tmp, subdir, "md5sums.txt")
os.makedirs(os.path.dirname(source_file), exist_ok=True)
with open(source_file, "w", encoding="utf-8") as f_md5:
for f, h in md5sums.items():
f_md5.write("{} {}\n".format(h, f))
if output_dir is not None:
target_file = os.path.join(
output_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
if outlocal_dir is not None:
target_file = os.path.join(
outlocal_dir, subdir, os.path.basename(source_file)
)
print("Copy: %s -> %s" % (source_file, target_file))
shutil.copyfile(source_file, target_file, follow_symlinks=True)
return md5sums
......@@ -257,26 +259,34 @@ def main():
artifacts_all.append(artifact.split(".")[0] + ".manifest")
artifacts_all.append(artifact.split(".")[0] + ".testdata.json")
md5sums = copy_files(
artifacts_all, args.images_dir, machine, output_dir, outlocal_dir
)
# If the path for the licenses is set, we check for the list with all
# licenses. If the list is found, we copy it to the output directory
# and also add it to the artifacts dictionary.
license_manifest = None
if args.licenses_dir is not None and os.path.isdir(args.licenses_dir):
manifest = glob.glob(
license_manifest = glob.glob(
os.path.join(args.licenses_dir, "**", "license.manifest")
)
if manifest:
copy_files(
["license.manifest"],
os.path.dirname(manifest[0]),
machine,
output_dir,
outlocal_dir,
if license_manifest:
md5sums.update(
copy_files(
["license.manifest"],
os.path.dirname(license_manifest[0]),
machine,
output_dir,
outlocal_dir,
)
)
artifacts_all.append("license.manifest")
md5sums = copy_files(
artifacts_all, args.images_dir, machine, output_dir, outlocal_dir
# Everything copied? Create md5sums file
write_md5sums_file(
md5sums, machine, output_dir, outlocal_dir
)
# Generate metadata
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment