本文整理汇总了Python中subprocess2.check_output函数的典型用法代码示例。如果您正苦于以下问题:Python check_output函数的具体用法?Python check_output怎么用?Python check_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_up_git
def set_up_git(self):
"""Creates git repositories and start the servers."""
self.set_up()
if self.gitdaemon:
return True
assert self.git_pid_file == None
try:
subprocess2.check_output(["git", "--version"])
except (OSError, subprocess2.CalledProcessError):
return False
for repo in ["repo_%d" % r for r in range(1, self.NB_GIT_REPOS + 1)]:
subprocess2.check_call(["git", "init", "-q", join(self.git_root, repo)])
self.git_hashes[repo] = [None]
self.git_port = find_free_port(self.host, 20000)
self.git_base = "git://%s:%d/git/" % (self.host, self.git_port)
# Start the daemon.
self.git_pid_file = tempfile.NamedTemporaryFile()
cmd = [
"git",
"daemon",
"--export-all",
"--reuseaddr",
"--base-path=" + self.root_dir,
"--pid-file=" + self.git_pid_file.name,
"--port=%d" % self.git_port,
]
if self.host == "127.0.0.1":
cmd.append("--listen=" + self.host)
self.check_port_is_free(self.git_port)
self.gitdaemon = subprocess2.Popen(cmd, cwd=self.root_dir, stdout=subprocess2.PIPE, stderr=subprocess2.PIPE)
wait_for_port_to_bind(self.host, self.git_port, self.gitdaemon)
self.populateGit()
self.git_dirty = False
return True
示例2: GuessVCS
def GuessVCS(options, path):
"""Helper to guess the version control system.
NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't
support it yet.
This examines the path directory, guesses which SCM we're using, and
returns an instance of the appropriate class. Exit with an error if we can't
figure it out.
Returns:
A SCM instance. Exits if the SCM can't be guessed.
"""
__pychecker__ = 'no-returnvalues'
real_path = path.split('@')[0]
logging.info("GuessVCS(%s)" % path)
# Subversion has a .svn in all working directories.
if os.path.isdir(os.path.join(real_path, '.svn')):
return SVN(options, path)
# Git has a command to test if you're in a git tree.
# Try running it, but don't die if we don't have git installed.
try:
subprocess2.check_output(
['git', 'rev-parse', '--is-inside-work-tree'], cwd=real_path,
stderr=subprocess2.VOID)
return GIT(options, path)
except subprocess2.CalledProcessError, e:
if e.returncode != errno.ENOENT and e.returncode != 128:
# ENOENT == 2 = they don't have git installed.
# 128 = git error code when not in a repo.
logging.warning('Unexpected error code: %s' % e.returncode)
raise
示例3: _set_svn_commit_date
def _set_svn_commit_date(self, revision, date):
subprocess2.check_output(
['svn', 'propset', 'svn:date', '--revprop', '-r', revision, date,
self.svn_base,
'--username', self.USERS[0][0],
'--password', self.USERS[0][1],
'--non-interactive'])
示例4: testMove
def testMove(self):
co = self._get_co(None)
self._check_move(co)
out = subprocess2.check_output(["svn", "status"], cwd=co.project_path)
out = sorted(out.splitlines())
expected = sorted(["A + chromeos/views/webui_menu_widget.h", "D chromeos/views/DOMui_menu_widget.h"])
self.assertEquals(expected, out)
# Make sure ancestry is what is expected;
env = os.environ.copy()
env["LANGUAGE"] = "en_US.UTF-8"
out = subprocess2.check_output(
["svn", "info", "chromeos/views/webui_menu_widget.h"], cwd=co.project_path, env=env
)
values = dict(l.split(": ", 1) for l in out.splitlines() if l)
expected = {
"Checksum": "65837bb3da662c8fa88a4a50940ea7c6",
"Copied From Rev": "2",
"Copied From URL": "%strunk/chromeos/views/DOMui_menu_widget.h" % self.svn_base,
"Name": "webui_menu_widget.h",
"Node Kind": "file",
"Path": "chromeos/views/webui_menu_widget.h",
"Repository Root": "%s" % self.svn_base.rstrip("/"),
"Revision": "2",
"Schedule": "add",
"URL": "%strunk/chromeos/views/webui_menu_widget.h" % self.svn_base,
}
self.assertEquals(expected, values)
示例5: testMove
def testMove(self):
co = self._get_co(None)
self._check_move(co)
out = subprocess2.check_output(
['svn', 'status'], cwd=co.project_path)
out = sorted(out.splitlines())
expected = sorted(
[
'A + chromeos/views/webui_menu_widget.h',
'D chromeos/views/DOMui_menu_widget.h',
])
self.assertEquals(expected, out)
# Make sure ancestry is what is expected;
env = os.environ.copy()
env['LANGUAGE'] = 'en_US.UTF-8'
out = subprocess2.check_output(
['svn', 'info', 'chromeos/views/webui_menu_widget.h'],
cwd=co.project_path,
env=env)
values = dict(l.split(': ', 1) for l in out.splitlines() if l)
expected = {
'Checksum': '65837bb3da662c8fa88a4a50940ea7c6',
'Copied From Rev': '2',
'Copied From URL':
'%strunk/chromeos/views/DOMui_menu_widget.h' % self.svn_base,
'Name': 'webui_menu_widget.h',
'Node Kind': 'file',
'Path': 'chromeos/views/webui_menu_widget.h',
'Repository Root': '%s' % self.svn_base.rstrip('/'),
'Revision': '2',
'Schedule': 'add',
'URL': '%strunk/chromeos/views/webui_menu_widget.h' % self.svn_base,
}
self.assertEquals(expected, values)
示例6: start_master
def start_master(master, path):
try:
subprocess2.check_output(
['make', 'start'], timeout=120, cwd=path,
stderr=subprocess2.STDOUT)
except subprocess2.CalledProcessError, e:
logging.error('Error: cannot start %s' % master)
print e
return False
示例7: test_check_output_throw_no_stderr
def test_check_output_throw_no_stderr(self):
try:
subprocess2.check_output(
self.exe + ['--fail', '--stderr'], universal_newlines=True)
self.fail()
except subprocess2.CalledProcessError, e:
self.assertEquals('', e.stdout)
self.assertEquals(None, e.stderr)
self.assertEquals(64, e.returncode)
示例8: _start_roll
def _start_roll(self, last_roll_revision, new_roll_revision):
roll_branch = '%s_roll' % self._project
cwd_kwargs = {'cwd': self._path_to_chrome}
subprocess2.check_call(['git', 'clean', '-d', '-f'], **cwd_kwargs)
subprocess2.call(['git', 'rebase', '--abort'], **cwd_kwargs)
subprocess2.call(['git', 'branch', '-D', roll_branch], **cwd_kwargs)
subprocess2.check_call(['git', 'checkout', 'origin/master', '-f'],
**cwd_kwargs)
subprocess2.check_call(['git', 'checkout', '-b', roll_branch,
'-t', 'origin/master', '-f'], **cwd_kwargs)
try:
subprocess2.check_call(['roll-dep-svn', self._path_to_project,
new_roll_revision], **cwd_kwargs)
subprocess2.check_call(['git', 'add', 'DEPS'], **cwd_kwargs)
subprocess2.check_call(['git', 'commit', '--no-edit'], **cwd_kwargs)
commit_msg = subprocess2.check_output(
['git', 'log', '-n1', '--format=%B', 'HEAD'],
**cwd_kwargs).decode('utf-8')
if self._notry:
commit_msg += NO_TRY_STR % { 'project': self._project }
upload_cmd = ['git', 'cl', 'upload', '--bypass-hooks', '-f']
if self._cq_dry_run:
upload_cmd.append('--cq-dry-run')
else:
upload_cmd.append('--use-commit-queue')
if self._cq_extra_trybots:
commit_msg += ('\n' + CQ_INCLUDE_TRYBOTS +
','.join(self._cq_extra_trybots))
tbr = '\nTBR='
emails = self._emails_to_cc_on_rolls()
if emails:
emails_str = ','.join(emails)
tbr += emails_str
upload_cmd.extend(['--cc', emails_str, '--send-mail'])
commit_msg += tbr
if self._include_commit_log:
log_cmd = ['git', 'log', '--format=%h %ae %s',
'%s..%s' % (last_roll_revision, new_roll_revision)]
git_log = subprocess2.check_output(log_cmd, cwd=self._project_git_dir)
commit_msg += '\n\nCommits in this roll:\n' + git_log.decode('utf-8')
upload_cmd.extend(['-m', commit_msg])
subprocess2.check_call(upload_cmd, **cwd_kwargs)
finally:
subprocess2.check_call(['git', 'checkout', 'origin/master', '-f'],
**cwd_kwargs)
subprocess2.check_call(
['git', 'branch', '-D', roll_branch], **cwd_kwargs)
# FIXME: It's easier to pull the issue id from rietveld rather than
# parse it from the safely-roll-deps output. Once we inline
# safely-roll-deps into this script this can go away.
search_result = self._search_for_active_roll()
if search_result:
self._rietveld.add_comment(search_result['issue'],
self.ROLL_BOT_INSTRUCTIONS)
示例9: main
def main():
tool_dir = os.path.dirname(os.path.abspath(__file__))
parser = optparse.OptionParser(usage='<new webkit rev>')
parser.add_option('-v', '--verbose', action='count', default=0)
parser.add_option('--commit', action='store_true', default=True,
help='(default) Put change in commit queue on upload.')
parser.add_option('--no-commit', action='store_false', dest='commit',
help='Don\'t put change in commit queue on upload.')
parser.add_option('-r', '--reviewers', default='',
help='Add given users as either reviewers or TBR as'
' appropriate.')
parser.add_option('--upstream', default='origin/master',
help='(default "%default") Use given start point for change'
' to upload. For instance, if you use the old git workflow,'
' you might set it to "origin/trunk".')
parser.add_option('--cc', help='CC email addresses for issue.')
options, args = parser.parse_args()
logging.basicConfig(
level=
[logging.WARNING, logging.INFO, logging.DEBUG][
min(2, options.verbose)])
if len(args) != 1:
parser.error('Need only one arg: new webkit revision to roll to.')
root_dir = os.path.dirname(tool_dir)
os.chdir(root_dir)
new_rev = int(args[0])
print 'Roll webkit revision to %s' % new_rev
# Silence the editor.
os.environ['EDITOR'] = 'true'
old_branch = scm.GIT.GetBranch(root_dir)
if old_branch == 'webkit_roll':
parser.error(
'Please delete the branch webkit_roll and move to a different branch')
subprocess2.check_output(
['git', 'checkout', '-b', 'webkit_roll', options.upstream])
try:
old_rev = process_deps(os.path.join(root_dir, 'DEPS'), new_rev)
review_field = 'TBR' if options.commit else 'R'
commit_msg = 'Webkit roll %s:%s\n\n%s=%s\n' % (old_rev, new_rev,
review_field,
options.reviewers)
subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS'])
subprocess2.check_call(['git', 'diff', options.upstream])
upload_cmd = ['git', 'cl', 'upload']
if options.commit:
upload_cmd.append('--use-commit-queue')
if options.reviewers:
upload_cmd.append('--send-mail')
if options.cc:
upload_cmd.extend(['--cc', options.cc])
subprocess2.check_call(upload_cmd)
finally:
subprocess2.check_output(['git', 'checkout', old_branch])
subprocess2.check_output(['git', 'branch', '-D', 'webkit_roll'])
return 0
示例10: main
def main():
tool_dir = os.path.dirname(os.path.abspath(__file__))
parser = optparse.OptionParser(usage="<new webkit rev>")
parser.add_option("-v", "--verbose", action="count", default=0)
options, args = parser.parse_args()
logging.basicConfig(level=[logging.WARNING, logging.INFO, logging.DEBUG][min(2, options.verbose)])
if len(args) != 1:
parser.error("Need only one arg: new webkit revision to roll to.")
root_dir = os.path.dirname(tool_dir)
os.chdir(root_dir)
new_rev = int(args[0])
print "Roll webkit revision to %s" % new_rev
# Silence the editor.
os.environ["EDITOR"] = "true"
old_branch = scm.GIT.GetBranch(root_dir)
if old_branch == "webkit_roll":
parser.error("Please delete the branch webkit_roll and move to a different branch")
subprocess2.check_output(["git", "checkout", "-b", "webkit_roll", "origin/master"])
try:
old_rev = process_deps(os.path.join(root_dir, "DEPS"), new_rev)
commit_msg = "Webkit roll %s:%s\n\nTBR=\n" % (old_rev, new_rev)
subprocess2.check_output(["git", "commit", "-m", commit_msg, "DEPS"])
subprocess2.check_call(["git", "diff", "origin/master"])
subprocess2.check_call(["git", "cl", "upload", "--use-commit-queue"])
finally:
subprocess2.check_output(["git", "checkout", old_branch])
subprocess2.check_output(["git", "branch", "-D", "webkit_roll"])
return 0
示例11: _current_revision
def _current_revision(self):
git_dir = self._path_from_chromium_root(self._path_to_project, '.git')
subprocess2.check_call(['git', '--git-dir', git_dir, 'fetch'])
git_show_cmd = ['git', '--git-dir', git_dir, 'show', '-s',
'origin/master']
git_log = subprocess2.check_output(git_show_cmd)
match = re.search('^\s*git-svn-id:.*@(?P<svn_revision>\d+)\ ',
git_log, re.MULTILINE)
if match:
return int(match.group('svn_revision'))
else:
# If it's not git-svn, fall back on git.
git_revparse_cmd = ['git', '--git-dir', git_dir, 'rev-parse',
'origin/master']
return subprocess2.check_output(git_revparse_cmd).rstrip()
示例12: apply_patch
def apply_patch(self, patches):
"""Ignores svn properties."""
for p in patches:
try:
stdout = ''
filename = os.path.join(self.project_path, p.filename)
if p.is_delete:
os.remove(filename)
else:
dirname = os.path.dirname(p.filename)
full_dir = os.path.join(self.project_path, dirname)
if dirname and not os.path.isdir(full_dir):
os.makedirs(full_dir)
filepath = os.path.join(self.project_path, p.filename)
if p.is_binary:
with open(filepath, 'wb') as f:
f.write(p.get())
else:
if p.diff_hunks:
stdout = subprocess2.check_output(
['patch', '-p%s' % p.patchlevel],
stdin=p.get(),
stderr=subprocess2.STDOUT,
cwd=self.project_path)
elif p.is_new and not os.path.exists(filepath):
# There is only a header. Just create the file.
open(filepath, 'w').close()
for post in (self.post_processors or []):
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
except subprocess.CalledProcessError, e:
raise PatchApplicationFailed(
p.filename, '%s%s' % (stdout, getattr(e, 'stdout', None)))
示例13: _log
def _log(self):
# Don't use the local checkout in case of caching incorrency.
out = subprocess2.check_output(
['svn', 'log', self.svn_url,
'--non-interactive', '--no-auth-cache',
'--username', self.usr, '--password', self.pwd,
'--with-all-revprops', '--xml',
'--limit', '1'])
logentry = ElementTree.XML(out).find('logentry')
if logentry == None:
return {'revision': 0}
data = {
'revision': int(logentry.attrib['revision']),
}
def set_item(name):
item = logentry.find(name)
if item != None:
data[name] = item.text
set_item('author')
set_item('msg')
revprops = logentry.find('revprops')
if revprops != None:
data['revprops'] = []
for prop in revprops.getiterator('property'):
data['revprops'].append((prop.attrib['name'], prop.text))
return data
示例14: get_dllexports
def get_dllexports(dll):
""" Get exports of DLL. """
dll2def = os.path.join(env.bin_dir, 'dll2def.exe')
if not os.path.isfile(dll2def):
build_script = os.path.join(env.src_dir, 'dll2def', 'build.bat')
try:
subproc.check_call([ build_script ], stderr=subproc.VOID, stdout=subproc.VOID, stdin=subproc.VOID)
except subproc.CalledProcessError:
import traceback
traceback.print_exc()
fatal_message(
'Failed to build dll2def',
''.join((
'There was an error while trying to build dll2def. To resolve this issue, you ',
'may want to check the following files to make sure they are correct:\n\n',
' /repository/util/src/dll2def/build.bat\n'
' /repository/util/bin/msvcc.bat\n'
' /repository/util/bin/_buildenv.bat\n\n'
'If you continue having issue, please report this error at this project\'s GitHub. ',
'(https://github.com/Juntalis/dypywin32)'
))
)
return split_lines_clean(subproc.check_output(
[ dll2def, env.data_file(dll) ], stderr=subproc.VOID
))
示例15: getRevisionLog
def getRevisionLog(url, revision):
"""Takes an svn url and gets the associated revision."""
svn_log = subprocess2.check_output(
['svn', 'log', url, '-r', str(revision)],
universal_newlines=True).splitlines(True)
# Don't include the header lines and the trailing "---..." line.
return ''.join(svn_log[3:-1])