aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2017-12-14 17:57:10 +0100
committerDiana Picus <diana.picus@linaro.org>2017-12-15 13:11:39 +0100
commit5ad5542c5207056c4420b80b3fc8c211bce1e83e (patch)
treefdd286529e34f9574d3994da9dc44a4062cf5790
parent052b7d37cefe8975f699110a5c9508b2501a97e0 (diff)
downloadlinaro-scripts-5ad5542c5207056c4420b80b3fc8c211bce1e83e.tar.gz
Move more stuff from modules.llvm to modules.utils
Move some helpers that aren't directly dealing with LLVM knowledge from modules/llvm.py to modules/utils.py. Change-Id: I792286b06a99852facc7bc77b7c39ed67988e18f
-rw-r--r--modules/llvm.py46
-rw-r--r--modules/utils.py46
-rw-r--r--scripts/llvm.py4
-rw-r--r--tests/unittests/testpush.py2
4 files changed, 49 insertions, 49 deletions
diff --git a/modules/llvm.py b/modules/llvm.py
index 2625038..76b317e 100644
--- a/modules/llvm.py
+++ b/modules/llvm.py
@@ -324,49 +324,3 @@ class LLVMBuildConfig(object):
cmakeSubprojFlags))
return cmakeSubprojFlags
-
-
-# FIXME: repo.pushToBranch doesn't work, because it doesn't handle remote
-# branches properly. Furthermore, there's no support for getting the remote URL,
-# so we need to resort to raw git commands. We may also consider moving the
-# functionality for parsing info out of the remote URL into the repo object.
-from sh import git
-from linaropy.cd import cd
-
-
-def get_user_from_remote(url):
- """Get the username used as part of the remote URL, or None.
-
- The remote URLs that we expect to see look like $protocol://$user@$location.
- If they look any different, we won't be able to parse them.
- """
- pattern = re.compile("(.*://)?(?P<user>.*)@(.*)\n?")
- match = pattern.match(str(url))
- if match is None:
- return None
- return match.group('user')
-
-
-def get_remote_branch(repo, local_branch):
- """
- Get the name of the remote branch corresponding to the given local branch.
- """
- with cd(repo.repodir):
- remote = git("remote", "get-url", "--push", "origin").strip()
- user = get_user_from_remote(remote)
- if not user:
- raise EnvironmentError("Couldn't parse user from {}.".format(remote))
-
- remote_branch = "linaro-local/{}/{}".format(user, local_branch)
- if not repo.is_valid_branch_name(remote_branch):
- raise EnvironmentError(
- "{} is not a valid branch name.".format(remote_branch))
-
- return remote_branch
-
-
-def push_branch(proj, local_branch, remote_branch, pathToRepo):
- """Push the given local branch into origin's given remote branch."""
- repo = Worktree(proj, pathToRepo)
- with cd(repo.repodir):
- git("push", "-u", "origin", "+{}:{}".format(local_branch, remote_branch))
diff --git a/modules/utils.py b/modules/utils.py
index 9e6f29a..7d27de5 100644
--- a/modules/utils.py
+++ b/modules/utils.py
@@ -27,3 +27,49 @@ class CommandRunner(object):
except CalledProcessError as exc:
raise RuntimeError(
"Error while running command\n{}".format(str(exc.output, 'utf-8'))) from exc
+
+
+# FIXME: repo.pushToBranch doesn't work, because it doesn't handle remote
+# branches properly. Furthermore, there's no support for getting the remote URL,
+# so we need to resort to raw git commands. We may also consider moving the
+# functionality for parsing info out of the remote URL into the repo object.
+from sh import git
+from linaropy.cd import cd
+
+
+def get_user_from_remote(url):
+ """Get the username used as part of the remote URL, or None.
+
+ The remote URLs that we expect to see look like $protocol://$user@$location.
+ If they look any different, we won't be able to parse them.
+ """
+ pattern = re.compile("(.*://)?(?P<user>.*)@(.*)\n?")
+ match = pattern.match(str(url))
+ if match is None:
+ return None
+ return match.group('user')
+
+
+def get_remote_branch(repo, local_branch):
+ """
+ Get the name of the remote branch corresponding to the given local branch.
+ """
+ with cd(repo.repodir):
+ remote = git("remote", "get-url", "--push", "origin").strip()
+ user = get_user_from_remote(remote)
+ if not user:
+ raise EnvironmentError("Couldn't parse user from {}.".format(remote))
+
+ remote_branch = "linaro-local/{}/{}".format(user, local_branch)
+ if not repo.is_valid_branch_name(remote_branch):
+ raise EnvironmentError(
+ "{} is not a valid branch name.".format(remote_branch))
+
+ return remote_branch
+
+
+def push_branch(proj, local_branch, remote_branch, pathToRepo):
+ """Push the given local branch into origin's given remote branch."""
+ repo = Worktree(proj, pathToRepo)
+ with cd(repo.repodir):
+ git("push", "-u", "origin", "+{}:{}".format(local_branch, remote_branch))
diff --git a/scripts/llvm.py b/scripts/llvm.py
index 2489171..919caf9 100644
--- a/scripts/llvm.py
+++ b/scripts/llvm.py
@@ -7,10 +7,10 @@ from sys import exit
from modules.llvm import LLVMBuildConfig
from modules.llvm import LLVMSubproject
from modules.llvm import LLVMSourceConfig
-from modules.llvm import get_remote_branch
-from modules.llvm import push_branch
from modules.utils import CommandPrinter
from modules.utils import CommandRunner
+from modules.utils import get_remote_branch
+from modules.utils import push_branch
from linaropy.cd import cd
from linaropy.git.clone import Clone
diff --git a/tests/unittests/testpush.py b/tests/unittests/testpush.py
index 3eb8e35..d25c93d 100644
--- a/tests/unittests/testpush.py
+++ b/tests/unittests/testpush.py
@@ -9,7 +9,7 @@ from linaropy.proj import Proj
from linaropy.git.clone import Clone
from linaropy.git.worktree import Worktree
-from modules.llvm import get_user_from_remote, get_remote_branch, push_branch
+from modules.utils import get_user_from_remote, get_remote_branch, push_branch
# FIXME: Maybe move these helpers somewhere more public, or use LLVMTestCase for
# these tests as well...