sapling/eden/integration/snapshot/unpack_snapshot.py
Mark Thomas 9218f35f45 rename and relocate eden and edenfs
Summary:
The Eden CLI tool is really a control program for `edenfs`.  Rename it to
`edenfsctl` to free up the `eden` name for future use.

The Eden daemon shouldn't really be on the user's path, and instead belongs in
`libexec`.

For transition compatibility, `eden` is symlinked to `edenfsctl`.

Reviewed By: simpkins

Differential Revision: D13888875

fbshipit-source-id: 435cc63e92b85b1f28b8691e4846fbcb05bc450e
2019-02-21 15:00:47 -08:00

67 lines
1.8 KiB
Python

#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import argparse
import os
from pathlib import Path
from . import snapshot as snapshot_mod
RUN_EDEN_SCRIPT = """\
#!/bin/bash
# Find the Eden binary to use.
DEV_EDEN="buck-out/gen/eden/cli/edenfsctl.par"
if [[ -n "$EDEN" ]]; then
# $EDEN is defined in the environment, so use that
:
elif [[ -x "$DEV_EDEN" ]]; then
# We appear to be running from an fbcode directory with a built
# version of eden in buck-out. Use it.
EDEN="$DEV_EDEN"
else
# Find eden from $PATH
EDEN="eden"
fi
SNAPSHOT_PATH={snapshot_path}
exec "$EDEN" \\
--etc-eden-dir "$SNAPSHOT_PATH/transient/etc_eden" \\
--config-dir "$SNAPSHOT_PATH/data/eden" \\
"$@"
"""
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", required=True, help="The output directory path.")
ap.add_argument(
"--start", action="store_true", default=False, help="Also start EdenFS."
)
ap.add_argument("snapshot", help="The path of the snapshot file to unpack.")
args = ap.parse_args()
output_dir = Path(args.output)
input_path = Path(args.snapshot)
output_dir.mkdir()
snapshot_mod.unpack_into(input_path, output_dir)
# Write a small helper script that can be used to more easily invoke Eden in this
# repository.
run_eden_path = output_dir / "run_eden"
with run_eden_path.open("w") as f:
f.write(RUN_EDEN_SCRIPT.format(snapshot_path=output_dir))
os.fchmod(f.fileno(), 0o755)
if __name__ == "__main__":
main()