Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • seco-ne/yocto/infrastructure/gitlab-ci
1 result
Show changes
Commits on Source (2)
......@@ -26,7 +26,20 @@ def generate_md5sums_file(input_files: list[str], output_file: str):
# This might should be used somewhere before,
# but the previous state was not to fail when a file in
# the list did not exist, like in copy files
md5sums = {os.path.basename(f): md5(f) for f in input_files if os.path.exists(f)}
md5sums = {}
for item in input_files:
# Check if the item ends with "/"
if item.endswith("/"):
# If it does, recursively calculate MD5 sums for all files in the directory
for root, _, files in os.walk(item):
for file in files:
file_path = os.path.join(root, file)
md5sums[os.path.relpath(file_path, item)] = md5(file_path)
else:
# Otherwise, calculate MD5 sum for the file
if os.path.exists(item):
md5sums[os.path.basename(item)] = md5(item)
output_dir = os.path.dirname(output_file)
if output_dir:
os.makedirs(output_dir, exist_ok=True)
......@@ -37,19 +50,29 @@ def generate_md5sums_file(input_files: list[str], output_file: str):
def copy_files(files: list[str], target_dir: str):
"""
Copy given files to target_dir. Create target_dir, if it does not exist. Subfolder
hierarchies on the input files will not be preserved, only plain files are copied.
Copy given files or directories to target_dir. Create target_dir, if it does not exist. Subfolder
hierarchies on the input directories will be preserved. Only plain files are copied.
"""
if target_dir is None:
return
os.makedirs(target_dir, exist_ok=True)
for source_file in files:
if os.path.exists(source_file):
target_file = os.path.join(target_dir, os.path.basename(source_file))
print(f"Copy: {source_file} -> {target_file}")
shutil.copyfile(source_file, target_file, follow_symlinks=True)
for source in files:
# Check if the source ends with "/"
if source.endswith("/"):
# If it does, copy the whole directory recursively
old_dir = os.path.abspath(source)
new_dir = os.path.join(target_dir, os.path.basename(source.rstrip("/")))
print(f"Copy Directory: {old_dir} -> {new_dir}")
shutil.copytree(old_dir, new_dir)
else:
print(f"Missing: {source_file}")
# Otherwise, treat it as a file and copy it directly
source_file = os.path.abspath(source)
if os.path.exists(source_file):
target_file = os.path.join(target_dir, os.path.basename(source_file))
print(f"Copy: {source_file} -> {target_file}")
shutil.copyfile(source_file, target_file, follow_symlinks=True)
else:
print(f"Missing: {source_file}")
def main():
......