diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-05-27 07:32:26 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-05-27 07:32:26 +0000 |
commit | 016060db2b1968d25a23d54e42b5566d14d3e16d (patch) | |
tree | 6f319b361050dce3221159961cccf186a70dc7e7 /v-i | |
parent | ad845a7d26bd43f2b0bff9cb9113c486fd4a19c7 (diff) | |
parent | 7230abdc1ece4b08b46da0483a5d75d6f5c5d5de (diff) | |
download | v-i-016060db2b1968d25a23d54e42b5566d14d3e16d.tar.gz |
Merge branch 'liw/tweaks' into 'main'
small improvements to make for a nicer experience
See merge request larswirzenius/v-i!47
Diffstat (limited to 'v-i')
-rwxr-xr-x | v-i | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -8,6 +8,7 @@ import shutil import subprocess import sys import tempfile +import time import yaml @@ -379,6 +380,31 @@ def vmdb_spec(system, ansible_vars): return {"steps": steps} +class Timings: + def __init__(self): + self.started = time.time() + self.times = {} + self.whats = [] + + def reached(self, what): + assert what not in self.whats + assert what not in self.times + self.times[what] = time.time() + self.whats.append(what) + + def report(self): + prev = self.started + for what in self.whats: + secs = "%.1f" % (self.times[what] - prev) + prev = self.times[what] + log(f"Duration: {what}: {secs} s") + print(f"Duration: {what}: {secs} s") + + +def cache_name(spec): + return f"{spec.debian_release}.cache.tar.gz" + + class SystemSpec: def __init__(self, filename): REQUIRED = "required" @@ -441,11 +467,13 @@ class SystemSpec: def main(): + timings = Timings() + p = argparse.ArgumentParser() p.add_argument("--verbose", action="store_true") p.add_argument("--very-verbose", action="store_true") p.add_argument("--log", default="install.log") - p.add_argument("--cache", default="cache.tar.gz") + p.add_argument("--cache", default=None) p.add_argument("spec") args = p.parse_args() @@ -463,6 +491,9 @@ def main(): system = SystemSpec(args.spec) log(f"spec: {system!r}") + cache = args.cache or cache_name(system) + log(f"cache: {cache}") + ansible_vars = dict(system.ansible_vars) ansible_vars["hostname"] = system.hostname for filename in system.ansible_vars_files: @@ -471,8 +502,10 @@ def main(): vars_dict = yaml.safe_load(f) ansible_vars.update(vars_dict) log(f"ansible_vars: {ansible_vars!r}") + timings.reached("read configuration") clean_up_disks([system.drive] + system.extra_drives) + timings.reached("clean up storage") vmdb = vmdb_spec(system, ansible_vars) tmp = tempfile.mkdtemp() @@ -490,7 +523,7 @@ def main(): argv = [ "vmdb2", - f"--rootfs-tarball={args.cache}", + f"--rootfs-tarball={cache}", f"--log={args.log}", f"--image={system.drive}", specfile, @@ -498,12 +531,16 @@ def main(): if verbose: argv.append("--verbose") run(argv, check=True, capture_output=True) + timings.reached("vmdb2") log("cleanup") shutil.rmtree(tmp) + timings.reached("clean up") log("OK, done") print("OK, done") + timings.report() + main() |