本文整理汇总了Python中subprocess.process函数的典型用法代码示例。如果您正苦于以下问题:Python process函数的具体用法?Python process怎么用?Python process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了process函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(*command, **kwargs):
kwargs.update(universal_newlines=True)
proc = process(command, **kwargs)
_, _ = proc.communicate()
code = proc.returncode
if not code: return code
sys.exit(code)
示例2: run
def run(self):
try:
batch = process([configuration.executables.GIT, 'cat-file', '--batch'], stdin=PIPE, stdout=PIPE, stderr=STDOUT, cwd=self.repository.path)
stdout, stderr = batch.communicate("\n".join(self.sha1s.keys()) + "\n")
gitobjects = []
for sha1, commit_id in self.sha1s.items():
line, stdout = stdout.split("\n", 1)
try: object_sha1, object_type, object_size = line.split(" ")
except: raise Exception, "unexpected header line: %r" % line
assert object_sha1 == sha1, "%s != %s (%s)" % (object_sha1, sha1)
assert object_type == "commit"
object_size = int(object_size)
object_data = stdout[:object_size]
stdout = stdout[object_size + 1:]
gitobjects.append((GitObject(object_sha1, object_type, object_size, object_data), commit_id))
self.gitobjects = gitobjects
except:
self.error = format_exc()
示例3: check_input
def check_input(args, stdin, **kwargs):
assert isinstance(stdin, str)
child = process(args, stdin=PIPE, **kwargs)
stdout, stderr = child.communicate(stdin)
if child.returncode != 0:
raise CalledProcessError(child.returncode, args, None)
示例4: lstree
def lstree(remote, regexp=None):
if regexp: name_check = lambda item: bool(regexp.match(item[1]))
else: name_check = lambda item: True
git = process([configuration.executables.GIT, 'ls-remote', remote], stdout=PIPE, stderr=PIPE, cwd="/tmp")
stdout, stderr = git.communicate()
if git.returncode == 0: return filter(name_check, (line.split() for line in stdout.splitlines()))
else: raise Exception, "'git ls-remote' failed: %s" % stderr.strip()
示例5: lint
def lint(code, comment):
# write input code to tmp file
fp = temp_file.format(tmp=temp_dir)
with open(fp, "w") as fh:
fh.write(code)
fh.close()
# lint it
out, err = process(["pep8", "--count", abspath(fp)],
stdout=PIPE,
stderr=STDOUT).communicate()
if out == b'':
comment("Good adherence to PEP8")
return 1
else:
comment(out)
return 1 - len(str(out).split("\n")) / len(code.split("\n"))
示例6: mergebase
def mergebase(self, commit_or_commits, db=None):
if db and isinstance(commit_or_commits, Commit):
cursor = db.cursor()
cursor.execute("SELECT mergebase FROM mergebases WHERE commit=%s", (commit_or_commits.getId(db),))
try:
return cursor.fetchone()[0]
except:
result = self.mergebase(commit_or_commits)
cursor.execute("INSERT INTO mergebases (commit, mergebase) VALUES (%s, %s)", (commit_or_commits.getId(db), result))
return result
try: sha1s = commit_or_commits.parents
except: sha1s = map(str, commit_or_commits)
assert len(sha1s) >= 2
git = process([configuration.executables.GIT, 'merge-base'] + sha1s,
stdout=PIPE, stderr=PIPE, cwd=self.path)
stdout, stderr = git.communicate()
if git.returncode == 0: return stdout.strip()
else: raise Exception, "'git merge-base' failed: %s" % stderr.strip()
示例7: runCustom
def runCustom(self, cwd, command, *arguments, **kwargs):
argv = [configuration.executables.GIT, command]
argv.extend(arguments)
stdin_data = kwargs.get("input")
if stdin_data is None: stdin = None
else: stdin = PIPE
env = {}
env.update(environ)
env.update(kwargs.get("env", {}))
if "GIT_DIR" in env: del env["GIT_DIR"]
git = process(argv, stdin=stdin, stdout=PIPE, stderr=PIPE, cwd=cwd, env=env)
stdout, stderr = git.communicate(stdin_data)
if kwargs.get("check_errors", True):
if git.returncode == 0:
if kwargs.get("include_stderr", False):
return stdout + stderr
else:
return stdout
else: raise Exception, "'%s' failed: %s (in %s)" % (" ".join(argv), stderr.strip(), cwd)
else:
return git.returncode, stdout, stderr
示例8: readObject
def readObject(repository_path, object_type, object_sha1):
git = process([configuration.executables.GIT, 'cat-file', object_type, object_sha1], stdout=PIPE, stderr=PIPE, cwd=repository_path)
stdout, stderr = git.communicate()
if git.returncode == 0: return stdout
else: raise Exception, "'git cat-file' failed: %s" % stderr.strip()
示例9: iscommit
def iscommit(self, name):
git = process([configuration.executables.GIT, 'cat-file', '-t', name],
stdout=PIPE, stderr=PIPE, cwd=self.path)
stdout, stderr = git.communicate()
if git.returncode == 0: return stdout.strip() == "commit"
else: return False
示例10: revparse
def revparse(self, name):
git = process([configuration.executables.GIT, 'rev-parse', '--verify', '--quiet', name],
stdout=PIPE, stderr=PIPE, cwd=self.path)
stdout, stderr = git.communicate()
if git.returncode == 0: return stdout.strip()
else: raise Exception, "'git rev-parse' failed: %s" % stderr.strip()
示例11: branch
def branch(self, name, startpoint):
git = process([configuration.executables.GIT, 'branch', name, startpoint],
stdout=PIPE, stderr=PIPE, cwd=self.path)
stdout, stderr = git.communicate()
if git.returncode != 0: raise Exception, stderr
示例12: __startBatchCheck
def __startBatchCheck(self):
if self.__batchCheck is None:
self.__batchCheck = process([configuration.executables.GIT, 'cat-file', '--batch-check'],
stdin=PIPE, stdout=PIPE, stderr=STDOUT, cwd=self.path)
示例13: __compact
def __compact(self):
import syntaxhighlight
cache_dir = configuration.services.HIGHLIGHT["cache_dir"]
if not os.path.isdir(cache_dir):
# Newly installed system that hasn't highlighted anything.
return 0, 0, 0, 0
self.info("cache compacting started")
now = time.time()
max_age_uncompressed = 7 * 24 * 60 * 60
max_age_compressed = 90 * 24 * 60 * 60
uncompressed_count = 0
compressed_count = 0
purged_paths = []
db = dbutils.Database.forSystem()
cursor = db.cursor()
cursor.execute("CREATE TEMPORARY TABLE purged (sha1 CHAR(40) PRIMARY KEY)")
cursor.execute("INSERT INTO purged (sha1) SELECT DISTINCT sha1 FROM codecontexts")
for section in sorted(os.listdir(cache_dir)):
if len(section) == 2:
for filename in os.listdir("%s/%s" % (cache_dir, section)):
fullname = "%s/%s/%s" % (cache_dir, section, filename)
age = now - os.stat(fullname).st_mtime
parts = filename.split(".")
if len(parts) < 2 \
or len(parts[0]) != 38 \
or parts[1] not in syntaxhighlight.LANGUAGES:
os.unlink(fullname)
continue
sha1 = section + parts[0]
if parts[-1] == "bz2":
if age > max_age_compressed:
self.debug("purging: %s/%s" % (section, filename))
purged_paths.append(fullname)
else:
cursor.execute("DELETE FROM purged WHERE sha1=%s", (sha1,))
compressed_count += 1
elif parts[-1] == "ctx":
self.debug("deleting context file: %s/%s" % (section, filename))
os.unlink(fullname)
else:
cursor.execute("DELETE FROM purged WHERE sha1=%s", (sha1,))
if age > max_age_uncompressed:
self.debug("compressing: %s/%s" % (section, filename))
worker = process(["/bin/bzip2", fullname])
worker.wait()
compressed_count += 1
else:
uncompressed_count += 1
self.info("cache compacting finished: uncompressed=%d / compressed=%d / purged=%d"
% (uncompressed_count, compressed_count, len(purged_paths)))
if purged_paths:
for path in purged_paths: os.unlink(path)
cursor.execute("SELECT COUNT(*) FROM purged")
purged_contexts = cursor.fetchone()[0]
cursor.execute("""DELETE
FROM codecontexts
WHERE sha1 IN (SELECT sha1
FROM purged)""")
db.commit()
db.close()
return uncompressed_count, compressed_count, len(purged_paths), purged_contexts
示例14: __compact
def __compact(self):
import syntaxhighlight
now = time.time()
max_age_uncompressed = 7 * 24 * 60 * 60
max_age_compressed = 90 * 24 * 60 * 60
uncompressed_count = 0
compressed_count = 0
purged_paths = []
db = dbutils.Database()
cursor = db.cursor()
cursor.execute("CREATE TEMPORARY TABLE purged (sha1 CHAR(40) PRIMARY KEY)")
cache_path = configuration.services.HIGHLIGHT["cache_dir"]
for section in sorted(os.listdir(cache_path)):
if len(section) == 2:
for filename in os.listdir("%s/%s" % (cache_path, section)):
fullname = "%s/%s/%s" % (cache_path, section, filename)
age = now - os.stat(fullname).st_mtime
if len(filename) > 38 and filename[38] == "." and filename[39:] in syntaxhighlight.LANGUAGES:
if age > max_age_uncompressed:
self.debug("compressing: %s/%s" % (section, filename))
worker = process(["/bin/bzip2", fullname])
worker.wait()
compressed_count += 1
else:
uncompressed_count += 1
elif (
len(filename) > 42
and filename[38] == "."
and filename[-4] == "."
and filename[39:-4] in syntaxhighlight.LANGUAGES
):
if filename.endswith(".bz2"):
if age > max_age_compressed:
self.debug("purging: %s/%s" % (section, filename))
cursor.execute("INSERT INTO purged (sha1) VALUES (%s)", (section + filename[:-4],))
purged_paths.append(fullname)
else:
compressed_count += 1
elif filename.endswith(".ctx"):
self.debug("deleting context file: %s/%s" % (section, filename))
os.unlink(fullname)
self.debug(
"uncompressed=%d / compressed=%d / purged=%d"
% (uncompressed_count, compressed_count, len(purged_paths))
)
if purged_paths:
for path in purged_paths:
os.unlink(path)
cursor.execute("DELETE FROM codecontexts USING purged WHERE codecontexts.sha1=purged.sha1")
db.commit()
db.close()