From 3d7fd76b58ddff719f202fb599f711e0aee580bf Mon Sep 17 00:00:00 2001 From: hi80482 <66435094+hi80482@users.noreply.github.com> Date: Fri, 3 Jul 2020 15:24:22 +0800 Subject: [PATCH] Add git.py (Sync Ver.200626) --- .../GameShell/10_Settings/BranchSelect/git.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Menu/GameShell/10_Settings/BranchSelect/git.py diff --git a/Menu/GameShell/10_Settings/BranchSelect/git.py b/Menu/GameShell/10_Settings/BranchSelect/git.py new file mode 100644 index 0000000..6198c62 --- /dev/null +++ b/Menu/GameShell/10_Settings/BranchSelect/git.py @@ -0,0 +1,26 @@ +import subprocess +import os + +def get_branches(path): + branches = subprocess.check_output(["git", "branch"], cwd=path).decode("utf-8").split("\n")[0:-1] + current = "" + result = [] + for branch in branches: + if branch[0] == "*": + current = branch + result.append(branch[2:]) + return result, current + +def checkout_branch(path, branch): + return subprocess.check_call(["git", "checkout", branch], cwd=path) + +def get_games(): + result = [] + for filename in os.listdir("/home/cpi/games"): + filename = os.path.join("/home/cpi/games", filename) + if os.path.isdir(filename) and is_git(filename): + result.append(filename) + return result + +def is_git(path): + return os.path.join(path, ".git") \ No newline at end of file