本文整理汇总了Python中rbtools.utils.process.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_repository_info
def get_repository_info(self):
if not check_install('cm version'):
return None
# Get the repository that the current directory is from. If there
# is more than one repository mounted in the current directory,
# bail out for now (in future, should probably enter a review
# request per each repository.)
split = execute(["cm", "ls", "--format={8}"], split_lines=True,
ignore_errors=True)
m = re.search(r'^rep:(.+)$', split[0], re.M)
if not m:
return None
# Make sure the repository list contains only one unique entry
if len(split) != split.count(split[0]):
# Not unique!
die('Directory contains more than one mounted repository')
path = m.group(1)
# Get the workspace directory, so we can strip it from the diff output
self.workspacedir = execute(["cm", "gwp", ".", "--format={1}"],
split_lines=False,
ignore_errors=True).strip()
logging.debug("Workspace is %s" % self.workspacedir)
return RepositoryInfo(path,
supports_changesets=True,
supports_parent_diffs=False)
示例2: diff_files
def diff_files(self, old_file, new_file):
"""Return unified diff for file.
Most effective and reliable way is use gnu diff.
"""
diff_cmd = ["diff", "-uN", old_file, new_file]
dl = execute(diff_cmd, extra_ignore_errors=(1,2),
translate_newlines=False)
# If the input file has ^M characters at end of line, lets ignore them.
dl = dl.replace('\r\r\n', '\r\n')
dl = dl.splitlines(True)
# Special handling for the output of the diff tool on binary files:
# diff outputs "Files a and b differ"
# and the code below expects the output to start with
# "Binary files "
if (len(dl) == 1 and
dl[0].startswith('Files %s and %s differ' % (old_file, new_file))):
dl = ['Binary files %s and %s differ\n' % (old_file, new_file)]
# We need oids of files to translate them to paths on reviewboard repository
old_oid = execute(["cleartool", "describe", "-fmt", "%On", old_file])
new_oid = execute(["cleartool", "describe", "-fmt", "%On", new_file])
if dl == [] or dl[0].startswith("Binary files "):
if dl == []:
dl = ["File %s in your changeset is unmodified\n" % new_file]
dl.insert(0, "==== %s %s ====\n" % (old_oid, new_oid))
dl.append('\n')
else:
dl.insert(2, "==== %s %s ====\n" % (old_oid, new_oid))
return dl
示例3: make_diff
def make_diff(self, ancestor, commit=""):
"""
Performs a diff on a particular branch range.
"""
# Use `git diff ancestor..commit` by default, except from when there
# is no `commit` given - then use `git show ancestor`.
if commit:
diff_command = 'diff'
rev_range = "%s..%s" % (ancestor, commit)
else:
diff_command = 'show'
rev_range = ancestor
if self.type == "svn":
diff_lines = execute([self.git, diff_command, "--no-color",
"--no-prefix", "--no-ext-diff", "-r", "-u",
rev_range],
split_lines=True)
return self.make_svn_diff(ancestor, diff_lines)
elif self.type == "git":
cmdline = [self.git, diff_command, "--no-color", "--full-index",
"--no-ext-diff", "--ignore-submodules", "--no-renames",
rev_range]
if (self.capabilities is not None and
self.capabilities.has_capability('diffs', 'moved_files')):
cmdline.append('-M')
return execute(cmdline)
return None
示例4: diff
def diff(self, args):
"""
Performs a diff across all modified files in the branch, taking into
account a parent branch.
"""
parent_branch = self._options.parent_branch
self.merge_base = execute([self.git, "merge-base",
self.upstream_branch,
self.head_ref]).strip()
if parent_branch:
diff_lines = self.make_diff(parent_branch)
parent_diff_lines = self.make_diff(self.merge_base, parent_branch)
else:
diff_lines = self.make_diff(self.merge_base, self.head_ref)
parent_diff_lines = None
if self._options.guess_summary and not self._options.summary:
s = execute([self.git, "log", "--pretty=format:%s", "HEAD^.."],
ignore_errors=True)
self._options.summary = s.replace('\n', ' ').strip()
if self._options.guess_description and not self._options.description:
self._options.description = execute(
[self.git, "log", "--pretty=format:%s%n%n%b",
(parent_branch or self.merge_base) + ".."],
ignore_errors=True).strip()
return (diff_lines, parent_diff_lines)
示例5: get_repository_info
def get_repository_info(self):
if not check_install('cm version'):
return None
# Get the workspace directory, so we can strip it from the diff output
self.workspacedir = execute(["cm", "gwp", ".", "--format={1}"],
split_lines=False,
ignore_errors=True).strip()
logging.debug("Workspace is %s" % self.workspacedir)
# Get the repository that the current directory is from
split = execute(["cm", "ls", self.workspacedir, "--format={8}"], split_lines=True,
ignore_errors=True)
# remove blank lines
split = filter(None, split)
m = re.search(r'^rep:(.+)$', split[0], re.M)
if not m:
return None
path = m.group(1)
return RepositoryInfo(path,
supports_changesets=True,
supports_parent_diffs=False)
示例6: do_diff
def do_diff(self, changeset):
"""Generates a unified diff for all files in the changeset."""
diff = []
for old_file, new_file, xpatches in changeset:
# We need oids of files to translate them to paths on
# reviewboard repository
old_oid = execute(["cleartool", "describe", "-fmt", "%On",
old_file])
new_oid = execute(["cleartool", "describe", "-fmt", "%On",
new_file])
dl = self._diff(old_file, new_file, xpatches=xpatches)
oid_line = "==== %s %s ====" % (old_oid, new_oid)
if dl is None:
dl = [oid_line,
'Binary files %s and %s differ' % (old_file, new_file),
'']
elif not dl:
dl = [oid_line,
'File %s in your changeset is unmodified' % new_file,
'']
else:
dl.insert(2, oid_line)
diff.append(os.linesep.join(dl))
return (''.join(diff), None)
示例7: _apply_patch_for_empty_files
def _apply_patch_for_empty_files(self, patch, p_num):
"""Returns True if any empty files in the patch are applied.
If there are no empty files in the patch or if an error occurs while
applying the patch, we return False.
"""
patched_empty_files = False
added_files = re.findall(r"^Index:\s+(\S+)\t\(added\)$", patch, re.M)
deleted_files = re.findall(r"^Index:\s+(\S+)\t\(deleted\)$", patch, re.M)
if added_files:
added_files = self._strip_p_num_slashes(added_files, int(p_num))
make_empty_files(added_files)
result = execute(["svn", "add"] + added_files, ignore_errors=True, none_on_ignored_error=True)
if result is None:
logging.error('Unable to execute "svn add" on: %s', ", ".join(added_files))
else:
patched_empty_files = True
if deleted_files:
deleted_files = self._strip_p_num_slashes(deleted_files, int(p_num))
result = execute(["svn", "delete"] + deleted_files, ignore_errors=True, none_on_ignored_error=True)
if result is None:
logging.error('Unable to execute "svn delete" on: %s', ", ".join(deleted_files))
else:
patched_empty_files = True
return patched_empty_files
示例8: test_scanning_nested_repos_2
def test_scanning_nested_repos_2(self):
"""Testing scan_for_usable_client with nested repositories (svn inside
git)
"""
git_dir = os.path.join(self.testdata_dir, 'git-repo')
svn_dir = os.path.join(self.testdata_dir, 'svn-repo')
# Check out git first
clone_dir = self.chdir_tmp()
git_clone_dir = os.path.join(clone_dir, 'git-repo')
os.mkdir(git_clone_dir)
execute(['git', 'clone', git_dir, git_clone_dir],
env=None, ignore_errors=False, extra_ignore_errors=())
# Now check out svn.
svn_clone_dir = os.path.join(git_clone_dir, 'svn-repo')
os.chdir(git_clone_dir)
execute(['svn', 'co', 'file://%s' % svn_dir, 'svn-repo'],
env=None, ignore_errors=False, extra_ignore_errors=())
os.chdir(svn_clone_dir)
repository_info, tool = scan_usable_client({}, self.options)
self.assertEqual(repository_info.local_path,
os.path.realpath(svn_clone_dir))
self.assertEqual(type(tool), SVNClient)
示例9: _set_label
def _set_label(self, label, path):
"""Set a ClearCase label on elements seen under path.
Args:
label (unicode):
The label to set.
path (unicode):
The filesystem path to set the label on.
"""
checkedout_elements = self._list_checkedout(path)
if checkedout_elements:
raise Exception(
'ClearCase backend cannot set label when some elements are '
'checked out:\n%s' % ''.join(checkedout_elements))
# First create label in vob database.
execute(['cleartool', 'mklbtype', '-c', 'label created for rbtools',
label],
with_errors=True)
# We ignore return code 1 in order to omit files that ClearCase cannot
# read.
recursive_option = ''
if cpath.isdir(path):
recursive_option = '-recurse'
# Apply label to path.
execute(['cleartool', 'mklabel', '-nc', recursive_option, label, path],
extra_ignore_errors=(1,),
with_errors=False)
示例10: diff_between_revisions
def diff_between_revisions(self, revision_range, args, repository_info):
"""
Performs a diff between 2 revisions of a Mercurial repository.
"""
if self._type != 'hg':
raise NotImplementedError
if ':' in revision_range:
r1, r2 = revision_range.split(':')
else:
# If only 1 revision is given, we find the first parent and use
# that as the second revision.
#
# We could also use "hg diff -c r1", but then we couldn't reuse the
# code for extracting descriptions.
r2 = revision_range
r1 = execute(["hg", "parents", "-r", r2,
"--template", "{rev}\n"]).split()[0]
if self._options.guess_summary and not self._options.summary:
self._options.summary = self.extract_summary(r2)
if self._options.guess_description and not self._options.description:
self._options.description = self.extract_description(r1, r2)
return (execute(["hg", "diff", "-r", r1, "-r", r2],
env=self._hg_env), None)
示例11: check_gnu_patch
def check_gnu_patch():
"""Checks if GNU patch is installed, and informs the user if it's not."""
has_gnu_patch = False
try:
result = execute(['patch', '--version'], ignore_errors=True)
has_gnu_patch = 'Free Software Foundation' in result
except OSError:
pass
try:
# SunOS has gpatch
result = execute(['gpatch', '--version'], ignore_errors=True)
has_gnu_patch = 'Free Software Foundation' in result
except OSError:
pass
if not has_gnu_patch:
sys.stderr.write('\n')
sys.stderr.write('GNU patch is required to post this review.'
'Make sure it is installed and in the path.\n')
sys.stderr.write('\n')
if os.name == 'nt':
sys.stderr.write('On Windows, you can install this from:\n')
sys.stderr.write(GNU_PATCH_WIN32_URL)
sys.stderr.write('\n')
die()
示例12: diff_directories
def diff_directories(self, old_dir, new_dir):
"""Return uniffied diff between two directories content.
Function save two version's content of directory to temp
files and treate them as casual diff between two files.
"""
old_content = self._directory_content(old_dir)
new_content = self._directory_content(new_dir)
old_tmp = make_tempfile(content=old_content)
new_tmp = make_tempfile(content=new_content)
diff_cmd = ["diff", "-uN", old_tmp, new_tmp]
dl = execute(diff_cmd,
extra_ignore_errors=(1, 2),
translate_newlines=False,
split_lines=True)
# Replacing temporary filenames to
# real directory names and add ids
if dl:
dl[0] = dl[0].replace(old_tmp, old_dir)
dl[1] = dl[1].replace(new_tmp, new_dir)
old_oid = execute(["cleartool", "describe", "-fmt", "%On",
old_dir])
new_oid = execute(["cleartool", "describe", "-fmt", "%On",
new_dir])
dl.insert(2, "==== %s %s ====\n" % (old_oid, new_oid))
return dl
示例13: merge
def merge(self, target, destination, message, author, squash=False,
run_editor=False):
"""Merges the target branch with destination branch."""
rc, output = execute(
['git', 'checkout', destination],
ignore_errors=True,
return_error_code=True)
if rc:
raise MergeError("Could not checkout to branch '%s'.\n\n%s" %
(destination, output))
if squash:
method = '--squash'
else:
method = '--no-ff'
rc, output = execute(
['git', 'merge', target, method, '--no-commit'],
ignore_errors=True,
return_error_code=True)
if rc:
raise MergeError("Could not merge branch '%s' into '%s'.\n\n%s" %
(target, destination, output))
self.create_commit(message, author, run_editor)
示例14: make_diff
def make_diff(self, ancestor, commit=""):
"""
Performs a diff on a particular branch range.
"""
if commit:
rev_range = "%s..%s" % (ancestor, commit)
else:
rev_range = ancestor
if self.type == "svn":
diff_lines = execute([self.git, "diff", "--no-color",
"--no-prefix", "--no-ext-diff", "-r", "-u",
rev_range],
split_lines=True)
return self.make_svn_diff(ancestor, diff_lines)
elif self.type == "git":
cmdline = [self.git, "diff", "--no-color", "--full-index",
"--no-ext-diff", "--ignore-submodules", "--no-renames",
rev_range]
if (self.capabilities is not None and
self.capabilities.has_capability('diffs', 'moved_files')):
cmdline.append('-M')
return execute(cmdline)
return None
示例15: make_svn_diff
def make_svn_diff(self, parent_branch, diff_lines):
"""
Formats the output of git diff such that it's in a form that
svn diff would generate. This is needed so the SVNTool in Review
Board can properly parse this diff.
"""
rev = execute([self.git, "svn", "find-rev", parent_branch]).strip()
if not rev and self.merge_base:
rev = execute([self.git, "svn", "find-rev",
self.merge_base]).strip()
if not rev:
return None
diff_data = ""
filename = ""
newfile = False
for line in diff_lines:
if line.startswith("diff "):
# Grab the filename and then filter this out.
# This will be in the format of:
#
# diff --git a/path/to/file b/path/to/file
info = line.split(" ")
diff_data += "Index: %s\n" % info[2]
diff_data += "=" * 67
diff_data += "\n"
elif line.startswith("index "):
# Filter this out.
pass
elif line.strip() == "--- /dev/null":
# New file
newfile = True
elif line.startswith("--- "):
newfile = False
diff_data += "--- %s\t(revision %s)\n" % \
(line[4:].strip(), rev)
elif line.startswith("+++ "):
filename = line[4:].strip()
if newfile:
diff_data += "--- %s\t(revision 0)\n" % filename
diff_data += "+++ %s\t(revision 0)\n" % filename
else:
# We already printed the "--- " line.
diff_data += "+++ %s\t(working copy)\n" % filename
elif line.startswith("new file mode"):
# Filter this out.
pass
elif line.startswith("Binary files "):
# Add the following so that we know binary files were
# added/changed.
diff_data += "Cannot display: file marked as a binary type.\n"
diff_data += "svn:mime-type = application/octet-stream\n"
else:
diff_data += line
return diff_data