From e1ac0f386acba3bde60574c20fca1e3418b9fd8d Mon Sep 17 00:00:00 2001 From: Danielle Mirzaeian <56207905+dani962@users.noreply.github.com> Date: 2024年2月22日 10:13:06 -0500 Subject: [PATCH 1/3] Delete get_game_data.py --- get_game_data.py | 109 ----------------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 get_game_data.py diff --git a/get_game_data.py b/get_game_data.py deleted file mode 100644 index a59e4a6..0000000 --- a/get_game_data.py +++ /dev/null @@ -1,109 +0,0 @@ -import os -import json -import shutil -from subprocess import PIPE, run -import sys - - -GAME_DIR_PATTERN = "game" -GAME_CODE_EXTENSION = ".go" -GAME_COMPILE_COMMAND = ["go", "build"] - - -def find_all_game_paths(source): - game_paths = [] - - for root, dirs, files in os.walk(source): - for directory in dirs: - if GAME_DIR_PATTERN in directory.lower(): - path = os.path.join(source, directory) - game_paths.append(path) - - break - - return game_paths - - -def get_name_from_paths(paths, to_strip): - new_names = [] - for path in paths: - _, dir_name = os.path.split(path) - new_dir_name = dir_name.replace(to_strip, "") - new_names.append(new_dir_name) - - return new_names - - -def create_dir(path): - if not os.path.exists(path): - os.mkdir(path) - - -def copy_and_overwrite(source, dest): - if os.path.exists(dest): - shutil.rmtree(dest) - shutil.copytree(source, dest) - - -def make_json_metadata_file(path, game_dirs): - data = { - "gameNames": game_dirs, - "numberOfGames": len(game_dirs) - } - - with open(path, "w") as f: - json.dump(data, f) - - -def compile_game_code(path): - code_file_name = None - for root, dirs, files in os.walk(path): - for file in files: - if file.endswith(GAME_CODE_EXTENSION): - code_file_name = file - break - - break - - if code_file_name is None: - return - - command = GAME_COMPILE_COMMAND + [code_file_name] - run_command(command, path) - - -def run_command(command, path): - cwd = os.getcwd() - os.chdir(path) - - result = run(command, stdout=PIPE, stdin=PIPE, universal_newlines=True) - print("compile result", result) - - os.chdir(cwd) - -def main(source, target): - cwd = os.getcwd() - source_path = os.path.join(cwd, source) - target_path = os.path.join(cwd, target) - - game_paths = find_all_game_paths(source_path) - new_game_dirs = get_name_from_paths(game_paths, "_game") - - create_dir(target_path) - - for src, dest in zip(game_paths, new_game_dirs): - dest_path = os.path.join(target_path, dest) - copy_and_overwrite(src, dest_path) - compile_game_code(dest_path) - - json_path = os.path.join(target_path, "metadata.json") - make_json_metadata_file(json_path, new_game_dirs) - - -if __name__ == "__main__": - args = sys.argv - if len(args) != 3: - raise Exception("You must pass a source and target directory - only.") - - source, target = args[1:] - main(source, target) From f7536a11e1d6ab49f9b3c9536bcbf36f8f5313cd Mon Sep 17 00:00:00 2001 From: Danielle Mirzaeian <56207905+dani962@users.noreply.github.com> Date: 2024年2月22日 10:17:48 -0500 Subject: [PATCH 2/3] updated README.md file --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a750539..60aa8fe 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# Python-Scripting-Project \ No newline at end of file +# Python-Scripting-Project + +### This project is for learning basic Python scripting skills. \ No newline at end of file From 201a849a11326896ffe3695cc5df0f02bdc1978e Mon Sep 17 00:00:00 2001 From: Danielle Mirzaeian <56207905+dani962@users.noreply.github.com> Date: 2024年2月22日 11:10:55 -0500 Subject: [PATCH 3/3] Upload get_game_data.py --- get_game_data.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 get_game_data.py diff --git a/get_game_data.py b/get_game_data.py new file mode 100644 index 0000000..427b9e4 --- /dev/null +++ b/get_game_data.py @@ -0,0 +1,100 @@ +import os +import json +import shutil +from subprocess import PIPE, run +import sys + +GAME_DIR_PATTERN = "game" +GAME_CODE_EXTENSION = ".go" +GAME_COMPILE_COMMAND = ["go", "build"] + +def find_all_game_paths(source): + game_paths = [] + + for root, dirs, files in os.walk(source): + for directory in dirs: + if GAME_DIR_PATTERN in directory.lower(): + path = os.path.join(source, directory) + game_paths.append(path) + + break + + return game_paths + +def get_name_from_paths(paths, to_strip): + new_names = [] + for path in paths: + _, dir_name = os.path.split(path) + new_dir_name = dir_name.replace(to_strip, "") + new_names.append(new_dir_name) + + return new_names + +def create_dir(path): + if not os.path.exists(path): + os.mkdir(path) + +def copy_and_overwrite(source, dest): + if os.path.exists(dest): + shutil.rmtree(dest) + shutil.copytree(source, dest) + +def make_json_metadata_file(path, game_dirs): + data = { + "gameNames": game_dirs, + "numberOfGames": len(game_dirs) + } + + with open(path, "w") as f: + json.dump(data, f) + +def compile_game_code(path): + code_file_name = None + for root, dirs, files in os.walk(path): + for file in files: + if file.endswith(GAME_CODE_EXTENSION): + code_file_name = file + break + + break + + if code_file_name is None: + return + + command = GAME_COMPILE_COMMAND + [code_file_name] + run_command(command, path) + +def run_command(command, path): + cwd = os.getcwd() + os.chdir(path) + + result = run(command, stdout=PIPE, stdin=PIPE, universal_newlines=True) + print("compile result", result) + + os.chdir(cwd) + +def main(source, target): + cwd = os.getcwd() + source_path = os.path.join(cwd, source) + target_path = os.path.join(cwd, target) + + game_paths = find_all_game_paths(source_path) + new_game_dirs = get_name_from_paths(game_paths, "_game") + + create_dir(target_path) + + for src, dest in zip(game_paths, new_game_dirs): + dest_path = os.path.join(target_path, dest) + copy_and_overwrite(src, dest_path) + compile_game_code(dest_path) + + json_path = os.path.join(target_path, "metadata.json") + make_json_metadata_file(json_path, new_game_dirs) + +if __name__ == "__main__": + args = sys.argv + if len(args) != 3: + raise Exception("You must pass a source and target directory - only.") + + source, target = args[1:] + main(source, target)

AltStyle によって変換されたページ (->オリジナル) /