本文整理汇总了Python中sub_process.call函数的典型用法代码示例。如果您正苦于以下问题:Python call函数的具体用法?Python call怎么用?Python call使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_triggers
def run_triggers(ref, globber):
"""
Runs all the trigger scripts in a given directory.
ref can be a certmaster object, if not None, the name will be passed
to the script. If ref is None, the script will be called with
no argumenets. Globber is a wildcard expression indicating which
triggers to run. Example: "/var/lib/certmaster/triggers/blah/*"
"""
log = logger.Logger().logger
triggers = glob.glob(globber)
triggers.sort()
for file in triggers:
log.debug("Executing trigger: %s" % file)
try:
if file.find(".rpm") != -1:
# skip .rpmnew files that may have been installed
# in the triggers directory
continue
if ref:
rc = sub_process.call([file, ref], shell=False)
else:
rc = sub_process.call([file], shell=False)
except:
log.warning("Warning: failed to execute trigger: %s" % file)
continue
if rc != 0:
raise codes.CMException, "certmaster trigger failed: %(file)s returns %(code)d" % { "file" : file, "code" : rc }
示例2: autostart
def autostart(self, vm):
self.conn = self.__get_conn()
if self.conn.get_type() == "Xen":
autostart_args = [
"/bin/ln",
"-s",
"/etc/xen/%s" % vm,
"/etc/xen/auto"
]
else:
# When using KVM, we need to make sure the autostart
# directory exists
mkdir_args = [
"/bin/mkdir",
"-p",
"/etc/libvirt/qemu/autostart"
]
sub_process.call(mkdir_args,shell=False,close_fds=True)
# We aren't using virsh autostart because we want
# the command to work even when the VM isn't running
autostart_args = [
"/bin/ln",
"-s",
"/etc/libvirt/qemu/%s.xml" % vm,
"/etc/libvirt/qemu/autostart/%s.xml" % vm
]
return sub_process.call(autostart_args,shell=False,close_fds=True)
示例3: __init__
def __init__(self, logfile="/var/log/cobbler/cobbler.log"):
# Main logfile is append mode, other logfiles not.
if not os.path.exists(logfile):
self.logfile = open(logfile, "a")
sub_process.call("chown apache %s" % logfile, shell=True)
self.logfile.close()
if logfile.find("tasks") != -1:
self.logfile = open(logfile, "w+")
else:
self.logfile = open(logfile, "a")
示例4: createrepo_walker
def createrepo_walker(self, repo, dirname, fnames):
"""
Used to run createrepo on a copied Yum mirror.
"""
if os.path.exists(dirname) or repo['breed'] == 'rsync':
utils.remove_yum_olddata(dirname)
try:
cmd = "createrepo %s %s" % (repo.createrepo_flags, dirname)
print _("- %s") % cmd
sub_process.call(cmd, shell=True, close_fds=True)
except:
print _("- createrepo failed. Is it installed?")
del fnames[:] # we're in the right place
示例5: scp_it
def scp_it(self,from_path,to_path):
from_path = "%s:%s" % (self.host, from_path)
cmd = "scp %s %s" % (from_path, to_path)
print _("- %s") % cmd
rc = sub_process.call(cmd, shell=True, close_fds=True)
if rc !=0:
raise CX(_("scp failed"))
示例6: __command
def __command(self, service_name, command):
filename = os.path.join("/etc/rc.d/init.d/",service_name)
if os.path.exists(filename):
return sub_process.call(["/sbin/service", service_name, command])
else:
raise codes.FuncException("Service not installed: %s" % service_name)
示例7: deploy
def deploy(api, system, virt_host=None, virt_group=None):
"""
Deploy the current system to the virtual host or virtual group
"""
if virt_host is None and virt_group is not None:
virt_host = __find_host(api, virt_group)
if virt_host is None and system.virt_group == "":
virt_host = __find_host(api, system.virt_group)
if system.virt_host != "":
virt_host = system.virt_host
if virt_host is None:
raise CX("No host specified for deployment.")
virt_host = api.find_system(virt_host)
if virt_host is None:
raise CX("Unable to find cobbler system record for virt-host (%s)" % virt_host)
if virt_host.hostname == "":
raise CX("Hostname for cobbler system (%s) not set" % virt_host.name)
me = api.settings().server
cmd = ["/usr/bin/ssh", virt_host.hostname, "koan", "--server", me, "--virt", "--system", system.name]
print "- %s" % " ".join(cmd)
rc = sub_process.call(cmd, shell=False)
if rc != 0:
raise CX("remote deployment failed")
return virt_host.name
示例8: rsync_sync
def rsync_sync(self, repo):
"""
Handle copying of rsync:// and rsync-over-ssh repos.
"""
repo_mirror = repo.mirror
if not repo.mirror_locally:
raise CX(_("rsync:// urls must be mirrored locally, yum cannot access them directly"))
if repo.rpm_list != "":
print _("- warning: --rpm-list is not supported for rsync'd repositories")
# FIXME: don't hardcode
dest_path = os.path.join("/var/www/cobbler/repo_mirror", repo.name)
spacer = ""
if not repo.mirror.startswith("rsync://") and not repo.mirror.startswith("/"):
spacer = "-e ssh"
if not repo.mirror.endswith("/"):
repo.mirror = "%s/" % repo.mirror
cmd = "rsync -rltDv %s --delete --delete-excluded --exclude-from=/etc/cobbler/rsync.exclude %s %s" % (spacer, repo.mirror, dest_path)
print _("- %s") % cmd
rc = sub_process.call(cmd, shell=True, close_fds=True)
if rc !=0:
raise CX(_("cobbler reposync failed"))
print _("- walking: %s") % dest_path
os.path.walk(dest_path, self.createrepo_walker, repo)
self.create_local_file(dest_path, repo)
示例9: __init__
def __init__(self, logfile="/var/log/cobbler/cobbler.log"):
self.logfile = None
# Main logfile is append mode, other logfiles not.
if not os.path.exists(logfile):
self.logfile = open(logfile, "a")
sub_process.call("chown apache %s" % logfile, shell=True)
self.logfile.close()
try:
if logfile.find("tasks") != -1:
self.logfile = open(logfile, "w+")
else:
self.logfile = open(logfile, "a")
except IOError:
# You likely don't have write access, this logger will just print
# things to stdout.
pass
示例10: subprocess_call
def subprocess_call(cmd, ignore_rc=False):
"""
Wrapper around subprocess.call(...)
"""
print "- %s" % cmd
rc = sub_process.call(cmd)
if rc != 0 and not ignore_rc:
raise InfoException, "command failed (%s)" % rc
return rc
示例11: is_selinux_enabled
def is_selinux_enabled():
if not os.path.exists("/usr/sbin/selinuxenabled"):
return False
args = "/usr/sbin/selinuxenabled"
selinuxenabled = sub_process.call(args,close_fds=True)
if selinuxenabled == 0:
return True
else:
return False
示例12: __command
def __command(self, service_name, command):
service_name = service_name.strip() # remove useless spaces
filename = os.path.join("/etc/rc.d/init.d/",service_name)
if os.path.exists(filename):
return sub_process.call(["/sbin/service", service_name, command], close_fds=True)
else:
raise codes.FuncException("Service not installed: %s" % service_name)
示例13: modacl
def modacl(self,isadd,isuser,who):
webdir = self.settings.webdir
snipdir = self.settings.snippetsdir
tftpboot = utils.tftpboot_location()
PROCESS_DIRS = {
webdir : "rwx",
"/var/log/cobbler" : "rwx",
"/var/lib/cobbler" : "rwx",
"/etc/cobbler" : "rwx",
tftpboot : "rwx",
"/var/lib/cobbler/triggers" : "rwx"
}
if not snipdir.startswith("/var/lib/cobbler/"):
PROCESS_DIRS[snipdir] = "r"
cmd = "-R"
if isadd:
cmd = "%s -m" % cmd
else:
cmd = "%s -x" % cmd
if isuser:
cmd = "%s u:%s" % (cmd,who)
else:
cmd = "%s g:%s" % (cmd,who)
for d in PROCESS_DIRS:
how = PROCESS_DIRS[d]
if isadd:
cmd2 = "%s:%s" % (cmd,how)
else:
cmd2 = cmd
cmd2 = "%s %s" % (cmd2,d)
print "- setfacl -d %s" % cmd2
rc = sub_process.call("setfacl -d %s" % cmd2,shell=True,close_fds=True)
if not rc == 0:
raise CX(_("command failed"))
print "- setfacl %s" % cmd2
rc = sub_process.call("setfacl %s" % cmd2,shell=True,close_fds=True)
if not rc == 0:
raise CX(_("command failed"))
示例14: check_service
def check_service(self, status, which, notes=""):
if notes != "":
notes = " (NOTE: %s)" % notes
rc = 0
if self.checked_dist == "redhat" or self.checked_dist == "suse":
if os.path.exists("/etc/rc.d/init.d/%s" % which):
rc = sub_process.call("/sbin/service %s status > /dev/null 2>/dev/null" % which, shell=True, close_fds=True)
if rc != 0:
status.append(_("service %s is not running%s") % (which,notes))
return False
elif self.checked_dist == "debian":
if os.path.exists("/etc/init.d/%s" % which):
rc = sub_process.call("/etc/init.d/%s status /dev/null 2>/dev/null" % which, shell=True, close_fds=True)
if rc != 0:
status.append(_("service %s is not running%s") % which,notes)
return False
else:
status.append(_("Unknown distribution type, cannot check for running service %s" % which))
return False
return True
示例15: run_this
def run_this(self, cmd, args):
"""
A simple wrapper around subprocess calls.
"""
my_cmd = cmd % args
print _("- %s") % my_cmd
rc = sub_process.call(my_cmd,shell=True,close_fds=True)
if rc != 0:
raise CX(_("Command failed"))