本文整理汇总了Python中executil.getoutput函数的典型用法代码示例。如果您正苦于以下问题:Python getoutput函数的具体用法?Python getoutput怎么用?Python getoutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getoutput函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_version
def get_version(cls):
"""Gets version of program -> version
Looks for version in the following places (by order):
1) <INSTALL_PATH>/version.txt (if it exists)
2) debian/changelog (if it exists - parsed with dpkg-parsechangelog)
3) `autoversion HEAD`
"""
version_file = join(cls.INSTALL_PATH, "version.txt")
if lexists(version_file):
return file(version_file).readline().strip()
orig_cwd = os.getcwd()
if cls.INSTALL_PATH:
os.chdir(cls.INSTALL_PATH)
try:
if not exists("debian/changelog"):
output = getoutput("autoversion HEAD")
version = output
else:
output = getoutput("dpkg-parsechangelog")
version = [ line.split(" ")[1]
for line in output.split("\n")
if line.startswith("Version:") ][0]
except ExecError:
os.chdir(orig_cwd)
return "?"
os.chdir(orig_cwd)
return version
示例2: apply_overlay
def apply_overlay(src, dst, olist_path):
orig_cwd = os.getcwd()
os.chdir(src)
executil.getoutput("tar --create --files-from=%s | tar --extract --directory %s" %
(olist_path, executil.mkarg(dst)))
os.chdir(orig_cwd)
示例3: refresh
def refresh(self):
self.uri_release.download()
self.uri_release_gpg.download()
executil.getoutput("gpgv", "--keyring", self.chanko.trustedkeys,
self.uri_release_gpg.path, self.uri_release.path)
release_content = file(self.uri_release.path).read()
for uri_index in self.uri_indexes:
# skip download if latest
if self._index_in_release(uri_index.path, release_content):
continue
# attempt download of Packages.bz2, fallback to Packages.gz
try:
uri_index.download()
except executil.ExecError, e:
if uri_index.filename == "Packages.bz2" and not e.exitcode == 22:
raise e
print "* info: Packages.bz2 not available, falling back to gzip..."
uri_index.url = uri_index.url.replace("bz2", "gz")
uri_index.download()
# verify integrity, delete on failure
if not self._index_in_release(uri_index.path, release_content):
os.remove(uri_index.path)
raise Error("verification failed: ", uri_index.path)
示例4: __init__
def __init__(self):
TempFile.__init__(self, prefix='key_')
os.remove(self.path)
executil.getoutput("ssh-keygen -N '' -f %s" % self.path)
os.remove(self.path + ".pub")
PrivateKey.__init__(self, self.path)
示例5: _is_alive
def _is_alive(self):
try:
getoutput("/etc/init.d/postgresql", "status")
except ExecError, e:
if e.exitcode == 3: # ie. stopped
return False
else:
raise Error("Unknown postgresql status exitcode: %s" % e.exitcode)
示例6: _is_signed
def _is_signed(fpath, keyring):
fpath_sig = fpath + ".sig"
if not exists(fpath_sig):
return False
try:
executil.getoutput("gpg --keyring=%s --verify" % keyring, fpath_sig)
return True
except:
return False
示例7: start
def start(cls):
if cls.is_running():
return
retries = 2
for i in range(retries):
try:
executil.getoutput(cls.INIT_SCRIPT, "start")
return
except executil.ExecError, e:
pass
示例8: get_version
def get_version():
try:
if not exists("debian/changelog"):
return getoutput("autoversion HEAD")
output = getoutput("dpkg-parsechangelog")
version = [ line.split(" ")[1]
for line in output.split("\n")
if line.startswith("Version:") ][0]
return version
except ExecError:
return None
示例9: termcap_get_lines
def termcap_get_lines():
buf = executil.getoutput("resize")
m = re.search('LINES=(\d+)', buf)
if not m:
raise Error("can't parse `resize` output")
return int(m.group(1))
示例10: usage
def usage(self):
if self.advanced_enabled:
default_button_label = "Advanced Menu"
default_return_value = "advanced"
else:
default_button_label = "Quit"
default_return_value = "quit"
#if no interfaces at all - display error and go to advanced
if len(self._get_filtered_ifnames()) == 0:
error = "No network adapters detected"
if not self.advanced_enabled:
fatal(error)
self.console.msgbox("Error", error)
return "advanced"
#if interfaces but no default - display error and go to networking
ifname = self._get_default_nic()
if not ifname:
error = "Networking is not yet configured"
if not self.advanced_enabled:
fatal(error)
self.console.msgbox("Error", error)
return "networking"
#tklbam integration
try:
tklbam_status = executil.getoutput("tklbam-status --short")
except executil.ExecError, e:
if e.exitcode in (10, 11): #not initialized, no backups
tklbam_status = e.output
else:
tklbam_status = ''
示例11: _get_public_ipaddr
def _get_public_ipaddr(cls):
publicip_cmd = conf.Conf().publicip_cmd
if publicip_cmd:
try:
return executil.getoutput(publicip_cmd)
except executil.ExecError, e:
pass
示例12: _read_partition_table
def _read_partition_table(path):
partitions = []
for line in executil.getoutput("fdisk -l %s" % path).splitlines():
if line.startswith(path):
partitions.append(Partition(line))
return partitions
示例13: _cmdcache
def _cmdcache(self, arg, sort=False):
results = executil.getoutput("apt-cache %s %s" % (self.options, arg))
if sort:
results = results.splitlines()
results.sort()
results = "\n".join(results)
return results
示例14: fmt_welcome
def fmt_welcome():
welcome = "Welcome to %s" % socket.gethostname()
kernel = executil.getoutput("uname -mr")
sysversion = fmt_sysversion()
if sysversion:
welcome += ", " + sysversion + " (" + kernel + ")"
return welcome
示例15: list_databases
def list_databases():
for line in getoutput(su('psql -l')).splitlines():
m = re.match(r'^ (\S+?)\s', line)
if not m:
continue
name = m.group(1)
yield name