summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-05-21 14:29:28 +0300
committerLars Wirzenius <liw@liw.fi>2017-05-21 14:29:28 +0300
commite1603a745086902b1c5163da6513c216bb859879 (patch)
tree6d1796ba6898fab5aa55ec1528df3d50463c594b
parent8f7f06ae7ae81924ddf61fa5f69c11298fe3eac5 (diff)
downloadvmdb2-e1603a745086902b1c5163da6513c216bb859879.tar.gz
Make progress reporting prettier, and not be errors anymore
-rw-r--r--NEWS2
-rw-r--r--vmdb/__init__.py2
-rw-r--r--vmdb/app.py5
-rw-r--r--vmdb/plugins/apt_plugin.py2
-rw-r--r--vmdb/plugins/chroot_plugin.py4
-rw-r--r--vmdb/plugins/debootstrap_plugin.py2
-rw-r--r--vmdb/plugins/echo_plugin.py4
-rw-r--r--vmdb/plugins/error_plugin.py6
-rw-r--r--vmdb/plugins/mkfs_plugin.py2
-rw-r--r--vmdb/plugins/mkimg_plugin.py2
-rw-r--r--vmdb/plugins/mount_plugin.py4
-rw-r--r--vmdb/plugins/partition_plugin.py6
-rw-r--r--vmdb/runcmd.py12
13 files changed, 28 insertions, 25 deletions
diff --git a/NEWS b/NEWS
index 4dabacc..03bfe75 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ NEWS for vmdb2, the Debian disk image builder
Version 0.2+git, not yet released
---------------------------------
+* Some prettification of progress reporting, plus progress reports are
+ no longer logged as errors.
Version 0.2, released 2017-05-14
---------------------------------
diff --git a/vmdb/__init__.py b/vmdb/__init__.py
index 7fc079d..758a900 100644
--- a/vmdb/__init__.py
+++ b/vmdb/__init__.py
@@ -24,5 +24,5 @@ from .step_list import (
NoMatchingRunner,
StepError,
)
-from .runcmd import runcmd, set_runcmd_progress, progress
+from .runcmd import runcmd, set_runcmd_progress, progress, error
from .app import Vmdb2
diff --git a/vmdb/app.py b/vmdb/app.py
index 1ef6a6c..6ef5df2 100644
--- a/vmdb/app.py
+++ b/vmdb/app.py
@@ -76,7 +76,7 @@ class Vmdb2(cliapp.Application):
return progress
def load_spec_file(self, filename):
- vmdb.progress('Load spec file {}\n'.format(filename))
+ vmdb.progress('Load spec file {}'.format(filename))
with open(filename) as f:
return yaml.safe_load(f)
@@ -104,8 +104,7 @@ class Vmdb2(cliapp.Application):
self.progress['curstep'] = self.format_step(runner, step)
method(expanded_step, self.settings, state)
except Exception as e:
- logging.error('ERROR: %s', str(e), exc_info=True)
- self.progress.error('ERROR: {}\n'.format(str(e)))
+ self.error(str(e))
core_meltdown = True
if not keep_going:
break
diff --git a/vmdb/plugins/apt_plugin.py b/vmdb/plugins/apt_plugin.py
index 9da8ef4..549ba4f 100644
--- a/vmdb/plugins/apt_plugin.py
+++ b/vmdb/plugins/apt_plugin.py
@@ -44,7 +44,7 @@ class AptStepRunner(vmdb.StepRunnerInterface):
fstag = step['fs-tag']
mount_point = state.mounts[fstag]
vmdb.progress(
- 'Install package {} to filesystem at {} ({})\n'.format(
+ 'Install package {} to filesystem at {} ({})'.format(
package, mount_point, fstag))
vmdb.runcmd(
['chroot', mount_point,
diff --git a/vmdb/plugins/chroot_plugin.py b/vmdb/plugins/chroot_plugin.py
index cf61d9b..7be6992 100644
--- a/vmdb/plugins/chroot_plugin.py
+++ b/vmdb/plugins/chroot_plugin.py
@@ -45,7 +45,7 @@ class ChrootStepRunner(vmdb.StepRunnerInterface):
mount_point = state.mounts[fs_tag]
vmdb.progress(
- 'chroot {} to {}\n'.format(mount_point, ' '.join(shell.split('\n'))))
+ 'chroot {} to {}'.format(mount_point, ' '.join(shell.split('\n'))))
vmdb.runcmd(['chroot', mount_point, 'sh', '-c', shell])
@@ -59,7 +59,7 @@ class ShellStepRunner(vmdb.StepRunnerInterface):
fs_tag = step['root-fs']
vmdb.progress(
- 'run shell {}\n'.format(' '.join(shell.split('\n'))))
+ 'run shell {}'.format(' '.join(shell.split('\n'))))
env = dict(os.environ)
env['ROOT'] = state.mounts[fs_tag]
vmdb.runcmd(['sh', '-c', shell], env=env)
diff --git a/vmdb/plugins/debootstrap_plugin.py b/vmdb/plugins/debootstrap_plugin.py
index 824c42c..0278cf1 100644
--- a/vmdb/plugins/debootstrap_plugin.py
+++ b/vmdb/plugins/debootstrap_plugin.py
@@ -47,5 +47,5 @@ class DebootstrapStepRunner(vmdb.StepRunnerInterface):
if not (suite and tag and target and mirror):
raise Exception('missing arg for debootstrap step')
vmdb.progress(
- 'Debootstrap {} {} {}\n'.format(suite, target, mirror))
+ 'Debootstrap {} {} {}'.format(suite, target, mirror))
vmdb.runcmd(['debootstrap', suite, target, mirror])
diff --git a/vmdb/plugins/echo_plugin.py b/vmdb/plugins/echo_plugin.py
index faa6b2d..26f8bab 100644
--- a/vmdb/plugins/echo_plugin.py
+++ b/vmdb/plugins/echo_plugin.py
@@ -38,10 +38,10 @@ class EchoStepRunner(vmdb.StepRunnerInterface):
def run(self, step, settings, state):
text = step['echo']
- vmdb.progress('{}\n'.format(text))
+ vmdb.progress('{}'.format(text))
def teardown(self, step, settings, state):
if 'teardown' in step:
text = step['teardown']
- vmdb.progress('{}\n'.format(text))
+ vmdb.progress('{}'.format(text))
logging.info('%s', text)
diff --git a/vmdb/plugins/error_plugin.py b/vmdb/plugins/error_plugin.py
index cc26579..d085748 100644
--- a/vmdb/plugins/error_plugin.py
+++ b/vmdb/plugins/error_plugin.py
@@ -37,10 +37,8 @@ class ErrorStepRunner(vmdb.StepRunnerInterface):
return ['error', 'teardown']
def run(self, step, settings, state):
- vmdb.progress('ERROR: {}\n'.format(step['error']))
- logging.error('%s', step['error'])
+ vmdb.error('{}'.format(step['error']))
raise vmdb.StepError('an error occurred')
def teardown(self, step, settings, state):
- vmdb.progress('ERROR: {}\n'.format(step['teardown']))
- logging.error('error cleanup: %s', step['teardown'])
+ vmdb.error('{}'.format(step['teardown']))
diff --git a/vmdb/plugins/mkfs_plugin.py b/vmdb/plugins/mkfs_plugin.py
index 0a2a754..82fd1d6 100644
--- a/vmdb/plugins/mkfs_plugin.py
+++ b/vmdb/plugins/mkfs_plugin.py
@@ -41,5 +41,5 @@ class MkfsStepRunner(vmdb.StepRunnerInterface):
part_tag = step['partition']
device = state.parts[part_tag]
vmdb.progress(
- 'Creating {} filesystem on {}\n'.format(fstype, device))
+ 'Creating {} filesystem on {}'.format(fstype, device))
vmdb.runcmd(['/sbin/mkfs', '-t', fstype, device])
diff --git a/vmdb/plugins/mkimg_plugin.py b/vmdb/plugins/mkimg_plugin.py
index 2f81151..6b1749c 100644
--- a/vmdb/plugins/mkimg_plugin.py
+++ b/vmdb/plugins/mkimg_plugin.py
@@ -44,5 +44,5 @@ class MkimgStepRunner(vmdb.StepRunnerInterface):
filename = step['mkimg']
size = step['size']
vmdb.progress(
- 'Creating image file {} (size {})\n'.format(filename, size))
+ 'Creating image file {} (size {})'.format(filename, size))
vmdb.runcmd(['qemu-img', 'create', '-f', 'raw', filename, size])
diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py
index 6c611ef..5e92705 100644
--- a/vmdb/plugins/mount_plugin.py
+++ b/vmdb/plugins/mount_plugin.py
@@ -51,7 +51,7 @@ class MountStepRunner(vmdb.StepRunnerInterface):
mount_point = tempfile.mkdtemp()
vmdb.progress(
- 'Mounting {} ({}) on {}\n'.format(device, fs_tag, mount_point))
+ 'Mounting {} ({}) on {}'.format(device, fs_tag, mount_point))
vmdb.runcmd(['mount', device, mount_point])
state.mounts[fs_tag] = mount_point
@@ -62,6 +62,6 @@ class MountStepRunner(vmdb.StepRunnerInterface):
mount_point = state.mounts[fs_tag]
vmdb.progress(
- 'Unmounting {} ({}) from {}\n'.format(mount_point, fs_tag, device))
+ 'Unmounting {} ({}) from {}'.format(mount_point, fs_tag, device))
vmdb.runcmd(['umount', mount_point])
os.rmdir(mount_point)
diff --git a/vmdb/plugins/partition_plugin.py b/vmdb/plugins/partition_plugin.py
index e9ce68e..f88b07e 100644
--- a/vmdb/plugins/partition_plugin.py
+++ b/vmdb/plugins/partition_plugin.py
@@ -42,7 +42,7 @@ class MklabelStepRunner(vmdb.StepRunnerInterface):
label_type = step['mklabel']
device = step['device']
vmdb.progress(
- 'Creating partition table ({}) on {}\n'.format(label_type, device))
+ 'Creating partition table ({}) on {}'.format(label_type, device))
vmdb.runcmd(['parted', device, 'mklabel', label_type])
state.parts = {}
@@ -60,7 +60,7 @@ class MkpartStepRunner(vmdb.StepRunnerInterface):
part_tag = step['part-tag']
vmdb.progress(
- 'Creating partition ({}) on {} ({} to {})\n'.format(
+ 'Creating partition ({}) on {} ({} to {})'.format(
part_type, device, start, end))
vmdb.runcmd(['parted', '-s', device, 'mkpart', part_type, start, end])
@@ -81,5 +81,5 @@ class MkpartStepRunner(vmdb.StepRunnerInterface):
def teardown(self, step, settings, state):
device = step['device']
vmdb.progress(
- 'Undoing loopback devices for partitions on {}\n'.format(device))
+ 'Undoing loopback devices for partitions on {}'.format(device))
vmdb.runcmd(['kpartx', '-dsv', device])
diff --git a/vmdb/runcmd.py b/vmdb/runcmd.py
index 3d4bcb9..9cae459 100644
--- a/vmdb/runcmd.py
+++ b/vmdb/runcmd.py
@@ -33,14 +33,18 @@ def set_runcmd_progress(progress, verbose):
_verbose = verbose
+def error(msg):
+ logging.error(msg, exc_info=True)
+ _progress['current'] = msg
+ if _verbose:
+ _progress.error(msg)
+
+
def progress(msg):
- logging.error(repr(msg))
logging.info(msg)
_progress['current'] = msg
if _verbose:
- sys.stdout.write(msg)
- if not msg.endswith('\n'):
- sys.stdout.write('\n')
+ _progress.notify(msg)
def runcmd(argv, *argvs, **kwargs):