本文整理汇总了Python中mic.msger.warning函数的典型用法代码示例。如果您正苦于以下问题:Python warning函数的具体用法?Python warning怎么用?Python warning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup_mounts
def cleanup_mounts(chrootdir):
umountcmd = misc.find_binary_path("umount")
for point in BIND_MOUNTS:
args = [ umountcmd, "-l", chrootdir + point ]
runner.quiet(args)
point = '/parentroot'
args = [ umountcmd, "-l", chrootdir + point ]
runner.quiet(args)
abs_chrootdir = os.path.abspath(chrootdir)
with open('/proc/mounts') as f:
for line in f:
if abs_chrootdir in line:
point = line.split()[1]
if abs_chrootdir == point:
continue
args = [ umountcmd, "-l", point ]
ret = runner.quiet(args)
if ret != 0:
msger.warning("failed to unmount %s" % point)
return ret
return 0
示例2: check_bind_mounts
def check_bind_mounts(chrootdir, bindmounts):
chrootmounts = []
for mount in bindmounts.split(";"):
if not mount:
continue
srcdst = mount.split(":")
if len(srcdst) == 1:
srcdst.append("none")
if not os.path.isdir(srcdst[0]):
return False
if srcdst[1] == "" or srcdst[1] == "none":
srcdst[1] = None
if srcdst[0] in BIND_MOUNTS or srcdst[0] == '/':
continue
if chrootdir:
if not srcdst[1]:
srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[0]))
else:
srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
tmpdir = chrootdir + "/" + srcdst[1]
if os.path.isdir(tmpdir):
msger.warning("Warning: dir %s has existed." % tmpdir)
return True
示例3: deselectPackage
def deselectPackage(self, pkg):
"""Deselect package. Can be specified as name.arch or name*
"""
sp = pkg.rsplit(".", 2)
txmbrs = []
if len(sp) == 2:
txmbrs = self.tsInfo.matchNaevr(name=sp[0], arch=sp[1])
if len(txmbrs) == 0:
exact, match, unmatch = yum.packages.parsePackages(
self.pkgSack.returnPackages(),
[pkg],
casematch=1)
for p in exact + match:
txmbrs.append(p)
if len(txmbrs) > 0:
for x in txmbrs:
self.tsInfo.remove(x.pkgtup)
# we also need to remove from the conditionals
# dict so that things don't get pulled back in as a result
# of them. yes, this is ugly. conditionals should die.
for req, pkgs in self.tsInfo.conditionals.iteritems():
if x in pkgs:
pkgs.remove(x)
self.tsInfo.conditionals[req] = pkgs
else:
msger.warning("No such package %s to remove" %(pkg,))
示例4: savefs_before_chroot
def savefs_before_chroot(chrootdir, saveto = None):
""" backup chrootdir to another directory before chrooting in """
if configmgr.chroot['saveto']:
savefs = True
saveto = configmgr.chroot['saveto']
wrnmsg = "Can't save chroot fs for dir %s exists" % saveto
if saveto == chrootdir:
savefs = False
wrnmsg = "Dir %s is being used to chroot" % saveto
elif os.path.exists(saveto):
if msger.ask("Dir %s already exists, cleanup and continue?" %
saveto):
shutil.rmtree(saveto, ignore_errors = True)
savefs = True
else:
savefs = False
if savefs:
msger.info("Saving image to directory %s" % saveto)
fs_related.makedirs(os.path.dirname(os.path.abspath(saveto)))
runner.quiet("cp -af %s %s" % (chrootdir, saveto))
devs = ['dev/fd',
'dev/stdin',
'dev/stdout',
'dev/stderr',
'etc/mtab']
ignlst = [os.path.join(saveto, x) for x in devs]
map(os.unlink, filter(os.path.exists, ignlst))
else:
msger.warning(wrnmsg)
示例5: cleanup_mountdir
def cleanup_mountdir(chrootdir, bindmounts):
if bindmounts == "" or bindmounts == None:
return
chrootmounts = []
for mount in bindmounts.split(";"):
if not mount:
continue
srcdst = mount.split(":")
if len(srcdst) == 1:
srcdst.append("none")
if srcdst[0] == "/":
continue
if srcdst[1] == "" or srcdst[1] == "none":
srcdst[1] = srcdst[0]
srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
tmpdir = chrootdir + "/" + srcdst[1]
if os.path.isdir(tmpdir):
if len(os.listdir(tmpdir)) == 0:
shutil.rmtree(tmpdir, ignore_errors = True)
else:
msger.warning("Warning: dir %s isn't empty." % tmpdir)
示例6: preinstallPkgs
def preinstallPkgs(self):
if not self.ts_pre:
self.__initialize_transaction()
self.ts_pre.order()
cb = rpmmisc.RPMInstallCallback(self.ts_pre)
cb.headmsg = "Preinstall"
installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
# start to catch stderr output from librpm
msger.enable_logstderr(installlogfile)
errors = self.ts_pre.run(cb.callback, '')
# stop catch
msger.disable_logstderr()
self.ts_pre.closeDB()
self.ts_pre = None
if errors is not None:
if len(errors) == 0:
msger.warning('scriptlet or other non-fatal errors occurred '
'during transaction.')
else:
for e in errors:
msger.warning(e[0])
raise RepoError('Could not run transaction.')
示例7: configure
def configure(self, repodata=None):
"""Configure the system image according to the kickstart.
This method applies the (e.g. keyboard or network) configuration
specified in the kickstart and executes the kickstart %post scripts.
If necessary, it also prepares the image to be bootable by e.g.
creating an initrd and bootloader configuration.
"""
ksh = self.ks.handler
msger.info("Applying configurations ...")
try:
kickstart.LanguageConfig(self._instroot).apply(ksh.lang)
kickstart.KeyboardConfig(self._instroot).apply(ksh.keyboard)
kickstart.TimezoneConfig(self._instroot).apply(ksh.timezone)
# kickstart.AuthConfig(self._instroot).apply(ksh.authconfig)
kickstart.FirewallConfig(self._instroot).apply(ksh.firewall)
kickstart.RootPasswordConfig(self._instroot).apply(ksh.rootpw)
kickstart.UserConfig(self._instroot).apply(ksh.user)
kickstart.ServicesConfig(self._instroot).apply(ksh.services)
kickstart.XConfig(self._instroot).apply(ksh.xconfig)
kickstart.NetworkConfig(self._instroot).apply(ksh.network)
kickstart.RPMMacroConfig(self._instroot).apply(self.ks)
kickstart.DesktopConfig(self._instroot).apply(ksh.desktop)
self.__save_repo_keys(repodata)
kickstart.MoblinRepoConfig(self._instroot).apply(ksh.repo, repodata)
except:
msger.warning("Failed to apply configuration to image")
raise
self._create_bootconfig()
self.__run_post_scripts()
示例8: addUser
def addUser(self, userconfig):
args = [ "/usr/sbin/useradd" ]
if userconfig.groups:
args += [ "--groups", string.join(userconfig.groups, ",") ]
if userconfig.name:
args += [ "-m"]
args += [ "-d", "/home/%s" % userconfig.name ]
args.append(userconfig.name)
try:
dev_null = os.open("/dev/null", os.O_WRONLY)
msger.debug('adding user with %s' % args)
subprocess.call(args,
stdout = dev_null,
stderr = dev_null,
preexec_fn = self.chroot)
os.close(dev_null)
except:
msger.warning('Cannot add user using "useradd"')
if userconfig.password not in (None, ""):
if userconfig.isCrypted:
self.set_encrypted_passwd(userconfig.name,
userconfig.password)
else:
self.set_unencrypted_passwd(userconfig.name,
userconfig.password)
else:
self.set_empty_passwd(userconfig.name)
else:
raise errors.KsError("Invalid kickstart command: %s" \
% userconfig.__str__())
示例9: __create_iso
def __create_iso(self, isodir):
iso = self._outdir + "/" + self.name + ".iso"
genisoimage = fs_related.find_binary_path("genisoimage")
args = [genisoimage,
"-J", "-r",
"-hide-rr-moved", "-hide-joliet-trans-tbl",
"-V", self.fslabel,
"-o", iso]
args.extend(self._get_mkisofs_options(isodir))
args.append(isodir)
if runner.show(args) != 0:
raise CreatorError("ISO creation failed!")
""" It should be ok still even if you haven't isohybrid """
isohybrid = None
if self._isohybrid:
try:
isohybrid = fs_related.find_binary_path("isohybrid")
msger.info("isohybrid found")
except:
msger.warning("isohybrid NOT found")
if isohybrid:
args = [isohybrid, "-partok", iso ]
if runner.show(args) != 0:
raise CreatorError("Hybrid ISO creation failed!")
else:
msger.info("Hybrid ISO created successfully")
self.__implant_md5sum(iso)
示例10: load_mountpoints
def load_mountpoints(fpath):
"""Load mount points mapping from file
:fpath, file path to load
"""
if not fpath:
return
from xml.dom import minidom
mount_maps = []
with open(fpath, 'r') as rf:
dom = minidom.parse(rf)
imgroot = dom.documentElement
for part in imgroot.getElementsByTagName("partition"):
p = dict(part.attributes.items())
try:
mp = (p['mountpoint'], p['label'], p['name'],
int(p['size']), p['fstype'])
except KeyError:
msger.warning("Wrong format line in file: %s" % fpath)
except ValueError:
msger.warning("Invalid size '%s' in file: %s" % (p['size'], fpath))
else:
mount_maps.append(mp)
return mount_maps
示例11: exec_cmd
def exec_cmd(cmd_and_args, as_shell = False, catch = 3):
"""
Execute command, catching stderr, stdout
Need to execute as_shell if the command uses wildcards
"""
msger.debug("exec_cmd: %s" % cmd_and_args)
args = cmd_and_args.split()
msger.debug(args)
if (as_shell):
rc, out = runner.runtool(cmd_and_args, catch)
else:
rc, out = runner.runtool(args, catch)
out = out.strip()
msger.debug("exec_cmd: output for %s (rc = %d): %s" % \
(cmd_and_args, rc, out))
if rc != 0:
# We don't throw exception when return code is not 0, because
# parted always fails to reload part table with loop devices. This
# prevents us from distinguishing real errors based on return
# code.
msger.warning("WARNING: %s returned '%s' instead of 0" % (cmd_and_args, rc))
return (rc, out)
示例12: SrcpkgsDownload
def SrcpkgsDownload(pkgs, repometadata, instroot, cachedir):
def get_source_repometadata(repometadata):
src_repometadata=[]
for repo in repometadata:
if repo["name"].endswith("-source"):
src_repometadata.append(repo)
if src_repometadata:
return src_repometadata
return None
def get_src_name(srpm):
m = SRPM_RE.match(srpm)
if m:
return m.group(1)
return None
src_repometadata = get_source_repometadata(repometadata)
if not src_repometadata:
msger.warning("No source repo found")
return None
src_pkgs = []
lpkgs_dict = {}
lpkgs_path = []
for repo in src_repometadata:
cachepath = "%s/%s/packages/*.src.rpm" %(cachedir, repo["name"])
lpkgs_path += glob.glob(cachepath)
for lpkg in lpkgs_path:
lpkg_name = get_src_name(os.path.basename(lpkg))
lpkgs_dict[lpkg_name] = lpkg
localpkgs = lpkgs_dict.keys()
cached_count = 0
destdir = instroot+'/usr/src/SRPMS'
if not os.path.exists(destdir):
os.makedirs(destdir)
srcpkgset = set()
for _pkg in pkgs:
srcpkg_name = get_source_name(_pkg, repometadata)
if not srcpkg_name:
continue
srcpkgset.add(srcpkg_name)
for pkg in list(srcpkgset):
if pkg in localpkgs:
cached_count += 1
shutil.copy(lpkgs_dict[pkg], destdir)
src_pkgs.append(os.path.basename(lpkgs_dict[pkg]))
else:
src_pkg = get_package(pkg, src_repometadata, 'src')
if src_pkg:
shutil.copy(src_pkg, destdir)
src_pkgs.append(src_pkg)
msger.info("%d source packages gotten from cache" % cached_count)
return src_pkgs
示例13: get_bind_mounts
def get_bind_mounts(chrootdir, bindmounts, mountparent = True):
chrootmounts = []
if bindmounts in ("", None):
bindmounts = ""
for mount in bindmounts.split(";"):
if not mount:
continue
srcdst = mount.split(":")
srcdst[0] = os.path.abspath(os.path.expanduser(srcdst[0]))
if len(srcdst) == 1:
srcdst.append("none")
# if some bindmount is not existed, but it's created inside
# chroot, this is not expected
if not os.path.exists(srcdst[0]):
os.makedirs(srcdst[0])
if not os.path.isdir(srcdst[0]):
continue
if srcdst[0] in BIND_MOUNTS or srcdst[0] == '/':
msger.verbose("%s will be mounted by default." % srcdst[0])
continue
if srcdst[1] == "" or srcdst[1] == "none":
srcdst[1] = None
else:
srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
if os.path.isdir(chrootdir + "/" + srcdst[1]):
msger.warning("%s has existed in %s , skip it."\
% (srcdst[1], chrootdir))
continue
chrootmounts.append(fs_related.BindChrootMount(srcdst[0],
chrootdir,
srcdst[1]))
"""Default bind mounts"""
for pt in BIND_MOUNTS:
chrootmounts.append(fs_related.BindChrootMount(pt,
chrootdir,
None))
if mountparent:
chrootmounts.append(fs_related.BindChrootMount("/",
chrootdir,
"/parentroot",
"ro"))
for kernel in os.listdir("/lib/modules"):
chrootmounts.append(fs_related.BindChrootMount(
"/lib/modules/"+kernel,
chrootdir,
None,
"ro"))
return chrootmounts
示例14: checkPkg
def checkPkg(self, pkg):
ret = 1
if not os.path.exists(pkg):
return ret
ret = rpmmisc.checkRpmIntegrity('rpm', pkg)
if ret != 0:
msger.warning("package %s is damaged: %s" % (os.path.basename(pkg), pkg))
return ret
示例15: setup_qemu_emulator
def setup_qemu_emulator(rootdir, arch):
# mount binfmt_misc if it doesn't exist
if not os.path.exists("/proc/sys/fs/binfmt_misc"):
modprobecmd = find_binary_path("modprobe")
runner.show([modprobecmd, "binfmt_misc"])
if not os.path.exists("/proc/sys/fs/binfmt_misc/register"):
mountcmd = find_binary_path("mount")
runner.show([mountcmd, "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"])
# qemu_emulator is a special case, we can't use find_binary_path
# qemu emulator should be a statically-linked executable file
qemu_emulator = "/usr/bin/qemu-arm"
if not os.path.exists(qemu_emulator) or not is_statically_linked(qemu_emulator):
qemu_emulator = "/usr/bin/qemu-arm-static"
if not os.path.exists(qemu_emulator):
raise CreatorError("Please install a statically-linked qemu-arm")
# qemu emulator version check
armv7_list = [arch for arch in rpmmisc.archPolicies.keys() if arch.startswith('armv7')]
if arch in armv7_list: # need qemu (>=0.13.0)
qemuout = runner.outs([qemu_emulator, "-h"])
m = re.search("version\s*([.\d]+)", qemuout)
if m:
qemu_version = m.group(1)
if qemu_version < "0.13":
raise CreatorError("Requires %s version >=0.13 for %s" % (qemu_emulator, arch))
else:
msger.warning("Can't get version info of %s, please make sure it's higher than 0.13.0" % qemu_emulator)
if not os.path.exists(rootdir + "/usr/bin"):
makedirs(rootdir + "/usr/bin")
shutil.copy(qemu_emulator, rootdir + qemu_emulator)
# disable selinux, selinux will block qemu emulator to run
if os.path.exists("/usr/sbin/setenforce"):
msger.info('Try to disable selinux')
runner.show(["/usr/sbin/setenforce", "0"])
node = "/proc/sys/fs/binfmt_misc/arm"
if is_statically_linked(qemu_emulator) and os.path.exists(node):
return qemu_emulator
# unregister it if it has been registered and is a dynamically-linked executable
if not is_statically_linked(qemu_emulator) and os.path.exists(node):
qemu_unregister_string = "-1\n"
fd = open("/proc/sys/fs/binfmt_misc/arm", "w")
fd.write(qemu_unregister_string)
fd.close()
# register qemu emulator for interpreting other arch executable file
if not os.path.exists(node):
qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:\n" % qemu_emulator
fd = open("/proc/sys/fs/binfmt_misc/register", "w")
fd.write(qemu_arm_string)
fd.close()
return qemu_emulator