本文整理汇总了Python中molecule.output.blue函数的典型用法代码示例。如果您正苦于以下问题:Python blue函数的具体用法?Python blue怎么用?Python blue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了blue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pre_run
def pre_run(self):
self._output.output("[%s|%s] %s" % (
blue("TarHandler"), darkred(self.spec_name),
_("executing pre_run"),
)
)
# run pre tar script
exec_script = self.metadata.get('pre_tar_script')
if exec_script:
env = os.environ.copy()
env['CHROOT_DIR'] = self.chroot_path
env['TAR_PATH'] = self.dest_path
env['TAR_CHECKSUM_PATH'] = self.dest_path + \
TarHandler.MD5_EXT
self._output.output("[%s|%s] %s: %s" % (
blue("TarHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env=env)
if rc != 0:
self._output.output(
"[%s|%s] %s: %s" % (
blue("TarHandler"), darkred(self.spec_name),
_("pre tar hook failed"), rc,
)
)
return rc
return 0
示例2: post_run
def post_run(self):
self._output.output("[%s|%s] %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("executing post_run"),
)
)
# run outer chroot script after
exec_script = self.metadata.get('outer_source_chroot_script_after')
if exec_script:
env = os.environ.copy()
env['IMAGE_NAME'] = self.metadata['image_name']
env['DESTINATION_IMAGE_DIR'] = \
self.metadata['destination_image_directory']
env['CHROOT_DIR'] = self.source_dir
self._output.output("[%s|%s] %s: %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env = env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("outer chroot hook (after inner) failed"), rc,
)
)
return rc
return 0
示例3: kill
def kill(self, success=True):
self._output.output("[%s|%s] %s" % (
blue("IsoUnpackHandler"), darkred(self.spec_name),
_("executing kill"),
)
)
if not success:
self._run_error_script(None, self.chroot_dir, self.dest_root)
rc = 0
if self.squash_mounted:
umounter = self.metadata.get('squash_umounter',
self._squash_umounter)
args = umounter + [self.tmp_squash_mount]
rc = molecule.utils.exec_cmd(args)
if rc == 0:
try:
os.rmdir(self.tmp_squash_mount)
except OSError:
self._output.output(
"[%s|%s] %s: %s" % (
blue("IsoUnpackHandler"), darkred(self.spec_name),
_("unable to remove temp. dir"), self.tmp_squash_mount,
)
)
rc = 0
if self.iso_mounted:
umounter = self.metadata.get('iso_umounter',
self._iso_umounter)
args = umounter + [self.tmp_mount]
rc = molecule.utils.exec_cmd(args)
if rc == 0:
try:
os.rmdir(self.tmp_mount)
except OSError:
# if not empty, skip
self._output.output(
"[%s|%s] %s: %s" % (
blue("IsoUnpackHandler"), darkred(self.spec_name),
_("unable to remove temp. dir"), self.tmp_mount,
)
)
if not success:
tmp_dir = self.metadata['chroot_tmp_dir']
if tmp_dir is not None:
try:
shutil.rmtree(tmp_dir, True)
except (shutil.Error, OSError,):
self._output.output("[%s|%s] %s: %s" % (
blue("IsoUnpackHandler"), darkred(self.spec_name),
_("unable to remove temp. dir"), tmp_dir,
)
)
return 0
示例4: pre_run
def pre_run(self):
self._output.output("[%s|%s] %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("executing pre_run"),
)
)
# run pre image script
exec_script = self.metadata.get('pre_image_script')
if exec_script:
env = os.environ.copy()
env['TMP_IMAGE_PATH'] = self.tmp_loop_device_file
env['LOOP_DEVICE'] = self.loop_device
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env=env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("pre image hook failed"), rc,
)
)
return rc
return 0
示例5: pre_run
def pre_run(self):
self._output.output("[%s|%s] %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("executing pre_run"),
)
)
# run pre image script
exec_script = self.metadata.get('pre_image_script')
if exec_script:
env = os.environ.copy()
env['IMAGE_NAME'] = self.metadata['image_name']
env['DESTINATION_IMAGE_DIR'] = \
self.metadata['destination_image_directory']
env['CHROOT_DIR'] = self.source_dir
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env = env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("pre image hook failed"), rc,
)
)
return rc
return 0
示例6: pre_run
def pre_run(self):
self._output.output("[%s|%s] %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("executing pre_run"),
)
)
# run outer chroot script
exec_script = self.metadata.get('outer_chroot_script')
if exec_script:
env = os.environ.copy()
env['CHROOT_DIR'] = self.source_dir
self._output.output("[%s|%s] %s: %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env=env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ChrootHandler"), darkred(self.spec_name),
_("outer chroot hook failed"), rc,
)
)
return rc
return 0
示例7: run
def run(self):
self._output.output("[%s|%s] %s" % (
blue("MirrorHandler"), darkred(self.spec_name),
_("mirroring running"),
)
)
# running sync
args = [self._mirror_syncer]
args.extend(self._mirror_syncer_builtin_args)
args.extend(self.metadata.get('extra_rsync_parameters', []))
args.append(self.source_dir + "/")
args.append(self.dest_dir + "/")
self._output.output("[%s|%s] %s: %s" % (
blue("MirrorHandler"), darkred(self.spec_name),
_("spawning"), " ".join(args),
)
)
rc = molecule.utils.exec_cmd(args)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("MirrorHandler"), darkred(self.spec_name),
_("mirroring failed"), rc,
)
)
return rc
self._output.output("[%s|%s] %s" % (
blue("MirrorHandler"), darkred(self.spec_name),
_("mirroring completed successfully"),
)
)
return 0
示例8: post_run
def post_run(self):
self._output.output("[%s|%s] %s" % (
blue("IsoHandler"), darkred(self.spec_name),
_("executing post_run"),
)
)
# run post iso script
exec_script = self.metadata.get('post_iso_script')
if exec_script:
env = os.environ.copy()
env['ISO_PATH'] = self.dest_iso
env['ISO_CHECKSUM_PATH'] = self.dest_iso + IsoHandler.MD5_EXT
self._output.output("[%s|%s] %s: %s" % (
blue("IsoHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env=env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("IsoHandler"), darkred(self.spec_name),
_("post iso hook failed"), rc,
)
)
return rc
return 0
示例9: _fill_image_file
def _fill_image_file(self):
"""
Fill image file (using _tmp_loop_device_fd) with either zeroes or
random data of image_mb size.
@raises IOError: if space is not enough
@raises OSError: well, sorry
"""
if self.randomize:
self._output.output("[%s|%s] %s => %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("generating random base image file"),
self.tmp_loop_device_file,
)
)
else:
self._output.output("[%s|%s] %s => %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("generating zeroed base image file"),
self.tmp_loop_device_file,
)
)
image_mb = self.image_mb
loop_f = os.fdopen(self._tmp_loop_device_fd, "wb")
self._tmp_loop_device_fd = None
arr = None
mb_bytes = ImageHandler.MB_IN_BYTES
while image_mb > 0:
image_mb -= 1
if self.randomize:
arr = array.array('c', os.urandom(mb_bytes))
else:
arr = array.array('c', chr(0)*mb_bytes)
arr.tofile(loop_f)
del arr
gc.collect()
# file self._tmp_loop_device_fd is closed here.
# no more writes needed
loop_f.flush()
loop_f.close()
# last but not least, tell the loop device that the file size changed
args = [ImageHandler.LOSETUP_EXEC, "-c", self.loop_device]
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("spawning"), " ".join(args),
)
)
rc = molecule.utils.exec_cmd(args)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("image file resize failed"), rc,
)
)
return rc
示例10: _kill_loop_device
def _kill_loop_device(self, preserve_loop_device_file=False):
kill_rc = 0
if self.image_mounted:
umounter = self.metadata.get(
'image_umounter',
ImageHandler.DEFAULT_IMAGE_UMOUNTER
)
args = umounter + [self.tmp_image_mount]
rc = molecule.utils.exec_cmd(args)
if rc != 0:
self._output.output(
"[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("unable to umount loop device"), self.loop_device,
)
)
kill_rc = rc
else:
self.image_mounted = False
if self.tmp_image_mount is not None:
try:
os.rmdir(self.tmp_image_mount)
except OSError:
pass
# kill loop device
if self.loop_device is not None:
rc = molecule.utils.exec_cmd([ImageHandler.LOSETUP_EXEC, "-d",
self.loop_device])
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("unable to kill loop device"), self.loop_device,
)
)
kill_rc = rc
else:
self.loop_device = None
if (self.tmp_loop_device_file is not None) and \
(not preserve_loop_device_file):
try:
os.remove(self.tmp_loop_device_file)
self.tmp_loop_device_file = None
except OSError as err:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("unable to remove temp. loop device file"),
err,
)
)
kill_rc = 1
return kill_rc
示例11: setup
def setup(self):
self.image_mb = self.metadata['image_mb']
if self.metadata.get('image_randomize') == "yes":
self.randomize = True
sts, loop_device = molecule.utils.exec_cmd_get_status_output(
[ImageHandler.LOSETUP_EXEC, "-f"])
if sts != 0:
# ouch
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("setup hook failed"), _("cannot setup loop device"),
)
)
return sts
try:
self._tmp_loop_device_fd, self.tmp_loop_device_file = \
tempfile.mkstemp(prefix="molecule", dir=self._config['tmp_dir'])
except (OSError, IOError,):
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("setup hook failed"), _("cannot create temporary file"),
)
)
return 1
# bind loop device
args = [ImageHandler.LOSETUP_EXEC, loop_device,
self.tmp_loop_device_file]
rc = molecule.utils.exec_cmd(args)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("setup hook failed"), _("cannot bind loop device"),
)
)
return 1
self.loop_device = loop_device
self.tmp_image_mount = molecule.utils.mkdtemp()
# setup metadata for next phases
self.metadata['ImageHandler_loop_device_file'] = \
self.tmp_loop_device_file
self.metadata['ImageHandler_tmp_image_mount'] = self.tmp_image_mount
self.metadata['ImageHandler_loop_device'] = self.loop_device
self.metadata['ImageHandler_kill_loop_device'] = self._kill_loop_device
return 0
示例12: run
def run(self):
self._output.output("[%s|%s] %s: %s => %s" % (
blue("IsoUnpackHandler"), darkred(self.spec_name),
_("iso unpacker running"), self.tmp_squash_mount,
self.metadata['chroot_unpack_path'],
)
)
def dorm():
if self.metadata['chroot_tmp_dir'] is not None:
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
# create chroot path
try:
rc = molecule.utils.copy_dir(self.tmp_squash_mount,
self.metadata['chroot_unpack_path'])
except:
dorm()
raise
if rc != 0:
dorm()
return rc
示例13: run
def run(self):
self._output.output("[%s|%s] %s: %s => %s" % (
blue("ImageIsoUnpackHandler"), darkred(self.spec_name),
_("iso unpacker running"), self.tmp_squash_mount,
self.metadata['chroot_unpack_path'],
)
)
def dorm():
if self.metadata['chroot_tmp_dir'] is not None:
shutil.rmtree(self.metadata['chroot_tmp_dir'], True)
# copy data into chroot, in our case, destination dir already
# exists, so copy_dir() is a bit tricky
try:
rc = molecule.utils.copy_dir_existing_dest(
self.tmp_squash_mount,
self.metadata['chroot_unpack_path']
)
except Exception:
dorm()
raise
if rc != 0:
dorm()
return rc
示例14: run
def run(self):
self._output.output("[%s|%s] %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("run hook called"),
)
)
# run pre image script
oexec_script = self.metadata.get('image_generator_script')
if oexec_script:
exec_script = oexec_script + [
self._tmp_image_file, str(self.metadata['image_mb']),
self.metadata['source_boot_directory'],
self.metadata['source_chroot']]
env = os.environ.copy()
env['PATHS_TO_REMOVE'] = ";".join(
self.metadata.get('paths_to_remove', []))
env['PATHS_TO_EMPTY'] = ";".join(
self.metadata.get('paths_to_empty', []))
env['RELEASE_STRING'] = self.metadata['release_string']
env['RELEASE_VERSION'] = self.metadata['release_version']
env['RELEASE_DESC'] = self.metadata['release_desc']
env['RELEASE_FILE'] = self.metadata['release_file']
env['IMAGE_NAME'] = self.metadata['image_name']
env['PACKAGES_TO_ADD'] = " ".join(self.metadata.get('packages_to_add', []))
env['PACKAGES_TO_REMOVE'] = " ".join(self.metadata.get('packages_to_remove', []))
env['DESTINATION_IMAGE_DIR'] = \
self.metadata['destination_image_directory']
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("spawning"), " ".join(exec_script),
)
)
rc = molecule.utils.exec_cmd(exec_script, env = env)
if rc != 0:
self._output.output("[%s|%s] %s: %s" % (
blue("ImageHandler"), darkred(self.spec_name),
_("image hook failed"), rc,
)
)
return rc
return 0
示例15: kill
def kill(self, success=True):
if not success:
self._run_error_script(self.source_dir, self.dest_dir, None)
self._output.output("[%s|%s] %s" % (
blue("ChrootHandler"),
darkred(self.spec_name), _("executing kill"),
)
)
return 0