diff --git a/README.md b/README.md deleted file mode 100644 index 1dd646d..0000000 --- a/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Python-Scripting-Project - -# π» Launch Your Software Development Career Today! - -π **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. - -π **Why Join?** -- πΌ **70γγ«k+ starting salary potential** -- π **Self-paced:** Complete on your own time -- π€ **Affordable:** Low risk compared to expensive bootcamps or degrees -- π― **45,000+ job openings** in the market - -π **[Start your journey today!](https://techwithtim.net/dev)** -No experience neededβjust your determination. Future-proof your career and unlock six-figure potential like many of our students have! diff --git a/get_game_data.py b/get_game_data.py index a59e4a6..8fc2165 100644 --- a/get_game_data.py +++ b/get_game_data.py @@ -1,109 +1,102 @@ import os import json import shutil -from subprocess import PIPE, run +from subprocess import run, PIPE 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 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) + result = run(command, stdout=PIPE, stderr=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") - + game_paths = find_all_game_paths(source_path) + new_games_dirs = get_name_from_paths(game_paths, "game") + create_dir(target_path) - for src, dest in zip(game_paths, new_game_dirs): + for src, dest in zip(game_paths, new_games_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) + make_json_metadata_file(json_path, new_games_dirs) + +def find_all_game_paths(source): + game_path = [] + + for root, dirs, files in os.walk(source): + for directory in dirs: + if GAME_DIR_PATTERN in directory.lower(): + game_path.append(os.path.join(source, directory)) + break + return game_path + +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, + "no_of_games": len(game_dirs) + } + with open(path, 'w') as f: + json.dump(data, f) if __name__ == "__main__": args = sys.argv + # print(args) if len(args) != 3: - raise Exception("You must pass a source and target directory - only.") - + raise Exception("you must pass a source and target directory only.") + source, target = args[1:] - main(source, target) + main(source, target) \ No newline at end of file diff --git a/target/hello_world_/main.exe b/target/hello_world_/main.exe new file mode 100644 index 0000000..f83ed94 Binary files /dev/null and b/target/hello_world_/main.exe differ diff --git a/target/hello_world_/main.go b/target/hello_world_/main.go new file mode 100644 index 0000000..d2c4e91 --- /dev/null +++ b/target/hello_world_/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world") +} diff --git a/target/metadata.json b/target/metadata.json new file mode 100644 index 0000000..8fa305d --- /dev/null +++ b/target/metadata.json @@ -0,0 +1 @@ +{"gameNames": ["hello_world_", "rock_paper_scissors_", "simon_says_"], "no_of_games": 3} \ No newline at end of file diff --git a/target/rock_paper_scissors_/code.exe b/target/rock_paper_scissors_/code.exe new file mode 100644 index 0000000..befdf79 Binary files /dev/null and b/target/rock_paper_scissors_/code.exe differ diff --git a/target/rock_paper_scissors_/code.go b/target/rock_paper_scissors_/code.go new file mode 100644 index 0000000..57eccc3 --- /dev/null +++ b/target/rock_paper_scissors_/code.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Rock paper scissors"); +} \ No newline at end of file diff --git a/target/simon_says_/file.exe b/target/simon_says_/file.exe new file mode 100644 index 0000000..cba34e1 Binary files /dev/null and b/target/simon_says_/file.exe differ diff --git a/target/simon_says_/file.go b/target/simon_says_/file.go new file mode 100644 index 0000000..e42e138 --- /dev/null +++ b/target/simon_says_/file.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Simon says") +}