2018-06-04 15:46:28 +03:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2020-09-29 17:22:49 +03:00
|
|
|
|
2018-06-04 15:46:28 +03:00
|
|
|
class Mercurial(object):
|
|
|
|
def __init__(self, repo_root):
|
|
|
|
self.root = os.path.abspath(repo_root)
|
|
|
|
self.hg = Mercurial.get_func(repo_root)
|
|
|
|
|
|
|
|
@staticmethod
|
2018-06-15 01:51:26 +03:00
|
|
|
def get_func(repo_root):
|
2018-06-04 15:46:28 +03:00
|
|
|
def hg(cmd, *args):
|
|
|
|
full_cmd = ["hg", cmd] + list(args)
|
2018-06-15 01:51:26 +03:00
|
|
|
return subprocess.check_output(full_cmd, cwd=repo_root)
|
2018-06-04 15:46:28 +03:00
|
|
|
# TODO: Test on Windows.
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2018-06-04 15:46:28 +03:00
|
|
|
return hg
|
2018-06-15 01:51:26 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_hg_repo(repo_root):
|
|
|
|
try:
|
|
|
|
with open(os.devnull, "w") as devnull:
|
|
|
|
subprocess.check_call(
|
|
|
|
["hg", "root"], cwd=repo_root, stdout=devnull, stderr=devnull
|
|
|
|
)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
return False
|
2020-03-06 18:05:35 +03:00
|
|
|
except OSError:
|
|
|
|
return False
|
2018-06-15 01:51:26 +03:00
|
|
|
# TODO: Test on windows
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class Git(object):
|
|
|
|
def __init__(self, repo_root, url_base):
|
|
|
|
self.root = os.path.abspath(repo_root)
|
|
|
|
self.git = Git.get_func(repo_root)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_func(repo_root):
|
|
|
|
def git(cmd, *args):
|
|
|
|
full_cmd = ["git", cmd] + list(args)
|
|
|
|
return subprocess.check_output(full_cmd, cwd=repo_root)
|
|
|
|
# TODO: Test on Windows.
|
2020-10-26 21:34:53 +03:00
|
|
|
|
2018-06-15 01:51:26 +03:00
|
|
|
return git
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_git_repo(repo_root):
|
|
|
|
try:
|
|
|
|
with open(os.devnull, "w") as devnull:
|
|
|
|
subprocess.check_call(
|
|
|
|
["git", "rev-parse", "--show-cdup"],
|
|
|
|
cwd=repo_root,
|
2020-09-29 17:22:49 +03:00
|
|
|
stdout=devnull,
|
|
|
|
stderr=devnull,
|
|
|
|
)
|
2018-06-15 01:51:26 +03:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
return False
|
2020-03-06 18:05:35 +03:00
|
|
|
except OSError:
|
|
|
|
return False
|
2018-06-15 01:51:26 +03:00
|
|
|
# TODO: Test on windows
|
|
|
|
return True
|