本文整理汇总了Python中mic.msger.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_prepare_partition
def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
kernel_dir, krootfs_dir, native_sysroot):
"""
Called to do the actual content population for a partition i.e. it
'prepares' the partition to be incorporated into the image.
In this case, prepare content for legacy bios boot partition.
"""
if part.rootfs is None:
if not 'ROOTFS_DIR' in krootfs_dir:
msg = "Couldn't find --rootfs-dir, exiting"
msger.error(msg)
rootfs_dir = krootfs_dir['ROOTFS_DIR']
else:
if part.rootfs in krootfs_dir:
rootfs_dir = krootfs_dir[part.rootfs]
elif part.rootfs:
rootfs_dir = part.rootfs
else:
msg = "Couldn't find --rootfs-dir=%s connection"
msg += " or it is not a valid path, exiting"
msger.error(msg % part.rootfs)
real_rootfs_dir = self.__get_rootfs_dir(rootfs_dir)
part.set_rootfs(real_rootfs_dir)
part.prepare_rootfs(cr_workdir, oe_builddir, real_rootfs_dir, native_sysroot)
示例2: do_prepare_partition
def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir,
kernel_dir, native_sysroot):
"""
Called to do the actual content population for a partition i.e. it
'prepares' the partition to be incorporated into the image.
In this case, prepare content for legacy bios boot partition.
"""
if not bootimg_dir:
bootimg_dir = get_bitbake_var("STAGING_DATADIR")
if not bootimg_dir:
msger.error("Couldn't find STAGING_DATADIR, exiting\n")
# just so the result notes display it
cr.set_bootimg_dir(bootimg_dir)
staging_kernel_dir = kernel_dir
staging_data_dir = bootimg_dir
hdddir = "%s/hdd/boot" % cr_workdir
install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \
% (staging_kernel_dir, hdddir)
tmp = exec_cmd(install_cmd)
install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \
% (staging_data_dir, hdddir)
tmp = exec_cmd(install_cmd)
du_cmd = "du -bks %s" % hdddir
rc, out = exec_cmd(du_cmd)
blocks = int(out.split()[0])
blocks += BOOTDD_EXTRA_SPACE
# Ensure total sectors is an integral number of sectors per
# track or mcopy will complain. Sectors are 512 bytes, and we
# generate images with 32 sectors per track. This calculation is
# done in blocks, thus the mod by 16 instead of 32.
blocks += (16 - (blocks % 16))
# dosfs image, created by mkdosfs
bootimg = "%s/boot.img" % cr_workdir
dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
exec_native_cmd(dosfs_cmd, native_sysroot)
mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
exec_native_cmd(mcopy_cmd, native_sysroot)
syslinux_cmd = "syslinux %s" % bootimg
exec_native_cmd(syslinux_cmd, native_sysroot)
chmod_cmd = "chmod 644 %s" % bootimg
exec_cmd(chmod_cmd)
du_cmd = "du -Lbms %s" % bootimg
rc, out = exec_cmd(du_cmd)
bootimg_size = out.split()[0]
part.set_size(bootimg_size)
part.set_source_file(bootimg)
示例3: exec_native_cmd
def exec_native_cmd(cmd_and_args, native_sysroot, catch = 3):
"""
Execute native command, catching stderr, stdout
Need to execute as_shell if the command uses wildcards
Always need to execute native commands as_shell
"""
native_paths = \
"export PATH=%s/sbin:%s/usr/sbin:%s/usr/bin:$PATH" % \
(native_sysroot, native_sysroot, native_sysroot)
native_cmd_and_args = "%s;%s" % (native_paths, cmd_and_args)
msger.debug("exec_native_cmd: %s" % cmd_and_args)
args = cmd_and_args.split()
msger.debug(args)
rc, out = exec_cmd(native_cmd_and_args, True, catch)
if rc == 127: # shell command-not-found
msger.error("A native (host) program required to build the image "
"was not found (see details above). Please make sure "
"it's installed and try again.")
return (rc, out)
示例4: close
def close(self):
if self.created:
try:
self.cleanup()
self.device = None
except MountError, e:
msger.error("%s" % e)
示例5: set_runtime
def set_runtime(self, runtime):
if runtime not in ("bootstrap", "native"):
msger.error("Invalid runtime mode: %s" % runtime)
if misc.get_distro()[0] in ("tizen", "Tizen"):
runtime = "native"
self.create['runtime'] = runtime
示例6: _do_chroot_tar
def _do_chroot_tar(cls, target, cmd=[]):
mountfp_xml = os.path.splitext(target)[0] + '.xml'
if not os.path.exists(mountfp_xml):
raise errors.CreatorError("No mount point file found for this tar "
"image, please check %s" % mountfp_xml)
import tarfile
tar = tarfile.open(target, 'r')
tmpdir = misc.mkdtemp()
tar.extractall(path=tmpdir)
tar.close()
mntdir = misc.mkdtemp()
loops = []
for (mp, label, name, size, fstype) in load_mountpoints(mountfp_xml):
if fstype in ("ext2", "ext3", "ext4"):
myDiskMount = fs_related.ExtDiskMount
elif fstype == "btrfs":
myDiskMount = fs_related.BtrfsDiskMount
elif fstype in ("vfat", "msdos"):
myDiskMount = fs_related.VfatDiskMount
else:
msger.error("Cannot support fstype: %s" % fstype)
name = os.path.join(tmpdir, name)
size = size * 1024L * 1024L
loop = myDiskMount(fs_related.SparseLoopbackDisk(name, size),
os.path.join(mntdir, mp.lstrip('/')),
fstype, size, label)
try:
msger.verbose("Mount %s to %s" % (mp, mntdir + mp))
fs_related.makedirs(os.path.join(mntdir, mp.lstrip('/')))
loop.mount()
except:
loop.cleanup()
for lp in reversed(loops):
chroot.cleanup_after_chroot("img", lp, None, mntdir)
shutil.rmtree(tmpdir, ignore_errors=True)
raise
loops.append(loop)
try:
if len(cmd) != 0:
cmdline = "/usr/bin/env HOME=/root " + ' '.join(cmd)
else:
cmdline = "/usr/bin/env HOME=/root /bin/bash"
chroot.chroot(mntdir, None, cmdline)
except:
raise errors.CreatorError("Failed to chroot to %s." % target)
finally:
for loop in reversed(loops):
chroot.cleanup_after_chroot("img", loop, None, mntdir)
shutil.rmtree(tmpdir, ignore_errors=True)
示例7: postoptparse
def postoptparse(self):
if self.options.verbose:
msger.set_loglevel('verbose')
if self.options.debug:
msger.set_loglevel('debug')
if self.options.logfile:
msger.set_interactive(False)
msger.set_logfile(self.options.logfile)
configmgr.create['logfile'] = self.options.logfile
if self.options.config:
configmgr.reset()
configmgr._siteconf = self.options.config
if self.options.outdir is not None:
configmgr.create['outdir'] = self.options.outdir
if self.options.cachedir is not None:
configmgr.create['cachedir'] = self.options.cachedir
os.environ['ZYPP_LOCKFILE_ROOT'] = configmgr.create['cachedir']
if self.options.local_pkgs_path is not None:
if not os.path.exists(self.options.local_pkgs_path):
msger.error('Local pkgs directory: \'%s\' not exist' \
% self.options.local_pkgs_path)
configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path
if self.options.release:
configmgr.create['release'] = self.options.release
if self.options.record_pkgs:
configmgr.create['record_pkgs'] = []
for infotype in self.options.record_pkgs.split(','):
if infotype not in ('name', 'content', 'license'):
raise errors.Usage('Invalid pkg recording: %s, valid ones:'
' "name", "content", "license"' \
% infotype)
configmgr.create['record_pkgs'].append(infotype)
if self.options.arch is not None:
supported_arch = sorted(rpmmisc.archPolicies.keys(), reverse=True)
if self.options.arch in supported_arch:
configmgr.create['arch'] = self.options.arch
else:
raise errors.Usage('Invalid architecture: "%s".\n'
' Supported architectures are: \n'
' %s\n' % (self.options.arch,
', '.join(supported_arch)))
if self.options.pkgmgr is not None:
configmgr.create['pkgmgr'] = self.options.pkgmgr
if self.options.runtime:
configmgr.create['runtime'] = self.options.runtime
if self.options.compress_disk_image is not None:
configmgr.create['compress_disk_image'] = \
self.options.compress_disk_image
示例8: _mount_instroot
def _mount_instroot(self, base_on=None):
if base_on and os.path.isfile(base_on):
self.__imgdir = os.path.dirname(base_on)
imgname = os.path.basename(base_on)
self._base_on(base_on)
self._set_image_size(misc.get_file_size(self._image))
# here, self._instloops must be []
self._instloops.append({
"mountpoint": "/",
"label": self.name,
"name": imgname,
"size": self.__image_size or 4096L,
"fstype": self.__fstype or "ext3",
"extopts": None,
"loop": None
})
self._check_imgdir()
for loop in self._instloops:
fstype = loop['fstype']
mp = os.path.join(self._instroot, loop['mountpoint'].lstrip('/'))
size = loop['size'] * 1024L * 1024L
imgname = loop['name']
if fstype in ("ext2", "ext3", "ext4"):
MyDiskMount = fs.ExtDiskMount
elif fstype == "btrfs":
MyDiskMount = fs.BtrfsDiskMount
elif fstype in ("vfat", "msdos"):
MyDiskMount = fs.VfatDiskMount
else:
msger.error('Cannot support fstype: %s' % fstype)
loop['loop'] = MyDiskMount(fs.SparseLoopbackDisk(
os.path.join(self.__imgdir, imgname),
size),
mp,
fstype,
self._blocksize,
loop['label'])
if fstype in ("ext2", "ext3", "ext4"):
loop['loop'].extopts = loop['extopts']
try:
msger.verbose('Mounting image "%s" on "%s"' % (imgname, mp))
fs.makedirs(mp)
loop['loop'].mount()
except MountError, e:
raise
示例9: runtool
def runtool(cmdln_or_args, catch=1):
""" wrapper for most of the subprocess calls
input:
cmdln_or_args: can be both args and cmdln str (shell=True)
catch: 0, quitely run
1, only STDOUT
2, only STDERR
3, both STDOUT and STDERR
return:
(rc, output)
if catch==0: the output will always None
"""
if catch not in (0, 1, 2, 3):
# invalid catch selection, will cause exception, that's good
return None
if isinstance(cmdln_or_args, list):
cmd = cmdln_or_args[0]
shell = False
else:
import shlex
cmd = shlex.split(cmdln_or_args)[0]
shell = True
if catch != 3:
dev_null = os.open("/dev/null", os.O_WRONLY)
if catch == 0:
sout = dev_null
serr = dev_null
elif catch == 1:
sout = subprocess.PIPE
serr = dev_null
elif catch == 2:
sout = dev_null
serr = subprocess.PIPE
elif catch == 3:
sout = subprocess.PIPE
serr = subprocess.STDOUT
try:
p = subprocess.Popen(cmdln_or_args, stdout=sout,
stderr=serr, shell=shell)
(sout, serr) = p.communicate()
# combine stdout and stderr, filter None out
out = ''.join(filter(None, [sout, serr]))
except OSError, e:
if e.errno == 2:
# [Errno 2] No such file or directory
msger.error('Cannot run command: %s, lost dependency?' % cmd)
else:
raise # relay
示例10: precmd
def precmd(self, argv): # check help before cmd
if '-h' in argv or '?' in argv or '--help' in argv or 'help' in argv:
return argv
if len(argv) == 1:
return ['help', argv[0]]
if os.geteuid() != 0:
msger.error("Root permission is required, abort")
try:
w = pwd.getpwuid(os.geteuid())
except KeyError:
msger.warning("Might fail in compressing stage for undetermined user")
return argv
示例11: __get_rootfs_dir
def __get_rootfs_dir(rootfs_dir):
if os.path.isdir(rootfs_dir):
return rootfs_dir
bitbake_env_lines = find_bitbake_env_lines(rootfs_dir)
if not bitbake_env_lines:
msg = "Couldn't get bitbake environment, exiting."
msger.error(msg)
image_rootfs_dir = find_artifact(bitbake_env_lines, "IMAGE_ROOTFS")
if not os.path.isdir(image_rootfs_dir):
msg = "No valid artifact IMAGE_ROOTFS from image named"
msg += " %s has been found at %s, exiting.\n" % \
(rootfs_dir, image_rootfs_dir)
msger.error(msg)
return image_rootfs_dir
示例12: __run_parted
def __run_parted(self, args):
""" Run parted with arguments specified in the 'args' list. """
args.insert(0, self.parted)
msger.debug(args)
rc, out = runner.runtool(args, catch = 3)
out = out.strip()
if out:
msger.debug('"parted" output: %s' % 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.error("WARNING: parted returned '%s' instead of 0 (use --debug for details)" % rc)
示例13: _install_syslinux
def _install_syslinux(self):
mbrfile = "%s/syslinux/" % self.bootimg_dir
if self._ptable_format == 'gpt':
mbrfile += "gptmbr.bin"
else:
mbrfile += "mbr.bin"
if not os.path.exists(mbrfile):
msger.error("Couldn't find %s. If using the -e option, do you have the right MACHINE set in local.conf? If not, is the bootimg_dir path correct?" % mbrfile)
for disk_name, disk in self.__instimage.disks.items():
full_path = self._full_path(self.__imgdir, disk_name, "direct")
msger.debug("Installing MBR on disk %s as %s with size %s bytes" \
% (disk_name, full_path, disk['min_size']))
rc = runner.show(['dd', 'if=%s' % mbrfile,
'of=%s' % full_path, 'conv=notrunc'])
if rc != 0:
raise MountError("Unable to set MBR to %s" % full_path)
示例14: main
def main(self, argv=None):
if argv is None:
argv = sys.argv
else:
argv = argv[:] # don't modify caller's list
self.optparser = self.get_optparser()
if self.optparser:
try:
argv = self.preoptparse(argv)
self.options, args = self.optparser.parse_args(argv)
except cmdln.CmdlnUserError, ex:
msg = "%s: %s\nTry '%s help' for info.\n"\
% (self.name, ex, self.name)
msger.error(msg)
except cmdln.StopOptionProcessing, ex:
return 0
示例15: _parse_siteconf
def _parse_siteconf(self, siteconf):
if not siteconf:
return
if not os.path.exists(siteconf):
msger.warning("cannot read config file: %s" % siteconf)
return
parser = ConfigParser.SafeConfigParser()
parser.read(siteconf)
for section in parser.sections():
if section in self.DEFAULTS:
getattr(self, section).update(dict(parser.items(section)))
# append common section items to other sections
for section in self.DEFAULTS.keys():
if section != "common":
getattr(self, section).update(self.common)
# check and normalize the scheme of proxy url
if self.create['proxy']:
m = re.match('^(\w+)://.*', self.create['proxy'])
if m:
scheme = m.group(1)
if scheme not in ('http', 'https', 'ftp', 'socks'):
msger.error("%s: proxy scheme is incorrect" % siteconf)
else:
msger.warning("%s: proxy url w/o scheme, use http as default"
% siteconf)
self.create['proxy'] = "http://" + self.create['proxy']
proxy.set_proxies(self.create['proxy'], self.create['no_proxy'])
# bootstrap option handling
self.set_runtime(self.create['runtime'])
if isinstance(self.bootstrap['packages'], basestring):
packages = self.bootstrap['packages'].replace('\n', ' ')
if packages.find(',') != -1:
packages = packages.split(',')
else:
packages = packages.split()
self.bootstrap['packages'] = packages