diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-13 12:35:26 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-13 13:19:02 +0200 |
commit | fa6501f87041ca3d3a239988d4b1ae03d7442700 (patch) | |
tree | 1beed5eb44e1939c2702179896cceb52004c16c9 /subplot/client.py | |
parent | 2f129dee8841f0007977ba80b1518e94b728d94a (diff) | |
download | obnam2-fa6501f87041ca3d3a239988d4b1ae03d7442700.tar.gz |
refactor: split obnam's bindings, functions for clarity
The old subplot/obnam.{yaml,py} were starting to get large enough that
it was hard to understand them. Also, were partly overlapping in
functionality with runcmd.
Diffstat (limited to 'subplot/client.py')
-rw-r--r-- | subplot/client.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/subplot/client.py b/subplot/client.py new file mode 100644 index 0000000..f159e74 --- /dev/null +++ b/subplot/client.py @@ -0,0 +1,60 @@ +import os +import subprocess +import yaml + + +def install_obnam(ctx): + runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"] + srcdir = globals()["srcdir"] + + # Add the directory with built Rust binaries to the path. + runcmd_prepend_to_path(ctx, dirname=os.path.join(srcdir, "target", "debug")) + + +def configure_client(ctx, filename=None): + get_file = globals()["get_file"] + + assert ctx.get("server_name") is not None + assert ctx.get("server_port") is not None + + config = get_file(filename) + config = yaml.safe_load(config) + config["server_name"] = ctx["server_name"] + config["server_port"] = ctx["server_port"] + + with open(filename, "w") as f: + yaml.safe_dump(config, stream=f) + + +def run_obnam_restore(ctx, filename=None, genid=None, dbname=None, todir=None): + runcmd_run = globals()["runcmd_run"] + + genid = ctx["vars"][genid] + runcmd_run( + ctx, + ["env", "RUST_LOG=obnam", "obnam", "restore", filename, genid, dbname, todir], + ) + + +def capture_generation_id(ctx, varname=None): + runcmd_get_stdout = globals()["runcmd_get_stdout"] + + stdout = runcmd_get_stdout(ctx) + gen_id = "unknown" + for line in stdout.splitlines(): + if line.startswith("gen id:"): + gen_id = line.split()[-1] + + v = ctx.get("vars", {}) + v[varname] = gen_id + ctx["vars"] = v + + +def live_and_restored_data_match(ctx, live=None, restore=None): + subprocess.check_call(["diff", "-rq", f"{live}/.", f"{restore}/{live}/."]) + + +def generation_list_contains(ctx, gen_id=None): + runcmd_stdout_contains = globals()["runcmd_stdout_contains"] + gen_id = ctx["vars"][gen_id] + runcmd_stdout_contains(ctx, text=gen_id) |