|
7 | 7 | from compiler_admin.services.google import USER_ARCHIVE, CallGAMCommand |
8 | 8 |
|
9 | 9 |
|
10 | | -CONFIG_DIR = os.environ.get("GAMCFGDIR", "./.config") |
11 | | -CONFIG_PATH = Path(CONFIG_DIR) |
12 | | -CONFIG_PATH_NAME = str(CONFIG_PATH) |
| 10 | +GAM_CONFIG_DIR = os.environ.get("GAMCFGDIR", "./.config/gam") |
| 11 | +GAM_CONFIG_PATH = Path(GAM_CONFIG_DIR) |
| 12 | +GYB_CONFIG_PATH = GAM_CONFIG_PATH.parent / "gyb" |
13 | 13 |
|
14 | 14 |
|
15 | | -def _clean_config_dir(): |
16 | | - for path in CONFIG_PATH.glob("**/*"): |
| 15 | +def _clean_config_dir(config_dir: Path) -> None: |
| 16 | + config_dir.mkdir(parents=True, exist_ok=True) |
| 17 | + for path in config_dir.glob("**/*"): |
17 | 18 | if path.is_file(): |
18 | 19 | path.unlink() |
19 | 20 | elif path.is_dir(): |
20 | 21 | rmtree(path) |
21 | 22 |
|
22 | 23 |
|
23 | | -def init(admin_user: str) -> int: |
| 24 | +def init(admin_user: str, gam: bool = False, gyb: bool = False) -> int: |
24 | 25 | """Initialize a new GAM project. |
25 | 26 |
|
26 | 27 | See https://github.com/taers232c/GAMADV-XTD3/wiki/How-to-Install-Advanced-GAM |
27 | 28 |
|
28 | 29 | Args: |
29 | 30 | admin_user (str): The Compiler admin with which to initialize a new project. |
| 31 | +
|
| 32 | + gam (bool): If True, initialize a new GAM project. |
| 33 | +
|
| 34 | + gyb (bool): If True, initialize a new GYB project. |
| 35 | +
|
30 | 36 | Returns: |
31 | 37 | A value indicating if the operation succeeded or failed. |
32 | 38 | """ |
33 | | - if CONFIG_PATH.exists(): |
34 | | - _clean_config_dir() |
35 | | - |
36 | | - res = CallGAMCommand(("config", "drive_dir", CONFIG_PATH_NAME, "verify")) |
37 | | - res += CallGAMCommand(("create", "project")) |
38 | | - res += CallGAMCommand(("oauth", "create")) |
39 | | - res += CallGAMCommand(("user", admin_user, "check", "serviceaccount")) |
40 | | - |
41 | | - # download GYB installer to config directory |
42 | | - gyb = CONFIG_PATH / "gyb-install.sh" |
43 | | - with gyb.open("w+") as dest: |
44 | | - res += subprocess.call(("curl", "-s", "-S", "-L", "https://gyb-shortn.jaylee.us/gyb-install"), stdout=dest) |
45 | | - |
46 | | - # install, giving values to options that prompt by default |
47 | | - # https://github.com/GAM-team/got-your-back/blob/main/install-gyb.sh |
48 | | - res += subprocess.call((gyb, "-u", admin_user, "-r", USER_ARCHIVE)) |
| 39 | + res = RESULT_SUCCESS |
| 40 | + |
| 41 | + if gam: |
| 42 | + _clean_config_dir(GAM_CONFIG_PATH) |
| 43 | + # GAM is already installed via pyproject.toml |
| 44 | + res += CallGAMCommand(("config", "drive_dir", str(GAM_CONFIG_PATH), "verify")) |
| 45 | + res += CallGAMCommand(("create", "project")) |
| 46 | + res += CallGAMCommand(("oauth", "create")) |
| 47 | + res += CallGAMCommand(("user", admin_user, "check", "serviceaccount")) |
| 48 | + |
| 49 | + if gyb: |
| 50 | + _clean_config_dir(GYB_CONFIG_PATH) |
| 51 | + # download GYB installer to config directory |
| 52 | + gyb = GYB_CONFIG_PATH / "gyb-install.sh" |
| 53 | + with gyb.open("w+") as dest: |
| 54 | + res += subprocess.call(("curl", "-s", "-S", "-L", "https://gyb-shortn.jaylee.us/gyb-install"), stdout=dest) |
| 55 | + |
| 56 | + # install, giving values to some options |
| 57 | + # https://github.com/GAM-team/got-your-back/blob/main/install-gyb.sh |
| 58 | + # |
| 59 | + # use GYB_CONFIG_PATH.parent for the install directory option, otherwise we get a .config/gyb/gyb directory structure |
| 60 | + res += subprocess.call((gyb, "-u", admin_user, "-r", USER_ARCHIVE, "-d", str(GYB_CONFIG_PATH.parent))) |
49 | 61 |
|
50 | 62 | return RESULT_SUCCESS if res == RESULT_SUCCESS else RESULT_FAILURE |
0 commit comments