本文整理汇总了Python中rbtools.utils.process.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:NurKaynar,项目名称:hacklab,代码行数:32,代码来源:plastic.py
示例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
开发者ID:flowblok,项目名称:rbtools,代码行数:35,代码来源:clearcase.py
示例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
开发者ID:jankoprowski,项目名称:rbtools,代码行数:32,代码来源:git.py
示例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)
开发者ID:mbait,项目名称:rbtools,代码行数:30,代码来源:git.py
示例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)
开发者ID:PlasticSCM,项目名称:rbtools,代码行数:28,代码来源:plastic.py
示例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)
开发者ID:bcelary,项目名称:rbtools,代码行数:29,代码来源:clearcase.py
示例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
开发者ID:RiverMeadow,项目名称:rbtools,代码行数:30,代码来源:svn.py
示例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)
开发者ID:reviewboard,项目名称:rbtools,代码行数:27,代码来源:test_scanning.py
示例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)
开发者ID:reviewboard,项目名称:rbtools,代码行数:31,代码来源:clearcase.py
示例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)
开发者ID:jerboaa,项目名称:rbtools,代码行数:27,代码来源:mercurial.py
示例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()
开发者ID:bcelary,项目名称:rbtools,代码行数:29,代码来源:checks.py
示例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
开发者ID:PlasticSCM,项目名称:rbtools,代码行数:30,代码来源:clearcase.py
示例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)
开发者ID:halvorlu,项目名称:rbtools,代码行数:27,代码来源:git.py
示例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
开发者ID:CheshireBat,项目名称:rbtools,代码行数:27,代码来源:git.py
示例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
开发者ID:gfournols,项目名称:rbtools,代码行数:59,代码来源:git.py
示例16: update_commits_with_reviewer_info
def update_commits_with_reviewer_info(self, options, review_url):
""" Use git commit --amend to add Reviewed-by: to each commit """
num_successful_updates = 0
if not self.rev_range_for_diff:
return 0 # don't know what commits to update, so bail.
# Get the list of commits we want to update.
commits = execute([self.git, "rev-list", "--reverse",
"..".join(self.rev_range_for_diff)],
ignore_errors=True, none_on_ignored_error=True,
split_lines=True)
if not commits:
return 0 # illegal commit-range
commits = [c.strip() for c in commits]
reviewed_by = "Reviewed-By:"
if options.target_people:
reviewed_by += " " + options.target_people
if options.target_people and options.target_groups:
reviewed_by += " and"
if options.target_groups:
reviewed_by += " groups:" + options.target_groups
reviewed_by += " <%s>" % review_url
# When post-review is run with -r, the first commits in our
# revrange will have already been updated with reviewer info
# (from previous calls to post-review for this review). In
# fact, the early commits may even have better reviewed-by
# information than we do, since they are more likely to have
# had the reviewers specified on the commandline when
# post-review was run. So if we see an existing commit with
# reviewed-by info, prefer that to our own reviewed-by text.
output = execute([self.git, "notes", "show", commits[0]],
with_errors=True, ignore_errors=True,
none_on_ignored_error=True)
if output:
for line in output.splitlines():
if line.startswith('Reviewed-By: ') and review_url in line:
reviewed_by = line
# We don't need to update this commit because we
# know it's reviewed-by text is already "right".
commits = commits[1:] # small optimization
num_successful_updates += 1 # count as a "null update"
break
# TODO(csilvers): shell-escape any nasty characters.
# Use perl to delete any old Reviewed-By messages and insert a new one
perlcmd = ("print unless /Reviewed-By: /i; "
"if (eof) { print; print q{%s} }" % reviewed_by)
git_editor_cmd = r'sh -c "perl -nli -e \"%s\" \"$1\""' % perlcmd
for commit in commits:
output = execute([self.git, "notes", "edit", commit],
env={"GIT_EDITOR": git_editor_cmd},
with_errors=True, ignore_errors=True,
none_on_ignored_error=True)
if output is not None:
num_successful_updates += 1
return num_successful_updates
开发者ID:Khan,项目名称:rbtools,代码行数:58,代码来源:git.py
示例17: _get_outgoing_diff
def _get_outgoing_diff(self, files):
"""
When working with a clone of a Mercurial remote, we need to find
out what the outgoing revisions are for a given branch. It would
be nice if we could just do `hg outgoing --patch <remote>`, but
there are a couple of problems with this.
For one, the server-side diff parser isn't yet equipped to filter out
diff headers such as "comparing with..." and "changeset: <rev>:<hash>".
Another problem is that the output of `outgoing` potentially includes
changesets across multiple branches.
In order to provide the most accurate comparison between one's local
clone and a given remote -- something akin to git's diff command syntax
`git diff <treeish>..<treeish>` -- we have to do the following:
- get the name of the current branch
- get a list of outgoing changesets, specifying a custom format
- filter outgoing changesets by the current branch name
- get the "top" and "bottom" outgoing changesets
- use these changesets as arguments to `hg diff -r <rev> -r <rev>`
Future modifications may need to be made to account for odd cases like
having multiple diverged branches which share partial history -- or we
can just punish developers for doing such nonsense :)
"""
files = files or []
remote = self._remote_path[0]
if not remote and self._options.parent_branch:
remote = self._options.parent_branch
current_branch = execute(['hg', 'branch'], env=self._hg_env).strip()
outgoing_changesets = \
self._get_outgoing_changesets(current_branch, remote)
top_rev, bottom_rev = \
self._get_top_and_bottom_outgoing_revs(outgoing_changesets) \
if len(outgoing_changesets) > 0 else (None, None)
if self._options.guess_summary and not self._options.summary:
self._options.summary = self.extract_summary(top_rev).rstrip("\n")
if self._options.guess_description and not self._options.description:
self._options.description = self.extract_description(bottom_rev,
top_rev)
if bottom_rev is not None and top_rev is not None:
full_command = ['hg', 'diff', '-r', str(bottom_rev), '-r',
str(top_rev)] + files
return (execute(full_command, env=self._hg_env), None)
else:
return ("", None)
开发者ID:PlasticSCM,项目名称:rbtools,代码行数:58,代码来源:mercurial.py
示例18: _write_file
def _write_file(self, depot_path, tmpfile):
"""
Grabs a file from Perforce and writes it to a temp file. p4 print sets
the file readonly and that causes a later call to unlink fail. So we
make the file read/write.
"""
logging.debug('Writing "%s" to "%s"' % (depot_path, tmpfile))
execute(["p4", "print", "-o", tmpfile, "-q", depot_path])
os.chmod(tmpfile, stat.S_IREAD | stat.S_IWRITE)
开发者ID:flowblok,项目名称:rbtools,代码行数:9,代码来源:perforce.py
示例19: _svn_add_file_commit
def _svn_add_file_commit(self, filename, data, msg, add_file=True):
outfile = open(filename, 'w')
outfile.write(data)
outfile.close()
if add_file:
execute(['svn', 'add', filename], ignore_errors=True)
execute(['svn', 'commit', '-m', msg])
开发者ID:reviewboard,项目名称:rbtools,代码行数:9,代码来源:test_mercurial.py
示例20: get_repository_info
def get_repository_info(self):
"""Returns information on the Clear Case repository.
This will first check if the cleartool command is
installed and in the path, and post-review was run
from inside of the view.
"""
if not check_install('cleartool help'):
return None
viewname = execute(["cleartool", "pwv", "-short"]).strip()
if viewname.startswith('** NONE'):
return None
# Now that we know it's ClearCase, make sure we have GNU diff installed,
# and error out if we don't.
check_gnu_diff()
property_lines = execute(["cleartool", "lsview", "-full", "-properties",
"-cview"], split_lines=True)
for line in property_lines:
properties = line.split(' ')
if properties[0] == 'Properties:':
# Determine the view type and check if it's supported.
#
# Specifically check if webview was listed in properties
# because webview types also list the 'snapshot'
# entry in properties.
if 'webview' in properties:
die("Webviews are not supported. You can use post-review"
" only in dynamic or snapshot view.")
if 'dynamic' in properties:
self.viewtype = 'dynamic'
else:
self.viewtype = 'snapshot'
break
# Find current VOB's tag
vobstag = execute(["cleartool", "describe", "-short", "vob:."],
ignore_errors=True).strip()
if "Error: " in vobstag:
die("To generate diff run post-review inside vob.")
# From current working directory cut path to VOB.
# VOB's tag contain backslash character before VOB's name.
# I hope that first character of VOB's tag like '\new_proj'
# won't be treat as new line character but two separate:
# backslash and letter 'n'
cwd = os.getcwd()
base_path = cwd[:cwd.find(vobstag) + len(vobstag)]
return ClearCaseRepositoryInfo(path=base_path,
base_path=base_path,
vobstag=vobstag,
supports_parent_diffs=False)
开发者ID:PlasticSCM,项目名称:rbtools,代码行数:56,代码来源:clearcase.py
注:本文中的rbtools.utils.process.execute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论