1
- from argparse import Namespace
2
1
import os
3
2
from pathlib import Path
4
3
from shutil import rmtree
5
4
import subprocess
6
5
7
- from compiler_admin import RESULT_FAILURE , RESULT_SUCCESS
6
+ import click
7
+
8
8
from compiler_admin .services .google import USER_ARCHIVE , CallGAMCommand
9
9
10
10
@@ -22,48 +22,37 @@ def _clean_config_dir(config_dir: Path) -> None:
22
22
rmtree (path )
23
23
24
24
25
- def init (args : Namespace , * extras ) -> int :
26
- """Initialize a new GAM project.
27
-
28
- See https://github.com/taers232c/GAMADV-XTD3/wiki/How-to-Install-Advanced-GAM
29
-
30
- Args:
31
- username (str): The Compiler admin with which to initialize a new project.
32
-
33
- gam (bool): If True, initialize a new GAM project.
25
+ @click .command ()
26
+ @click .option ("--gam" , "init_gam" , is_flag = True )
27
+ @click .option ("--gyb" , "init_gyb" , is_flag = True )
28
+ @click .argument ("username" )
29
+ def init (username : str , init_gam : bool = False , init_gyb : bool = False ):
30
+ """Initialize a new GAM and/or GYB project.
34
31
35
- gyb (bool): If True, initialize a new GYB project.
32
+ See:
36
33
37
- Returns:
38
- A value indicating if the operation succeeded or failed.
34
+ - https://github.com/taers232c/GAMADV-XTD3/wiki/How-to-Install-Advanced-GAM
35
+ - https://github.com/GAM-team/got-your-back/wiki
39
36
"""
40
- if not hasattr (args , "username" ):
41
- raise ValueError ("username is required" )
42
-
43
- admin_user = args .username
44
- res = RESULT_SUCCESS
45
-
46
- if getattr (args , "gam" , False ):
37
+ if init_gam :
47
38
_clean_config_dir (GAM_CONFIG_PATH )
48
39
# GAM is already installed via pyproject.toml
49
- res += CallGAMCommand (("config" , "drive_dir" , str (GAM_CONFIG_PATH ), "verify" ))
50
- res += CallGAMCommand (("create" , "project" ))
51
- res += CallGAMCommand (("oauth" , "create" ))
52
- res += CallGAMCommand (("user" , admin_user , "check" , "serviceaccount" ))
40
+ CallGAMCommand (("config" , "drive_dir" , str (GAM_CONFIG_PATH ), "verify" ))
41
+ CallGAMCommand (("create" , "project" ))
42
+ CallGAMCommand (("oauth" , "create" ))
43
+ CallGAMCommand (("user" , username , "check" , "serviceaccount" ))
53
44
54
- if getattr ( args , "gyb" , False ) :
45
+ if init_gyb :
55
46
_clean_config_dir (GYB_CONFIG_PATH )
56
47
# download GYB installer to config directory
57
48
gyb = GYB_CONFIG_PATH / "gyb-install.sh"
58
49
with gyb .open ("w+" ) as dest :
59
- res += subprocess .call (("curl" , "-s" , "-S" , "-L" , "https://gyb-shortn.jaylee.us/gyb-install" ), stdout = dest )
50
+ subprocess .call (("curl" , "-s" , "-S" , "-L" , "https://gyb-shortn.jaylee.us/gyb-install" ), stdout = dest )
60
51
61
- res += subprocess .call (("chmod" , "+x" , str (gyb .absolute ())))
52
+ subprocess .call (("chmod" , "+x" , str (gyb .absolute ())))
62
53
63
54
# install, giving values to some options
64
55
# https://github.com/GAM-team/got-your-back/blob/main/install-gyb.sh
65
56
#
66
57
# use GYB_CONFIG_PATH.parent for the install directory option, otherwise we get a .config/gyb/gyb directory structure
67
- res += subprocess .call ((gyb , "-u" , admin_user , "-r" , USER_ARCHIVE , "-d" , str (GYB_CONFIG_PATH .parent )))
68
-
69
- return RESULT_SUCCESS if res == RESULT_SUCCESS else RESULT_FAILURE
58
+ subprocess .call ((gyb , "-u" , username , "-r" , USER_ARCHIVE , "-d" , str (GYB_CONFIG_PATH .parent )))
0 commit comments