summaryrefslogtreecommitdiffstats
path: root/src/virtBootstrap/virt_bootstrap.py
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-04 16:24:26 +0100
committerCédric Bosdonnat <cbosdonnat@suse.com>2017-07-05 13:29:45 +0200
commit08d036a433b830319c931976b7a4e17574934720 (patch)
tree82852905f09c823950763f5571021e36399a37cd /src/virtBootstrap/virt_bootstrap.py
parentb8b69f2f41802bf87e119845a6f532d4970d2481 (diff)
downloadvirt-bootstrap.git-08d036a433b830319c931976b7a4e17574934720.tar.gz
virt-bootstrap.git-08d036a433b830319c931976b7a4e17574934720.tar.xz
virt-bootstrap.git-08d036a433b830319c931976b7a4e17574934720.zip
Add --status-only flag
When this flag is passed only the current state of virt-bootstrap will be shown along with the total bootstrap progress.
Diffstat (limited to 'src/virtBootstrap/virt_bootstrap.py')
-rwxr-xr-xsrc/virtBootstrap/virt_bootstrap.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/virtBootstrap/virt_bootstrap.py b/src/virtBootstrap/virt_bootstrap.py
index f03f29b..b2a32d7 100755
--- a/src/virtBootstrap/virt_bootstrap.py
+++ b/src/virtBootstrap/virt_bootstrap.py
@@ -81,6 +81,25 @@ def set_root_password(rootfs, password):
raise CalledProcessError(chpasswd.returncode, cmd=args, output=None)
+def write_progress(prog):
+ """
+ Write progress output to console
+ """
+ # Get terminal width
+ try:
+ terminal_width = int(Popen(["stty", "size"], stdout=PIPE).stdout
+ .read().split()[1])
+ except Exception:
+ terminal_width = 80
+ # Prepare message
+ msg = "\rStatus: %s, Progress: %.2f%%" % (prog['status'], prog['value'])
+ # Fill with whitespace and return cursor at the begging
+ msg = "%s\r" % msg.ljust(terminal_width)
+ # Write message to console
+ sys.stdout.write(msg)
+ sys.stdout.flush()
+
+
# pylint: disable=too-many-arguments
def bootstrap(uri, dest,
fmt='dir',
@@ -179,13 +198,19 @@ def main():
const=logging.WARNING,
help=_("Suppresses messages notifying about"
"current state or actions of virt-bootstrap"))
+ parser.add_argument("--status-only", action="store_const",
+ const=write_progress,
+ help=_("Show only the current status and progress"
+ "of virt-bootstrap"))
+
# TODO add UID / GID mapping parameters
try:
args = parser.parse_args()
- # Configure logging lovel/format
- set_logging_conf(args.loglevel)
+ if not args.status_only:
+ # Configure logging lovel/format
+ set_logging_conf(args.loglevel)
# do the job here!
bootstrap(uri=args.uri,
@@ -195,7 +220,8 @@ def main():
password=args.password,
root_password=args.root_password,
not_secure=args.not_secure,
- no_cache=args.no_cache)
+ no_cache=args.no_cache,
+ progress_cb=args.status_only)
sys.exit(0)
except KeyboardInterrupt: