diff --git a/image_creator/bundle_volume.py b/image_creator/bundle_volume.py index 232be5caf3310e019ffd3c1b8d4793a3e0ef8276..09373f99fe0a75091461ebc1af4203f0d8b10dee 100644 --- a/image_creator/bundle_volume.py +++ b/image_creator/bundle_volume.py @@ -213,7 +213,7 @@ class BundleVolume(object): self.meta = meta self.tmp = tmp - self.out.output('Searching for root device ...', False) + self.out.info('Searching for root device ...', False) root = get_root_partition() if root.startswith("UUID=") or root.startswith("LABEL="): @@ -389,7 +389,7 @@ class BundleVolume(object): # For partitions that are not mounted right now, we can simply dd them # into the image. for p in unmounted: - self.out.output('Cloning partition %d ... ' % p.num, False) + self.out.info('Cloning partition %d ... ' % p.num, False) dd('if=%s' % self.disk.device.path, 'of=%s' % image, 'count=%d' % (p.end - p.start + 1), 'conv=notrunc', 'seek=%d' % p.start, 'skip=%d' % p.start) @@ -413,8 +413,8 @@ class BundleVolume(object): '-s', 'LABEL', '-o', 'value', orig_dev[i]).stdout.strip() fs = filesystem[i].fs - self.out.output('Creating %s file system on partition %d ... ' - % (fs, i), False) + self.out.info('Creating %s file system on partition %d ... ' + % (fs, i), False) mkfs(fs, dev, uuid=uuid, label=label) # For ext[234] enable the default mount options @@ -520,7 +520,7 @@ class BundleVolume(object): # Check if the available space is enough to host the image dirname = os.path.dirname(image) - self.out.output("Examining available space ...", False) + self.out.info("Examining available space ...", False) if free_space(dirname) <= size: raise FatalError("Not enough space under %s to host the temporary " "image" % dirname) diff --git a/image_creator/dialog_main.py b/image_creator/dialog_main.py index fca07af6d7fa09d8fbe5f74b83f8dcc81b3b9e98..dadf4c0d31282cf1d2e35f1ef24b45fc7fff1974 100644 --- a/image_creator/dialog_main.py +++ b/image_creator/dialog_main.py @@ -205,11 +205,11 @@ def dialog_main(media, logfile, tmpdir, snapshot): while 1: try: out = CompositeOutput([log]) - out.output("Starting %s v%s ..." % (PROGNAME, version)) + out.info("Starting %s v%s ..." % (PROGNAME, version)) ret = create_image(d, media, out, tmpdir, snapshot) break except Reset: - log.output("Resetting everything ...") + log.info("Resetting everything ...") except FatalError as error: log.error(str(error)) diff --git a/image_creator/dialog_menu.py b/image_creator/dialog_menu.py index 6dd53707534f4ae26de4ad6b8a012bd172ff7138..0fd555f9bc6c99a7d43ca7b24e41a607a1467878 100644 --- a/image_creator/dialog_menu.py +++ b/image_creator/dialog_menu.py @@ -160,7 +160,7 @@ def upload_image(session): "Calculating block hashes", "Uploading missing blocks") # Upload md5sum file - out.output("Uploading md5sum file ...") + out.info("Uploading md5sum file ...") md5str = "%s %s\n" % (session['checksum'], filename) kamaki.upload(StringIO.StringIO(md5str), size=len(md5str), remote_path="%s.md5sum" % filename) @@ -247,21 +247,20 @@ def register_image(session): out.append(gauge) try: try: - out.output("Registering %s image with the cloud ..." % - img_type) + out.info("Registering %s image with the cloud ..." % img_type) kamaki = Kamaki(session['account'], out) result = kamaki.register(name, session['pithos_uri'], metadata, is_public) out.success('done') # Upload metadata file - out.output("Uploading metadata file ...") + out.info("Uploading metadata file ...") metastring = unicode(json.dumps(result, ensure_ascii=False)) kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), remote_path="%s.meta" % session['upload']) out.success("done") if is_public: - out.output("Sharing metadata and md5sum files ...") + out.info("Sharing metadata and md5sum files ...") kamaki.share("%s.meta" % session['upload']) kamaki.share("%s.md5sum" % session['upload']) out.success('done') diff --git a/image_creator/dialog_util.py b/image_creator/dialog_util.py index 99df808c00f5a243157632aa50be53ea1c011eb5..6e1e95920ff97c50f17097546288aa4d16fc8ac2 100644 --- a/image_creator/dialog_util.py +++ b/image_creator/dialog_util.py @@ -214,13 +214,13 @@ def extract_image(session): image.dump(path) # Extract metadata file - out.output("Extracting metadata file ...") + out.info("Extracting metadata file ...") with open('%s.meta' % path, 'w') as f: f.write(extract_metadata_string(session)) out.success('done') # Extract md5sum file - out.output("Extracting md5sum file ...") + out.info("Extracting md5sum file ...") md5str = "%s %s\n" % (session['checksum'], name) with open('%s.md5sum' % path, 'w') as f: f.write(md5str) diff --git a/image_creator/dialog_wizard.py b/image_creator/dialog_wizard.py index c5f514ea95558963e1ba9546f148d2ad13cc0e3f..70a5f572006bc80b7140bb13b5820491907454b6 100644 --- a/image_creator/dialog_wizard.py +++ b/image_creator/dialog_wizard.py @@ -463,9 +463,9 @@ def create_image(session, answers): # MD5 session['checksum'] = image.md5() - image.out.output() + image.out.info() try: - image.out.output("Uploading image to the cloud:") + image.out.info("Uploading image to the cloud:") account = Kamaki.get_account(answers['Cloud']) assert account, "Cloud: %s is not valid" % answers['Cloud'] kamaki = Kamaki(account, image.out) @@ -478,33 +478,33 @@ def create_image(session, answers): "(1/3) Calculating block hashes", "(2/3) Uploading image blocks") - image.out.output("(3/3) Uploading md5sum file ...", False) + image.out.info("(3/3) Uploading md5sum file ...", False) md5sumstr = '%s %s\n' % (session['checksum'], name) kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr), remote_path="%s.%s" % (name, 'md5sum')) image.out.success('done') - image.out.output() + image.out.info() - image.out.output('Registering %s image with the cloud ...' % - answers['RegistrationType'].lower(), False) + image.out.info('Registering %s image with the cloud ...' % + answers['RegistrationType'].lower(), False) result = kamaki.register(answers['ImageName'], remote, metadata, answers['RegistrationType'] == "Public") image.out.success('done') - image.out.output("Uploading metadata file ...", False) + image.out.info("Uploading metadata file ...", False) metastring = unicode(json.dumps(result, ensure_ascii=False)) kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), remote_path="%s.%s" % (name, 'meta')) image.out.success('done') if answers['RegistrationType'] == "Public": - image.out.output("Sharing md5sum file ...", False) + image.out.info("Sharing md5sum file ...", False) kamaki.share("%s.md5sum" % name) image.out.success('done') - image.out.output("Sharing metadata file ...", False) + image.out.info("Sharing metadata file ...", False) kamaki.share("%s.meta" % name) image.out.success('done') - image.out.output() + image.out.info() except ClientError as error: raise FatalError("Storage service client: %d %s" % diff --git a/image_creator/disk.py b/image_creator/disk.py index b8ad44194b06490ece40a04982a8e34a410fee4d..7cae1d39aff0ab59f192e48faab9b40a561bcb9a 100644 --- a/image_creator/disk.py +++ b/image_creator/disk.py @@ -130,7 +130,7 @@ class Disk(object): if self._file is not None: return self._file - self.out.output("Examining source media `%s' ..." % self.source, False) + self.out.info("Examining source media `%s' ..." % self.source, False) mode = os.stat(self.source).st_mode if stat.S_ISDIR(mode): self.out.success('looks like a directory') @@ -159,7 +159,7 @@ class Disk(object): # Examine media file info = image_info(self.file) - self.out.output("Snapshotting media source ...", False) + self.out.info("Snapshotting media source ...", False) # Create a qcow2 snapshot for image files that are not raw if info['format'] != 'raw': diff --git a/image_creator/image.py b/image_creator/image.py index 7098062da0c37c74d1ffa47f7f53c7d74661bde0..91263cfa6c27bf4838e5a925e28506a5af2e1347 100644 --- a/image_creator/image.py +++ b/image_creator/image.py @@ -85,7 +85,7 @@ class Image(object): self.enable_guestfs() - self.out.output('Inspecting Operating System ...', False) + self.out.info('Inspecting Operating System ...', False) roots = self.g.inspect_os() if len(roots) == 0 or len(roots) > 1: @@ -149,7 +149,7 @@ class Image(object): # process has opened pipes. Since the recovery process is an optional # feature of libguestfs, it's better to disable it. if self.check_guestfs_version(1, 17, 14) >= 0: - self.out.output("Enabling recovery process ...", False) + self.out.info("Enabling recovery process ...", False) self.g.set_recovery_proc(1) self.out.success('done') else: @@ -158,7 +158,7 @@ class Image(object): # self.g.set_trace(1) # self.g.set_verbose(1) - self.out.output('Launching helper VM (may take a while) ...', False) + self.out.info('Launching helper VM (may take a while) ...', False) # self.progressbar = self.out.Progress(100, "Launching helper VM", # "percent") # eh = self.g.set_event_callback(self.progress_callback, @@ -187,7 +187,7 @@ class Image(object): self.out.warn("Guestfs is already disabled") return - self.out.output("Shutting down helper VM ...", False) + self.out.info("Shutting down helper VM ...", False) self.g.sync() # guestfs_shutdown which is the preferred way to shutdown the backend # process was introduced in version 1.19.16 diff --git a/image_creator/main.py b/image_creator/main.py index 7b169e048d6e7079803a4536f15cbd9a78de7af7..ec18bd403860a1ba1a6895ae6e78683fbdaecdcb 100644 --- a/image_creator/main.py +++ b/image_creator/main.py @@ -220,8 +220,8 @@ def image_creator(): SimpleOutput(False) title = 'snf-image-creator %s' % version - out.output(title) - out.output('=' * len(title)) + out.info(title) + out.info('=' * len(title)) if os.geteuid() != 0: raise FatalError("You must run %s as root" @@ -317,15 +317,15 @@ def image_creator(): if options.print_syspreps: image.os.print_syspreps() - out.output() + out.info() if options.print_sysprep_params: image.os.print_sysprep_params() - out.output() + out.info() if options.print_metadata: image.os.print_metadata() - out.output() + out.info() if options.outfile is None and not options.upload: return 0 @@ -335,7 +335,7 @@ def image_creator(): image.os.install_virtio_drivers() if len(options.host_run) != 0: - out.output("Running scripts on the input media:") + out.info("Running scripts on the input media:") mpoint = tempfile.mkdtemp() try: image.mount(mpoint) @@ -346,8 +346,8 @@ def image_creator(): cnt = 1 for script in options.host_run: script = os.path.abspath(script) - out.output(("(%d/%d)" % (cnt, size)).ljust(7), False) - out.output("Running `%s'" % script) + out.info(("(%d/%d)" % (cnt, size)).ljust(7), False) + out.info("Running `%s'" % script) ret = subprocess.Popen([script], cwd=mpoint).wait() if ret != 0: raise FatalError("Script: `%s' failed (rc=%d)" % @@ -357,7 +357,7 @@ def image_creator(): while not image.umount(): out.warn("Unable to umount the media. Retrying ...") time.sleep(1) - out.output() + out.info() finally: os.rmdir @@ -379,21 +379,21 @@ def image_creator(): if options.outfile is not None: image.dump(options.outfile) - out.output('Dumping metadata file ...', False) + out.info('Dumping metadata file ...', False) with open('%s.%s' % (options.outfile, 'meta'), 'w') as f: f.write(metastring) out.success('done') - out.output('Dumping md5sum file ...', False) + out.info('Dumping md5sum file ...', False) with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f: f.write('%s %s\n' % (checksum, os.path.basename(options.outfile))) out.success('done') - out.output() + out.info() try: if options.upload: - out.output("Uploading image to the storage service:") + out.info("Uploading image to the storage service:") with image.raw_device() as raw: with open(raw, 'rb') as f: remote = kamaki.upload( @@ -401,42 +401,42 @@ def image_creator(): "(1/3) Calculating block hashes", "(2/3) Uploading missing blocks") - out.output("(3/3) Uploading md5sum file ...", False) + out.info("(3/3) Uploading md5sum file ...", False) md5sumstr = '%s %s\n' % (checksum, os.path.basename(options.upload)) kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr), remote_path="%s.%s" % (options.upload, 'md5sum')) out.success('done') - out.output() + out.info() if options.register: img_type = 'public' if options.public else 'private' - out.output('Registering %s image with the compute service ...' - % img_type, False) + out.info('Registering %s image with the compute service ...' + % img_type, False) result = kamaki.register(options.register, remote, image.meta, options.public) out.success('done') - out.output("Uploading metadata file ...", False) + out.info("Uploading metadata file ...", False) metastring = unicode(json.dumps(result, ensure_ascii=False)) kamaki.upload(StringIO.StringIO(metastring), size=len(metastring), remote_path="%s.%s" % (options.upload, 'meta')) out.success('done') if options.public: - out.output("Sharing md5sum file ...", False) + out.info("Sharing md5sum file ...", False) kamaki.share("%s.md5sum" % options.upload) out.success('done') - out.output("Sharing metadata file ...", False) + out.info("Sharing metadata file ...", False) kamaki.share("%s.meta" % options.upload) out.success('done') - out.output() + out.info() except ClientError as e: raise FatalError("Service client: %d %s" % (e.status, e.message)) finally: - out.output('cleaning up ...') + out.info('cleaning up ...') disk.cleanup() out.success("snf-image-creator exited without errors") diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index 0b74649e740ac09d758c55577302dabf2bda303d..b4195dd8126c7aeab6e034396b430a85df7191ab 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -88,7 +88,7 @@ def sysprep(message, enabled=True, **kwargs): @wraps(method) def inner(self, print_message=True): if print_message: - self.out.output(message) + self.out.info(message) return method(self) return inner @@ -306,21 +306,21 @@ class OSBase(object): if self.image.is_unsupported(): return - self.out.output('Running OS inspection:') + self.out.info('Running OS inspection:') with self.mount(readonly=True, silent=True): self._do_inspect() - self.out.output() + self.out.info() def collect_metadata(self): """Collect metadata about the OS""" - self.out.output('Collecting image metadata ...', False) + self.out.info('Collecting image metadata ...', False) with self.mount(readonly=True, silent=True): self._do_collect_metadata() self.out.success('done') - self.out.output() + self.out.info() def list_syspreps(self): """Returns a list of sysprep objects""" @@ -378,11 +378,11 @@ class OSBase(object): def print_metadata(self): """Print the image metadata""" - self.out.output("Detected image metadata:") + self.out.info("Detected image metadata:") col_width = max(len(key) for key in self.meta) + 2 for key, val in self.meta.items(): - self.out.output("%s %s" % (key.ljust(col_width), val)) + self.out.info("%s %s" % (key.ljust(col_width), val)) def print_syspreps(self): """Print enabled and disabled system preparation operations""" @@ -396,34 +396,34 @@ class OSBase(object): wrapper.initial_indent = '\t' wrapper.width = 72 - self.out.output("Enabled system preparation operations:") + self.out.info("Enabled system preparation operations:") if len(enabled) == 0: - self.out.output("(none)") + self.out.info("(none)") else: for sysprep in enabled: name = sysprep.__name__.replace('_', '-')[1:] descr = wrapper.fill(textwrap.dedent(sysprep.__doc__)) - self.out.output(' %s:\n%s\n' % (name, descr)) + self.out.info(' %s:\n%s\n' % (name, descr)) - self.out.output("Disabled system preparation operations:") + self.out.info("Disabled system preparation operations:") if len(disabled) == 0: - self.out.output("(none)") + self.out.info("(none)") else: for sysprep in disabled: name = sysprep.__name__.replace('_', '-')[1:] descr = wrapper.fill(textwrap.dedent(sysprep.__doc__)) - self.out.output(' %s:\n%s\n' % (name, descr)) + self.out.info(' %s:\n%s\n' % (name, descr)) def print_sysprep_params(self): """Print the system preparation parameter the user may use""" - self.out.output("System preparation parameters:") - self.out.output() + self.out.info("System preparation parameters:") + self.out.info() public_params = [(n, p) for n, p in self.sysprep_params.items() if not p.hidden] if len(public_params) == 0: - self.out.output("(none)") + self.out.info("(none)") return wrapper = textwrap.TextWrapper() @@ -433,20 +433,20 @@ class OSBase(object): for name, param in public_params: if param.hidden: continue - self.out.output("NAME:".ljust(13) + name) - self.out.output(wrapper.fill("DESCRIPTION:".ljust(13) + - "%s" % param.description)) - self.out.output("TYPE:".ljust(13) + "%s%s" % - ("list:" if param.is_list else "", param.type)) - self.out.output("VALUE:".ljust(13) + - ("\n".ljust(14).join(param.value) if param.is_list - else param.value)) - self.out.output() + self.out.info("NAME:".ljust(13) + name) + self.out.info(wrapper.fill("DESCRIPTION:".ljust(13) + + "%s" % param.description)) + self.out.info("TYPE:".ljust(13) + "%s%s" % + ("list:" if param.is_list else "", param.type)) + self.out.info("VALUE:".ljust(13) + + ("\n".ljust(14).join(param.value) if param.is_list + else param.value)) + self.out.info() def do_sysprep(self): """Prepare system for image creation.""" - self.out.output('Preparing system for image creation:') + self.out.info('Preparing system for image creation:') if self.image.is_unsupported(): self.out.warn( @@ -458,7 +458,7 @@ class OSBase(object): cnt = 0 def exec_sysprep(cnt, size, task): - self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False) + self.out.info(('(%d/%d)' % (cnt, size)).ljust(7), False) task() del self._sysprep_tasks[task.__name__] @@ -471,7 +471,7 @@ class OSBase(object): cnt += 1 exec_sysprep(cnt, size, task) - self.out.output() + self.out.info() @sysprep('Shrinking image (may take a while)', nomount=True) def _shrink(self): @@ -487,7 +487,7 @@ class OSBase(object): """Returns a context manager for mounting an image""" parent = self - output = lambda msg='', nl=True: None if silent else self.out.output + output = lambda msg='', nl=True: None if silent else self.out.info success = lambda msg='', nl=True: None if silent else self.out.success warn = lambda msg='', nl=True: None if silent else self.out.warn diff --git a/image_creator/os_type/freebsd.py b/image_creator/os_type/freebsd.py index 2ec89e8d27d2d7f90161b67305a63705f764d6d3..6ff7f355a3a73e62a79dac9721040db616f42e20 100644 --- a/image_creator/os_type/freebsd.py +++ b/image_creator/os_type/freebsd.py @@ -77,7 +77,7 @@ class Freebsd(Bsd): def _do_inspect(self): """Run various diagnostics to check if media is supported""" - self.out.output('Checking partition table type...', False) + self.out.info('Checking partition table type...', False) ptype = self.image.g.part_get_parttype(self.image.guestfs_device) if ptype != 'gpt': self.out.warn("partition table type is: `%s'" % ptype) diff --git a/image_creator/os_type/linux.py b/image_creator/os_type/linux.py index 631fd72645202b76fcfd5d8de3855730be0d25fb..293dcf383bc6ae9647951870d88974581ac13181 100644 --- a/image_creator/os_type/linux.py +++ b/image_creator/os_type/linux.py @@ -320,13 +320,13 @@ class Linux(Unix): def _do_inspect(self): """Run various diagnostics to check if media is supported""" - self.out.output( + self.out.info( 'Checking if the media contains logical volumes (LVM)...', False) has_lvm = True if len(self.image.g.lvs()) else False if has_lvm: - self.out.output() + self.out.info() self.image.set_unsupported('The media contains logical volumes') else: self.out.success('no') diff --git a/image_creator/os_type/windows/__init__.py b/image_creator/os_type/windows/__init__.py index fd1b93926c01fb27583e8358c86811a3b6c9529f..388d88aeb18db41bd3efa95a5ec46e0ed71aa502 100644 --- a/image_creator/os_type/windows/__init__.py +++ b/image_creator/os_type/windows/__init__.py @@ -271,7 +271,7 @@ class Windows(OSBase): self.registry = Registry(self.image) with self.mount(readonly=True, silent=True): - self.out.output("Checking media state ...", False) + self.out.info("Checking media state ...", False) # Enumerate the windows users (self.usernames, @@ -453,7 +453,7 @@ class Windows(OSBase): self.out.warn("Not enough available space to shrink the image!") return - self.out.output("\tReclaiming %dMB ..." % querymax) + self.out.info("\tReclaiming %dMB ..." % querymax) cmd = ( r'cmd /Q /V:ON /C "SET SCRIPT=%TEMP%\QUERYMAX_%RANDOM%.TXT & ' + @@ -473,14 +473,14 @@ class Windows(OSBase): for line in stdout.splitlines(): if line.find("%d" % querymax) >= 0: - self.out.output(" %s" % line) + self.out.info(" %s" % line) self.shrinked = True def do_sysprep(self): """Prepare system for image creation.""" - self.out.output('Preparing system for image creation:') + self.out.info('Preparing system for image creation:') # Check if winexe is installed if not WinEXE.is_installed(): @@ -506,7 +506,7 @@ class Windows(OSBase): timeout = self.sysprep_params['boot_timeout'].value shutdown_timeout = self.sysprep_params['shutdown_timeout'].value - self.out.output("Preparing media for boot ...", False) + self.out.info("Preparing media for boot ...", False) with self.mount(readonly=False, silent=True): @@ -560,13 +560,13 @@ class Windows(OSBase): self.image.disable_guestfs() booted = False try: - self.out.output("Starting windows VM ...", False) + self.out.info("Starting windows VM ...", False) self.vm.start() try: self.out.success("started (console on VNC display: %d)" % self.vm.display) - self.out.output("Waiting for OS to boot ...", False) + self.out.info("Waiting for OS to boot ...", False) if not self.vm.wait_on_serial(timeout): raise FatalError("Windows VM booting timed out!") self.out.success('done') @@ -577,17 +577,17 @@ class Windows(OSBase): # conditions time.sleep(5) - self.out.output("Checking connectivity to the VM ...", False) + self.out.info("Checking connectivity to the VM ...", False) self._check_connectivity() # self.out.success('done') - # self.out.output("Disabling automatic logon ...", False) + # self.out.info("Disabling automatic logon ...", False) self._disable_autologon() self.out.success('done') self._exec_sysprep_tasks() - self.out.output("Waiting for windows to shut down ...", False) + self.out.info("Waiting for windows to shut down ...", False) (_, stderr, rc) = self.vm.wait(shutdown_timeout) if rc != 0 or "terminating on signal" in stderr: raise FatalError("Windows VM died unexpectedly!\n\n" @@ -601,7 +601,7 @@ class Windows(OSBase): finally: self.image.enable_guestfs() - self.out.output("Reverting media boot preparations ...", False) + self.out.info("Reverting media boot preparations ...", False) with self.mount(readonly=False, silent=True, fatal=False): if not self.ismounted: @@ -640,11 +640,11 @@ class Windows(OSBase): cnt = 0 for task in enabled: cnt += 1 - self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False) + self.out.info(('(%d/%d)' % (cnt, size)).ljust(7), False) task() del self._sysprep_tasks[task.__name__] - self.out.output("Sending shut down command ...", False) + self.out.info("Sending shut down command ...", False) if not self.sysprepped: self._shutdown() self.out.success("done") @@ -769,10 +769,10 @@ class Windows(OSBase): log.file.write("STDERR:\n%s\n" % stderr) finally: log.close() - self.out.output("failed! See: `%s' for the full output" % log.name) + self.out.info("failed! See: `%s' for the full output" % log.name) if i < retries - 1: wait = timeout.pop() - self.out.output("retrying in %d seconds ..." % wait, False) + self.out.info("retrying in %d seconds ..." % wait, False) time.sleep(wait) raise FatalError("Connection to the Windows VM failed after %d retries" @@ -858,8 +858,8 @@ class Windows(OSBase): if len(drvs) == 0: del collection[drv_type] - self.out.output('Found %d valid driver%s' % - (num, "s" if num != 1 else "")) + self.out.info('Found %d valid driver%s' % + (num, "s" if num != 1 else "")) return collection def install_virtio_drivers(self, upgrade=True): @@ -871,7 +871,7 @@ class Windows(OSBase): if not dirname: raise FatalError('No directory hosting the VirtIO drivers defined') - self.out.output('Installing VirtIO drivers:') + self.out.info('Installing VirtIO drivers:') valid_drvs = self._fetch_virtio_drivers(dirname) if not len(valid_drvs): @@ -890,7 +890,7 @@ class Windows(OSBase): self._cleanup('virtio') self.out.success("VirtIO drivers were successfully installed") - self.out.output() + self.out.info() def _upload_virtio_drivers(self, dirname, drvs, delete_old=True): """Upload the VirtIO drivers and installation scripts to the media. @@ -1008,7 +1008,7 @@ class Windows(OSBase): timeout = self.sysprep_params['boot_timeout'].value shutdown_timeout = self.sysprep_params['shutdown_timeout'].value virtio_timeout = self.sysprep_params['virtio_timeout'].value - self.out.output("Starting Windows VM ...", False) + self.out.info("Starting Windows VM ...", False) booted = False try: if old_windows: @@ -1020,16 +1020,16 @@ class Windows(OSBase): self.out.success("started (console on VNC display: %d)" % self.vm.display) - self.out.output("Waiting for Windows to boot ...", False) + self.out.info("Waiting for Windows to boot ...", False) if not self.vm.wait_on_serial(timeout): raise FatalError("Windows VM booting timed out!") self.out.success('done') booted = True - self.out.output("Installing new drivers ...", False) + self.out.info("Installing new drivers ...", False) if not self.vm.wait_on_serial(virtio_timeout): raise FatalError("Windows VirtIO installation timed out!") self.out.success('done') - self.out.output('Shutting down ...', False) + self.out.info('Shutting down ...', False) (_, stderr, rc) = self.vm.wait(shutdown_timeout) if rc != 0 or "terminating on signal" in stderr: raise FatalError("Windows VM died unexpectedly!\n\n" @@ -1051,7 +1051,7 @@ class Windows(OSBase): # Hopefully restart in safe mode. Newer windows will not boot from # a viostor device unless we initially start them in safe mode try: - self.out.output('Rebooting Windows VM in safe mode ...', False) + self.out.info('Rebooting Windows VM in safe mode ...', False) self.vm.start() (_, stderr, rc) = self.vm.wait(timeout + shutdown_timeout) if rc != 0 or "terminating on signal" in stderr: diff --git a/image_creator/os_type/windows/vm.py b/image_creator/os_type/windows/vm.py index 8fd1b0f480dc9809aacc101d90890f9f05ef0907..fc884ec1ab7f6efa1e603d724530c57fb7ee3650 100644 --- a/image_creator/os_type/windows/vm.py +++ b/image_creator/os_type/windows/vm.py @@ -249,8 +249,6 @@ class VM(object): fname = log.name log.close() - # self.out.output("Command: `%s' failed (rc=%d). Reason: %s" % - # (command, rc, reason)) raise FatalError("Command: `%s' failed (rc=%d). See: %s" % (command, rc, fname)) diff --git a/image_creator/output/__init__.py b/image_creator/output/__init__.py index f9b5b2d7c0a9bb8eae74377abc813f9ea56ecfd2..8ca8963585319cdc3ab5bb0f9a010a8d35aa235c 100644 --- a/image_creator/output/__init__.py +++ b/image_creator/output/__init__.py @@ -36,7 +36,7 @@ class Output(object): """Print msg after an action is completed""" pass - def output(self, msg='', new_line=True): + def info(self, msg='', new_line=True): """Print normal program output""" pass @@ -61,7 +61,7 @@ class Output(object): def __init__(self, size, title, bar_type='default'): self.size = size self.bar_type = bar_type - self.parent.output("%s ..." % title, False) + self.parent.info("%s ..." % title, False) def goto(self, dest): """Move progress to a specific position""" diff --git a/image_creator/output/cli.py b/image_creator/output/cli.py index 3ca723dea77eb25b888d27dcefe716e2f7ddfeea..f22f1a12c504e83f9805171655f0491e34574387 100644 --- a/image_creator/output/cli.py +++ b/image_creator/output/cli.py @@ -24,68 +24,48 @@ from colors import red, green, yellow from progress.bar import Bar -def output(msg, new_line, decorate, stream): +def write(msg, new_line, decorate, stream): """Print a message""" nl = "\n" if new_line else ' ' stream.write(decorate(msg) + nl) -def error(msg, new_line, colored, stream): - """Print an error message""" - color = red if colored else lambda x: x - output("Error: %s" % msg, new_line, color, stream) - - -def warn(msg, new_line, colored, stream): - """Print a warning""" - color = yellow if colored else lambda x: x - output("Warning: %s" % msg, new_line, color, stream) - - -def success(msg, new_line, colored, stream): - """Print a success message""" - color = green if colored else lambda x: x - output(msg, new_line, color, stream) - - -def clear(stream): - """Clears the terminal screen.""" - if stream.isatty(): - stream.write('\033[H\033[2J') - - class SilentOutput(Output): """Silent Output class. Only Errors are printed""" - pass - -class SimpleOutput(Output): - """Print messages but not progress bars. Progress bars are treated as - output messages. The user gets informed when the action begins and when it - ends, but no progress is shown in between.""" def __init__(self, colored=True, stream=None): self.colored = colored self.stream = sys.stderr if stream is None else stream def error(self, msg, new_line=True): """Print an error""" - error(msg, new_line, self.colored, self.stream) + color = red if self.colored else lambda x: x + write("Error: %s" % msg, new_line, color, self.stream) + + +class SimpleOutput(SilentOutput): + """Print messages but not progress bars. Progress bars are treated as + output messages. The user gets informed when the action begins and when it + ends, but no progress is shown in between.""" def warn(self, msg, new_line=True): """Print a warning""" - warn(msg, new_line, self.colored, self.stream) + color = yellow if self.colored else lambda x: x + write("Warning: %s" % msg, new_line, color, self.stream) def success(self, msg, new_line=True): """Print msg after an action is completed""" - success(msg, new_line, self.colored, self.stream) + color = green if self.colored else lambda x: x + write(msg, new_line, color, self.stream) - def output(self, msg='', new_line=True): + def info(self, msg='', new_line=True): """Print msg as normal program output""" - output(msg, new_line, lambda x: x, self.stream) + write(msg, new_line, lambda x: x, self.stream) def clear(self): """Clear the screen""" - clear(self.stream) + if self.stream.isatty(): + self.stream.write('\033[H\033[2J') class OutputWthProgress(SimpleOutput): @@ -118,7 +98,7 @@ class OutputWthProgress(SimpleOutput): def success(self, result): """Print result after progress has finished""" - self.parent.output("\r%s ...\033[K" % self.title, False) + self.parent.info("\r%s ...\033[K" % self.title, False) self.parent.success(result) # vim: set sta sts=4 shiftwidth=4 sw=4 et ai : diff --git a/image_creator/output/composite.py b/image_creator/output/composite.py index c5fc7f33b1bfcc409f50cbac21335159df79070b..fbcb76d1c9d9165fa30a657f8d1605fa94adc499 100644 --- a/image_creator/output/composite.py +++ b/image_creator/output/composite.py @@ -51,10 +51,10 @@ class CompositeOutput(Output, list): for out in self: out.success(msg, new_line) - def output(self, msg='', new_line=True): + def info(self, msg='', new_line=True): """Call the output method of each of the output instances""" for out in self: - out.output(msg, new_line) + out.info(msg, new_line) def cleanup(self): """Call the cleanup method of each of the output instances""" diff --git a/image_creator/output/dialog.py b/image_creator/output/dialog.py index 6e7bf9a913276c0ae691e24768c9f9993f41f05f..8fb93cc1eb3fc51cf549ad4aea944584c07d7a75 100644 --- a/image_creator/output/dialog.py +++ b/image_creator/output/dialog.py @@ -41,7 +41,7 @@ class GaugeOutput(Output): flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) - def output(self, msg='', new_line=True): + def info(self, msg='', new_line=True): """Print msg as normal output""" self.msg = msg self.percent = 0 @@ -107,7 +107,7 @@ class InfoBoxOutput(Output): self.height = height self.d.infobox(self.msg, title=self.title) - def output(self, msg='', new_line=True): + def info(self, msg='', new_line=True): """Print msg as normal output""" nl = '\n' if new_line else '' self.msg += "%s%s" % (msg, nl) @@ -122,11 +122,11 @@ class InfoBoxOutput(Output): def success(self, result, new_line=True): """Print result after an action is completed successfully""" - self.output(result, new_line) + self.info(result, new_line) def warn(self, msg, new_line=True): """Print a warning message""" - self.output("Warning: %s" % msg, new_line) + self.info("Warning: %s" % msg, new_line) def finalize(self): """Finalize the output. After this is called, the InfoboxOutput diff --git a/image_creator/rsync.py b/image_creator/rsync.py index e428c72d0eef2337a7c38229350022229e309275..99c14d1a5cebaf7b7f7707943dd0cc1d05a05fda 100644 --- a/image_creator/rsync.py +++ b/image_creator/rsync.py @@ -76,8 +76,8 @@ class Rsync: for i in self._exclude: cmd.extend(['--exclude', i]) - self._out.output("Calculating total number of %s files ..." % slabel, - False) + self._out.info("Calculating total number of %s files ..." % slabel, + False) # If you don't specify a destination, rsync will list the source files. dry_run = subprocess.Popen(cmd + [src], shell=False,