本文整理汇总了Python中sh.git方法的典型用法代码示例。如果您正苦于以下问题:Python sh.git方法的具体用法?Python sh.git怎么用?Python sh.git使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sh
的用法示例。
在下文中一共展示了sh.git方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_stress
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def build_stress(stress_revision, name=None):
# Build a stress revision
try:
git_id = sh.git('--git-dir={home}/fab/cassandra.git'
.format(home=HOME), 'rev-parse', stress_revision).strip()
except sh.ErrorReturnCode:
raise AssertionError('Invalid stress_revision: {}'.format(stress_revision))
path = os.path.join(CASSANDRA_STRESS_PATH, git_id)
if not os.path.exists(path):
logger.info("Building cassandra-stress '{}' in '{}'.".format(stress_revision, path))
os.makedirs(path)
sh.tar(
sh.git("--git-dir={home}/fab/cassandra.git".format(home=HOME), "archive", git_id),
'x', '-C', path
)
antcmd('-Dbasedir={}'.format(path), '-f', '{}/build.xml'.format(path),
'realclean', 'jar', _env={"JAVA_TOOL_OPTIONS": "-Dfile.encoding=UTF8",
"JAVA_HOME": JAVA_HOME})
name = name if name else stress_revision
return {name: git_id}
示例2: setup
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def setup(flamegraph_directory, flamegraph_path, perf_map_agent_path, java_home):
"""Setup deps for flamegraph"""
# Create the flamegraph directory and clean the directory
if not os.path.exists(flamegraph_directory):
os.mkdir(flamegraph_directory)
for f in os.listdir(flamegraph_directory):
file_path = os.path.join(flamegraph_directory, f)
sh.sudo.rm(file_path)
if not os.path.exists(perf_map_agent_path):
sh.git('clone', 'https://github.com/jrudolph/perf-map-agent', perf_map_agent_path)
sh.cmake('.', _cwd=perf_map_agent_path, _env={'JAVA_HOME': java_home})
sh.make(_cwd=perf_map_agent_path)
if not os.path.exists(flamegraph_path):
sh.git('clone', 'https://github.com/brendangregg/FlameGraph', flamegraph_path)
示例3: test_clone_no_fallback
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_clone_no_fallback(self, sh_mock):
config = configparser.RawConfigParser()
config.read("projects.ini")
config.set('DEFAULT', 'fallback_to_master', '0')
self.config = ConfigOptions(config)
# We need to redefine the mock object again, to use a side effect
# that will fail in the git checkout call. A bit convoluted, but
# it works
with mock.patch.object(sh.Command, '__call__') as new_mock:
new_mock.side_effect = _aux_sh
self.assertRaises(sh.ErrorReturnCode_1, repositories.refreshrepo,
'url', 'path', branch='branch')
expected = [mock.call('url', 'path'),
mock.call('origin'),
mock.call('-f', 'branch')]
self.assertEqual(new_mock.call_args_list, expected)
示例4: download_and_build_spark_cassandra_stress
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def download_and_build_spark_cassandra_stress(stress_node=None):
dse_home = 'DSE_HOME={dse_path}'.format(dse_path=dse.get_dse_path())
dse_resources = 'DSE_RESOURCES={dse_resources_path}'.format(dse_resources_path=os.path.join(dse.get_dse_path(), 'resources'))
spark_cassandra_stress_git = 'https://github.com/datastax/spark-cassandra-stress.git'
git_clone_spark_cass_stress_command = 'git clone -b master --single-branch ' \
'{spark_cass_stress_git} ' \
'{spark_cass_stress_path}'.format(spark_cass_stress_git=spark_cassandra_stress_git,
spark_cass_stress_path=get_spark_cassandra_stress_path(stress_node=stress_node))
build_command = './gradlew jar -Pagainst=dse;'
full_build_command = 'cd {spark_cass_stress_path}; TERM=dumb {dse_home} {dse_resources} {build_cmd}'.format(
spark_cass_stress_path=get_spark_cassandra_stress_path(),
dse_home=dse_home,
dse_resources=dse_resources,
build_cmd=build_command
)
if stress_node:
with common.fab.settings(hosts=stress_node):
execute(fab.run, 'rm -rf {spark_cass_stress_path}'.format(spark_cass_stress_path=get_spark_cassandra_stress_path(stress_node=stress_node)))
execute(fab.run, git_clone_spark_cass_stress_command)
execute(fab.run, full_build_command)
else:
shutil.rmtree(get_spark_cassandra_stress_path(), ignore_errors=True)
logger.info('Installing Spark-Cassandra-Stress from {spark_cass_stress_git}'.format(spark_cass_stress_git=spark_cassandra_stress_git))
proc = subprocess.Popen(git_clone_spark_cass_stress_command, shell=True)
proc.wait()
assert proc.returncode == 0, 'Installing Spark-Cassandra-Stress from {spark_cass_stress_git} ' \
'did not complete successfully'.format(spark_cass_stress_git=spark_cassandra_stress_git)
logger.info('Building Spark-Cassandra-Stress using {full_build_command}'.format(full_build_command=full_build_command))
proc = subprocess.Popen(full_build_command, shell=True)
proc.wait()
assert proc.returncode == 0, 'Building Spark-Cassandra-Stress using {full_build_command} ' \
'did not complete successfully'.format(full_build_command=full_build_command)
示例5: test_clone_if_not_cloned
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_clone_if_not_cloned(self, sh_mock):
repositories.refreshrepo('url', 'path', branch='branch')
expected = [mock.call(sh.git.clone, 'url', 'path'),
mock.call(sh.git.fetch, 'origin'),
mock.call(sh.git.checkout, '-f', 'branch'),
mock.call(sh.git.reset, '--hard', 'origin/branch'),
mock.call(sh.git.log, '--pretty=format:%H %ct', '-1', '.')]
self.assertEqual(sh_mock.call_args_list, expected)
示例6: test_dont_clone_if_cloned
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_dont_clone_if_cloned(self, path_mock, shutil_mock, sh_mock):
repositories.refreshrepo('url', 'path', branch='branch')
expected = [mock.call(sh.git, 'remote', '-v'),
mock.call(sh.git.clone, 'url', 'path'),
mock.call(sh.git.fetch, 'origin'),
mock.call(sh.git.checkout, '-f', 'branch'),
mock.call(sh.git.reset, '--hard', 'origin/branch'),
mock.call(sh.git.log, '--pretty=format:%H %ct', '-1', '.')]
self.assertEqual(sh_mock.call_args_list, expected)
示例7: test_dont_fetch_if_local_repo_exists
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_dont_fetch_if_local_repo_exists(self, path_mock, sh_mock):
repositories.refreshrepo('url', 'path', branch='branch', local=True)
expected = [mock.call(sh.git.log, '--pretty=format:%H %ct', '-1', '.')]
self.assertEqual(sh_mock.call_args_list, expected)
示例8: test_clone_fetch_if_local_repo_missing
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_clone_fetch_if_local_repo_missing(self, sh_mock):
repositories.refreshrepo('url', 'path', branch='branch', local=True)
expected = [mock.call(sh.git.clone, 'url', 'path'),
mock.call(sh.git.fetch, 'origin'),
mock.call(sh.git.checkout, '-f', 'branch'),
mock.call(sh.git.reset, '--hard', 'origin/branch'),
mock.call(sh.git.log, '--pretty=format:%H %ct', '-1', '.')]
self.assertEqual(sh_mock.call_args_list, expected)
示例9: __git_raw
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def __git_raw(*args):
"""
@return sh.RunningCommand
Proxies the specified git command+args and returns it
"""
return sh.git(args)
示例10: __git
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def __git(*args):
"""
Proxies the specified git command+args and returns a cleaned up version
of the stdout buffer.
"""
return __git_raw(*args).stdout.replace('\n', '')
示例11: test_run_command
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_run_command(capsys):
cmd = sh.git.bake(version=True)
util.run_command(cmd)
result, _ = capsys.readouterr()
assert "" == result
示例12: test_run_command_with_debug
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def test_run_command_with_debug(temp_dir, capsys):
cmd = sh.git.bake(version=True)
util.run_command(cmd, debug=True)
result, _ = capsys.readouterr()
x = "COMMAND: {} --version".format(sh.git)
assert x in result
x = "PWD: {}".format(temp_dir)
assert x in result
示例13: update_devel
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def update_devel(self):
if not os.path.exists(self.develdir):
logger.debug('git clone %s %s' % (self.DEVEL_URL, self.develdir))
git('clone', self.DEVEL_URL, self.develdir)
else:
cmd = 'cd %s; git fetch -a; git pull --rebase origin devel' % self.develdir
logger.debug(cmd)
run_command(cmd)
示例14: status
# 需要导入模块: import sh [as 别名]
# 或者: from sh import git [as 别名]
def status(path: str = '.') -> Optional[Mapping[str, Any]]:
try:
output = sh.git(
"status", "-s", "-b", "--porcelain=2",
_cwd=os.path.expanduser(path)
)
except:
return None
head = None
upstream = None
ahead, behind = 0, 0
modified: List[str] = []
untracked: List[str] = []
for line in output.rstrip('\n').splitlines():
if line.startswith('#'):
if line.startswith("# branch.oid "):
oid = line.rsplit(' ', 1)[1]
if line.startswith("# branch.head "):
branch = line.rsplit(' ', 1)[1]
if branch != "(detached)":
head = branch
elif line.startswith("# branch.upstream "):
branch = line.rsplit(' ', 1)[1]
if branch != "(detached)":
upstream = branch
elif line.startswith("# branch.ab "):
ahead, behind = [abs(int(x)) for x in line.rsplit(' ', 2)[1:]]
elif line.startswith('?'):
untracked.append(line.rsplit(' ', -1)[1])
elif not line.startswith('!'):
vals = line.split(' ')
s, _, _, u = vals[2]
flag = s == 'S' and u == 'U'
(untracked if flag else modified).append(vals[-1])
return {
"path": path,
"oid": oid,
"branch": {
"head": head,
"upstream": upstream
},
"commits": {
"ahead": ahead,
"behind": behind
},
"files": {
"modified": modified,
"untracked": untracked
}
}