From c43db0d910dce0ddcc3dcbe8287614d00bafd5af Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Fri, 29 May 2026 16:01:35 +0000 Subject: [PATCH] unifying with updated naming convention --- administrator/tool/new-project | 110 ++++++++++++++++++ .../Greeter.lib.c | 0 .../Math.lib.c | 0 .../hello.CLI.c | 0 4 files changed, 110 insertions(+) create mode 100755 administrator/tool/new-project rename developer/authored/{ExampleGreet => example-greet}/Greeter.lib.c (100%) rename developer/authored/{ExampleGreet => example-greet}/Math.lib.c (100%) rename developer/authored/{ExampleGreet => example-greet}/hello.CLI.c (100%) diff --git a/administrator/tool/new-project b/administrator/tool/new-project new file mode 100755 index 0000000..58d49e3 --- /dev/null +++ b/administrator/tool/new-project @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*- + +import sys ,os ,subprocess +from pathlib import Path + +def get_Z_date() -> str: + try: + res = subprocess.run(["Z" ,"format-%year-%month-%day"] ,capture_output=True ,text=True ,check=True) + return res.stdout.strip() + except Exception: + return "1970-01-01" + +def work(project_name: str ,remotes: list[str]) -> int: + repo_home = os.environ.get("REPO_HOME") + if not repo_home: + print("Error: REPO_HOME is not set. A person must run this from within a sourced role environment." ,file=sys.stderr) + return 1 + + repo_path = Path(repo_home).resolve() + + dest_path = Path(project_name) + if not dest_path.is_absolute(): + dest_path = (repo_path.parent / project_name).resolve() + + if dest_path.exists(): + print(f"Error: Destination {dest_path} already exists." ,file=sys.stderr) + return 1 + + print(f"Creating new project at: {dest_path}") + dest_path.mkdir(parents=True) + + archive_cmd = "git archive HEAD | tar -x -C " + str(dest_path) + res = subprocess.run(archive_cmd ,shell=True ,cwd=str(repo_path)) + if res.returncode != 0: + print("Error extracting archive." ,file=sys.stderr) + return 1 + + opus_src = dest_path / "0pus_Harmony" + opus_dst = dest_path / f"0pus_{dest_path.name}" + if opus_src.exists(): + opus_src.rename(opus_dst) + + version_file = dest_path / "shared" / "tool" / "version" + date_str = get_Z_date() + version_line = f"echo \"{dest_path.name} v0.1 {date_str}\"\n" + + if version_file.exists(): + with open(version_file ,"a" ,encoding="utf-8") as vf: + vf.write(version_line) + else: + with open(version_file ,"w" ,encoding="utf-8") as vf: + vf.write(version_line) + + print("Initializing git repository...") + subprocess.run(["git" ,"init" ,"-b" ,"core-developer_branch"] ,cwd=str(dest_path) ,check=True) + subprocess.run(["git" ,"add" ,"."] ,cwd=str(dest_path) ,check=True) + subprocess.run(["git" ,"commit" ,"-m" ,f"Initial commit of {dest_path.name} from Harmony skeleton"] ,cwd=str(dest_path) ,check=True) + + for idx ,remote_url in enumerate(remotes): + remote_name = f"remote_{idx}" + if "github.com" in remote_url: + remote_name = "github" + elif "RT" in remote_url: + remote_name = "RT" + elif idx == 0: + remote_name = "origin" + + print(f"Adding remote '{remote_name}': {remote_url}") + subprocess.run(["git" ,"remote" ,"add" ,remote_name ,remote_url] ,cwd=str(dest_path) ,check=True) + + print(f"Project '{dest_path.name}' successfully created.") + return 0 + +def CLI(argv=None) -> int: + if argv is None: + argv = sys.argv[1:] + + if not argv or "-h" in argv or "--help" in argv: + print("Usage: new-project [-remote ]...") + return 0 + + project_name = None + remotes = [] + + idx = 0 + while idx < len(argv): + arg = argv[idx] + if arg == "-remote": + if idx + 1 < len(argv): + remotes.append(argv[idx+1]) + idx += 1 + else: + print("Error: -remote requires a URL." ,file=sys.stderr) + return 1 + elif project_name is None: + project_name = arg + else: + print(f"Error: unexpected argument '{arg}'" ,file=sys.stderr) + return 1 + idx += 1 + + if not project_name: + print("Error: project name is required." ,file=sys.stderr) + return 1 + + return work(project_name ,remotes) + +if __name__ == "__main__": + sys.exit(CLI()) diff --git a/developer/authored/ExampleGreet/Greeter.lib.c b/developer/authored/example-greet/Greeter.lib.c similarity index 100% rename from developer/authored/ExampleGreet/Greeter.lib.c rename to developer/authored/example-greet/Greeter.lib.c diff --git a/developer/authored/ExampleGreet/Math.lib.c b/developer/authored/example-greet/Math.lib.c similarity index 100% rename from developer/authored/ExampleGreet/Math.lib.c rename to developer/authored/example-greet/Math.lib.c diff --git a/developer/authored/ExampleGreet/hello.CLI.c b/developer/authored/example-greet/hello.CLI.c similarity index 100% rename from developer/authored/ExampleGreet/hello.CLI.c rename to developer/authored/example-greet/hello.CLI.c -- 2.20.1