本文整理汇总了Python中executil.system函数的典型用法代码示例。如果您正苦于以下问题:Python system函数的具体用法?Python system怎么用?Python system使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了system函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parun
def parun(commands, minheight=DEFAULT_MINHEIGHT, daemon=False, session_name=None):
if (termcap_get_lines() - len(commands)) / len(commands) >= minheight:
split = True
else:
split = False
stdin = None
if not os.isatty(sys.stdin.fileno()):
stdin = TempFile()
stdin.write(sys.stdin.read())
stdin.close()
# screen wants stdin to be connected to a tty
os.dup2(sys.stderr.fileno(), sys.stdin.fileno())
screens = fmt_screens(commands, stdin)
if split:
screenrc = "split\nfocus\n".join([ screen + "\n" for screen in screens ])
else:
screenrc = "\n".join(screens) + "\n" + "windowlist -b" + "\n"
screenrc_tmp = TempFile()
screenrc_tmp.write(screenrc)
screenrc_tmp.close()
args = ["-c", screenrc_tmp.path]
if daemon:
args += [ "-dm" ]
if session_name:
args += [ "-S", session_name ]
executil.system("screen", *args)
if daemon:
time.sleep(1)
示例2: get
def get(url, dest):
"""Get file from <url> and save it to <dest>.
Tries to retrieve <url> from cache, otherwise stores it in
cache following retrieval.
"""
url = urllib.unquote(url)
if url.endswith("/"):
raise Error("illegal url - can't get a directory")
if os.path.isdir(dest):
dest = os.path.join(dest, os.path.basename(url))
else:
if dest.endswith("/"):
raise Error("no such directory: " + dest)
if os.path.lexists(dest):
raise Error("won't overwrite already existing file: " + dest)
cache = Cache()
cached_path = cache.retrieve(url, dest)
if cached_path:
print "* get: retrieved file from cache"
else:
print "* get: retrieving file from network..."
system("curl -L -f %s -o %s" % (mkarg(url), mkarg(dest)))
cached_path = cache.store(url, dest)
return cached_path
示例3: _amitools_cmd
def _amitools_cmd(command, opts):
amitools_path = _get_amitools_path()
os.environ["EC2_AMITOOL_HOME"] = amitools_path
log.debug("amitools_cmd - %s %s", command, opts)
cmd = os.path.join(amitools_path, 'bin', command)
executil.system(cmd, *opts)
示例4: cpp
def cpp(input, cpp_opts=[]):
"""preprocess <input> through cpp -> preprocessed output
input may be path/to/file or iterable data type
"""
args = [ "-Ulinux" ]
for opt, val in cpp_opts:
args.append(opt + val)
include_path = os.environ.get('FAB_PLAN_INCLUDE_PATH')
if include_path:
for path in include_path.split(':'):
args.append("-I" + path)
command = ["cpp", input]
if args:
command += args
trap = stdtrap.StdTrap()
try:
executil.system(*command)
except ExecError, e:
trap.close()
trapped_stderr = trap.stderr.read()
raise ExecError(" ".join(command), e.exitcode, trapped_stderr)
示例5: index
def index(self, component, arch):
component_dir = join(self.pool, component)
if not exists(join(self.path, component_dir)):
raise Error('component does not exist', join(self.path, component_dir))
output_dir = '%s/dists/%s/%s/binary-%s' % (self.path, self.release,
component, arch)
if not exists(output_dir):
os.makedirs(output_dir)
output = self._archive_cmd('--arch=%s packages' % arch, component_dir)
fh = file(join(output_dir, 'Packages'), "w")
fh.write(output)
if output:
# append newline if packages were in pool
print >> fh
fh.close()
executil.system("gzip -c %s > %s" % (join(output_dir, 'Packages'),
join(output_dir, 'Packages.gz')))
executil.system("bzip2 -c %s > %s" % (join(output_dir, 'Packages'),
join(output_dir, 'Packages.bz2')))
fh = file(join(output_dir, 'Release'), "w")
print >> fh, "Origin: %s" % self.origin
print >> fh, "Label: %s" % self.origin
print >> fh, "Archive: %s" % self.release
print >> fh, "Version: %s" % self.version
print >> fh, "Component: %s" % component
print >> fh, "Architecture: %s" % arch
fh.close()
示例6: run
def run(self, passphrase, creds=None, debug=False):
sys.stdout.flush()
if creds:
os.environ['AWS_ACCESS_KEY_ID'] = creds.accesskey
os.environ['AWS_SECRET_ACCESS_KEY'] = creds.secretkey
os.environ['X_AMZ_SECURITY_TOKEN'] = ",".join([creds.producttoken, creds.usertoken])
if PATH_DEPS_BIN not in os.environ['PATH'].split(':'):
os.environ['PATH'] = PATH_DEPS_BIN + ':' + os.environ['PATH']
if PATH_DEPS_PYLIB:
os.environ['PYTHONPATH'] = PATH_DEPS_PYLIB
os.environ['PASSPHRASE'] = passphrase
if debug:
import executil
shell = os.environ.get("SHELL", "/bin/bash")
if shell == "/bin/bash":
shell += " --norc"
executil.system(shell)
child = Popen(self.command)
del os.environ['PASSPHRASE']
exitcode = child.wait()
if exitcode != 0:
raise Error("non-zero exitcode (%d) from backup command: %s" % (exitcode, str(self)))
示例7: _is_alive
def _is_alive(self):
try:
system('mysqladmin -s ping >/dev/null 2>&1')
except ExecError:
return False
return True
示例8: ebsmount_add
def ebsmount_add(devname, mountdir):
"""ebs device attached"""
matching_devices = []
for device in udevdb.query():
if device.name.startswith(basename(devname)):
matching_devices.append(device)
for device in matching_devices:
devpath = join('/dev', device.name)
mountpath = join(mountdir, device.env.get('ID_FS_UUID', devpath[-1])[:4])
mountoptions = ",".join(config.mountoptions.split())
scriptpath = join(mountpath, ".ebsmount")
filesystem = device.env.get('ID_FS_TYPE', None)
if not filesystem:
log(devname, "could not identify filesystem: %s" % devpath)
continue
if not filesystem in config.filesystems.split():
log(devname, "filesystem (%s) not supported: %s" % (filesystem,devpath))
continue
if is_mounted(devpath):
log(devname, "already mounted: %s" % devpath)
continue
mount(devpath, mountpath, mountoptions)
log(devname, "mounted %s %s (%s)" % (devpath, mountpath, mountoptions))
if exists(scriptpath):
cmd = "run-parts --verbose --exit-on-error %s" % scriptpath
cmd += " 2>&1 | tee -a %s" % config.logfile
system(cmd)
示例9: update
def update(section, name, value):
config_path = "/var/www/piwik/config/config.ini.php"
if not os.path.exists(config_path):
raise Error("config file does not exist: %s" % config_path)
config_new = []
in_section = False
seen = False
for line in file(config_path).readlines():
line = line.rstrip()
if line.startswith("["):
if line == section:
in_section = True
else:
in_section = False
if in_section and line.startswith("%s =" % name) and seen == False:
line = "%s = \"%s\"" % (name, value)
seen = True
config_new.append(line)
# write out updated config
file(config_path, "w").write("\n".join(config_new) + "\n")
# set ownership and permissions
system("chown www-data:www-data %s" % config_path)
system("chmod 640 %s" % config_path)
示例10: _checkout
def _checkout(self, arg):
orig_cwd = os.getcwd()
os.chdir(self.git.path)
try:
system("sumo-checkout", arg)
finally:
os.chdir(orig_cwd)
示例11: umount
def umount(self):
if self.mounted_devpts_myself:
executil.system("umount", self.paths.dev.pts)
self.mounted_devpts_myself = False
if self.mounted_proc_myself:
executil.system("umount", self.paths.proc)
self.mounted_proc_myself = False
示例12: mount
def mount(self):
if not self._is_mounted(self.paths.proc):
executil.system("mount -t proc", "proc-chroot", self.paths.proc)
self.mounted_proc_myself = True
if not self._is_mounted(self.paths.dev.pts):
executil.system("mount -t devpts", "devpts-chroot", self.paths.dev.pts)
self.mounted_devpts_myself = True
示例13: __init__
def __init__(self):
system("mkdir -p /var/run/mysqld")
system("chown mysql:root /var/run/mysqld")
self.selfstarted = False
if not self._is_alive():
self._start()
self.selfstarted = True
示例14: _start
def _start(self):
system("mysqld --skip-networking >/dev/null 2>&1 &")
for i in range(6):
if self._is_alive():
return
time.sleep(1)
raise Error("could not start mysqld")
示例15: _system
def _system(self, command, *args):
os.setuid(self.euid)
try:
try:
system(command, *args)
except ExecError, e:
raise Error(e)
finally:
os.setreuid(self.uid, self.euid)