2017-04-04 01:47:53 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2017-04-04 01:47:53 +03:00
|
|
|
#
|
2019-06-20 02:58:25 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
2017-04-04 01:47:53 +03:00
|
|
|
|
2018-03-29 08:10:41 +03:00
|
|
|
import argparse
|
2017-04-04 01:47:53 +03:00
|
|
|
import os
|
2018-08-22 21:05:42 +03:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import Optional, Tuple, Union
|
2017-04-04 01:47:53 +03:00
|
|
|
|
2018-08-22 21:05:44 +03:00
|
|
|
from . import config as config_mod, subcmd as subcmd_mod
|
2018-08-22 21:05:42 +03:00
|
|
|
from .config import EdenCheckout, EdenInstance
|
2017-04-04 01:47:53 +03:00
|
|
|
|
|
|
|
|
2018-08-16 07:34:10 +03:00
|
|
|
def get_eden_instance(args: argparse.Namespace) -> EdenInstance:
|
2018-08-22 21:05:42 +03:00
|
|
|
return EdenInstance(
|
|
|
|
args.config_dir, etc_eden_dir=args.etc_eden_dir, home_dir=args.home_dir
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def find_checkout(
|
2018-11-10 01:25:36 +03:00
|
|
|
args: argparse.Namespace, path: Union[Path, str, None]
|
2018-08-22 21:05:42 +03:00
|
|
|
) -> Tuple[EdenInstance, Optional[EdenCheckout], Optional[Path]]:
|
|
|
|
if path is None:
|
|
|
|
path = os.getcwd()
|
|
|
|
return config_mod.find_eden(
|
|
|
|
path,
|
|
|
|
etc_eden_dir=args.etc_eden_dir,
|
|
|
|
home_dir=args.home_dir,
|
|
|
|
state_dir=args.config_dir,
|
|
|
|
)
|
2018-08-22 21:05:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
def require_checkout(
|
2019-06-26 04:39:31 +03:00
|
|
|
args: argparse.Namespace, path: Union[Path, str, None]
|
2018-08-22 21:05:44 +03:00
|
|
|
) -> Tuple[EdenInstance, EdenCheckout, Path]:
|
|
|
|
instance, checkout, rel_path = find_checkout(args, path)
|
|
|
|
if checkout is None:
|
2019-08-21 01:33:41 +03:00
|
|
|
msg_path = path if path is not None else os.getcwd()
|
2020-06-06 03:19:47 +03:00
|
|
|
raise subcmd_mod.CmdError(f"no Eden checkout found at {msg_path}\n")
|
2018-08-22 21:05:44 +03:00
|
|
|
assert rel_path is not None
|
|
|
|
return instance, checkout, rel_path
|