From 193eac89f64cbe58b04d9cc53a81910c7a3a893d Mon Sep 17 00:00:00 2001 From: "hao.hu" Date: Thu, 29 Feb 2024 14:25:34 +0000 Subject: [PATCH 1/2] Add script to convert mirroring-config repo to be lorry2 compatible --- scripts/convert_to_lorry2.py | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 scripts/convert_to_lorry2.py diff --git a/scripts/convert_to_lorry2.py b/scripts/convert_to_lorry2.py new file mode 100755 index 00000000..6a1460b3 --- /dev/null +++ b/scripts/convert_to_lorry2.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 + +from pathlib import Path +import argparse + + +def convert_file(file_path): + """ + convert a single lorry file to lorry2 format + """ + content = "" + + with open(file_path, "r", encoding="utf-8") as r: + new_repo_flag = False + repo_content = "" + merge_url_flag = False + tarball_flag = False + + for line in r.readlines(): + stripped_line = line.strip() + # new repo + if not line.startswith(" ") and stripped_line.endswith(":"): + if repo_content: + content += repo_content + repo_content = "" + new_repo_flag = True + + if new_repo_flag: + # merge line only contains "url:" with next line + # ie: convert + # + # url: + # https://lorry1.url + # + # to "url: https://lorry1.url" + if stripped_line == "url:": + repo_content += line.rstrip() + merge_url_flag = True + # convert "tarball" to "raw-file" as lorry2 doesn't support + # ie: convert + # + # type: tarball + # url: https://lorry1.tar.gz + # + # to: + # + # type: raw-file + # urls: + # - destination: tarballs + # url: https://lorr1.tar.gz + elif stripped_line.startswith("type: tarball"): + repo_content += line.replace("tarball", "raw-file") + repo_content += line.replace("type: tarball", "urls:") + repo_content += line.replace("type: tarball", + " - destination: tarballs") + tarball_flag = True + # drop "type: hg" repo as lorry2 doesn't support + elif stripped_line.startswith("type: hg"): + repo_content = "" + new_repo_flag = False + else: + if merge_url_flag: + repo_content += f" {stripped_line}\n" + merge_url_flag = False + elif tarball_flag: + repo_content += f" {line}" + tarball_flag = False + else: + repo_content += line + + if repo_content: + content += repo_content + + return content + + +def convert_to_lorry2(lorry_config_repo): + """ + convert lorry_config_repo to be compatible with lorry2 + """ + + dirs_to_ignore = [".git"] + dir_path = Path(lorry_config_repo).absolute() + subdirs = sorted([d for d in dir_path.iterdir() + if d.is_dir() and d.name not in dirs_to_ignore]) + + for subdir in subdirs: + lorry_files = [ + f for f in subdir.iterdir() if f.is_file() and f.suffix == ".lorry" + ] + + for lorry_file in lorry_files: + content = convert_file(lorry_file) + with open(lorry_file, "w", encoding="utf-8") as w: + w.write(content) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + usage="""convert_to_lorry2.py lorry_config_repo + + lorry_config_repo: path to lorry config repo that need to be converted + """, + description="convert lorry config repo to lorry2 format") + parser.add_argument('lorry_config_repo') + args = parser.parse_args() + convert_to_lorry2(args.lorry_config_repo) -- GitLab From 114a153d08c03f3d10bf3fa73e147adc7008cfe9 Mon Sep 17 00:00:00 2001 From: "hao.hu" Date: Thu, 29 Feb 2024 14:25:58 +0000 Subject: [PATCH 2/2] Update README.md with converting lorry mirroring-config --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 1c0f5886..7da544fa 100644 --- a/README.md +++ b/README.md @@ -570,3 +570,15 @@ can now deploy Lorry 2! [git push documentation]: https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt [gitlab-push-options]: https://docs.gitlab.com/ee/user/project/push_options.html + +## Lorry Mirror Config + +The lorry mirroring-config repo itself also need to be converted into lorry2 +compatible, ie. to remove unsupported `type: hg` or convert `type: tarball` to +`type: raw-file`. To achieve this goal, calling: + +`./scripts/convert_to_lorry2.py mirror_config_repo` + +Where `mirror_config_repo` should be the root directory of the mirroring-config +repo. You may need manually readd the ignored `type: hg` repos with possible +replacement git repos if they are really in need. -- GitLab