From c16fd1d5d847ef139c5a756700438ecb066c4073 Mon Sep 17 00:00:00 2001 From: Masterchef365 Date: Sat, 6 May 2023 03:00:11 -0700 Subject: [PATCH 1/2] 'cimvr new' subcommand, written mostly by chatgpt --- cimvr.py | 54 +++++++++++++++++++++++++++++++++++++++++++ obj_loader/src/obj.rs | 1 - 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cimvr.py b/cimvr.py index cd1f5931..f8961485 100755 --- a/cimvr.py +++ b/cimvr.py @@ -4,6 +4,10 @@ import argparse from subprocess import Popen from time import sleep +import shutil +import subprocess +import sys + # TODO: Enable this script to `cargo run` the server and client. @@ -35,8 +39,16 @@ def main(): ) parser.add_argument("--verbose", "-v", help="Verbose debug output") parser.add_argument("--vr", action="store_true", help="Run the client in VR mode") + args = parser.parse_args() + # cimvr new "subcommand" - workaround for argparse + if len(args.plugins) == 2 and args.plugins[0] == "new": + # This means you cannot have a plugin named "new" + # but if you do f*** you anyway + create_new(args.plugins[1]) + return; + # The script is assumed to be at the root of the project root_path = dirname(__file__) @@ -182,5 +194,47 @@ def find_exe(env_var, names, root_path): return None +def create_new(dir_name): + # Courtesy of ChatGPT 5/6/2023 + REPO_URL = "https://github.com/ChatImproVR/template.git" + CARGO_TOML_FILE = "Cargo.toml" + CARGO_TOML_NAME_FIELD = "name = \"template_plugin\"" + + # TODO: Is this barbaric? + BASHRC_FILE = os.path.expanduser("~/.bashrc") + BASHRC_EXPORT_LINE = "export CIMVR_PLUGINS=\"$CIMVR_PLUGINS;{}\"" + + # Clone the git repository into the specified directory + subprocess.run(["git", "clone", REPO_URL, dir_name], check=True) + + # Edit the name field in the Cargo.toml file + cargo_toml_path = os.path.join(dir_name, CARGO_TOML_FILE) + with open(cargo_toml_path, "r+") as f: + content = f.read() + name = os.path.basename(dir_name) + new_content = content.replace( + CARGO_TOML_NAME_FIELD, + f"name = \"{name}\"" + ) + f.seek(0) + f.write(new_content) + f.truncate() + + shutil + print("Edited Cargo.toml") + + # Append the export line to the user's .bashrc file + bashrc_export_line = BASHRC_EXPORT_LINE.format(os.path.abspath(dir_name)) + with open(BASHRC_FILE, "a") as f: + f.write("\n" + bashrc_export_line + "\n") + + to_delete = os.path.join(dir_name, ".git") + #if input(f"Remove template git path {to_delete}? [y/N] ") == 'y': + print(f"Deleting {to_delete}") + shutil.rmtree(to_delete); + + print("Done.") + + if __name__ == "__main__": main() diff --git a/obj_loader/src/obj.rs b/obj_loader/src/obj.rs index 8df95ea3..071eacf2 100644 --- a/obj_loader/src/obj.rs +++ b/obj_loader/src/obj.rs @@ -149,4 +149,3 @@ pub fn obj_lines_to_mesh(obj: &str) -> Mesh { m } - From ee05ef2ba577befd270705965b24ed6709291ec6 Mon Sep 17 00:00:00 2001 From: Masterchef365 Date: Sat, 6 May 2023 14:47:47 -0700 Subject: [PATCH 2/2] Nitpick cimvr new subcommand --- cimvr.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cimvr.py b/cimvr.py index f8961485..9f63ba44 100755 --- a/cimvr.py +++ b/cimvr.py @@ -44,8 +44,7 @@ def main(): # cimvr new "subcommand" - workaround for argparse if len(args.plugins) == 2 and args.plugins[0] == "new": - # This means you cannot have a plugin named "new" - # but if you do f*** you anyway + # This means you cannot have a plugin named "new" (but why would you?) create_new(args.plugins[1]) return; @@ -220,19 +219,19 @@ def create_new(dir_name): f.write(new_content) f.truncate() - shutil print("Edited Cargo.toml") - - # Append the export line to the user's .bashrc file - bashrc_export_line = BASHRC_EXPORT_LINE.format(os.path.abspath(dir_name)) - with open(BASHRC_FILE, "a") as f: - f.write("\n" + bashrc_export_line + "\n") to_delete = os.path.join(dir_name, ".git") #if input(f"Remove template git path {to_delete}? [y/N] ") == 'y': print(f"Deleting {to_delete}") shutil.rmtree(to_delete); + # Append the export line to the user's .bashrc file + bashrc_export_line = BASHRC_EXPORT_LINE.format(os.path.abspath(dir_name)) + with open(BASHRC_FILE, "a") as f: + f.write("\n" + bashrc_export_line + "\n") + print(f"Edited {BASHRC_FILE}") + print("Done.")