From df5e80d63cff8acce2b510e1f2be07a7e1369415 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Wed, 10 Jun 2020 00:12:21 +0100 Subject: branchsetup : new generic module, drop old branchinject, branchmaster && branchnext modules; plug the new module into the new cli client -> works magic --- src/backend/branchsetup.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/backend/branchsetup.py (limited to 'src/backend/branchsetup.py') diff --git a/src/backend/branchsetup.py b/src/backend/branchsetup.py new file mode 100644 index 0000000..5e0976e --- /dev/null +++ b/src/backend/branchsetup.py @@ -0,0 +1,71 @@ +#!/usr/bin/python3 + +import os +import subprocess +import sisyphus.check +import sisyphus.branchreset +import sisyphus.filesystem +import sys + +def start(branch,remote): + if "master" in branch: + if "gitlab" in remote: + remote = sisyphus.filesystem.remoteGitlab + elif "pagure" in remote: + remote = sisyphus.filesystem.remotePagure + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" + ) + elif "next" in branch: + if "gitlab" in remote: + remote = sisyphus.filesystem.remoteGitlab + elif "pagure" in remote: + remote = sisyphus.filesystem.remotePagure + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" + ) + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid branch" + " " + "'" + str(branch) + "'" +" " + "(options : master, next)" + ) + + portageRemote = [remote, sisyphus.filesystem.portageRepo] + redcoreRemote = [remote, sisyphus.filesystem.redcoreRepo] + portageConfigRemote = [remote, sisyphus.filesystem.portageConfigRepo] + remoteBranch = ['origin', branch] + + sisyphus.check.root() + sisyphus.branchreset.start() + + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageRepoDir, '.git')): + os.chdir(sisyphus.filesystem.portageRepoDir) + print("\nInjecting branch" + " " + "'" + branch + "'" + " " + "from" + " " + "/".join(portageRemote)) + subprocess.call(['git', 'init', '-q']) + subprocess.call(['git', 'remote', 'add', 'origin'] + "/".join(portageRemote).split()) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + branch.split() + ['--quiet']) + subprocess.call(['git', 'checkout', '-b'] + branch.split() + "/".join(remoteBranch).split() + ['--quiet']) + + if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreRepoDir, '.git')): + os.chdir(sisyphus.filesystem.redcoreRepoDir) + print("\nInjecting branch" + " " + "'" + branch + "'" + " " + "from" + " " + "/".join(redcoreRemote) + "\n") + subprocess.call(['git', 'init', '-q']) + subprocess.call(['git', 'remote', 'add', 'origin'] + "/".join(redcoreRemote).split()) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + branch.split() + ['--quiet']) + subprocess.call(['git', 'checkout', '-b'] + branch.split() + "/".join(remoteBranch).split() + ['--quiet']) + + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): + os.chdir(sisyphus.filesystem.portageConfigDir) + print("Injecting branch" + " " + "'" + branch + "'" + " " + "from" + " " + "/".join(portageConfigRemote) + "\n") + subprocess.call(['git', 'init', '-q']) + subprocess.call(['git', 'remote', 'add', 'origin'] + "/".join(portageConfigRemote).split()) + subprocess.call(['git', 'fetch', '--depth=1', 'origin'] + branch.split() + ['--quiet']) + subprocess.call(['git', 'checkout', '-b'] + branch.split() + "/".join(remoteBranch).split() + ['--quiet']) + + sisyphus.setjobs.start() + sisyphus.setprofile.start() + sisyphus.metadata.regenAnimated() -- cgit v1.2.3