1- from argparse import Namespace
21import os
32from pathlib import Path
43from shutil import rmtree
54import subprocess
65
7- from compiler_admin import RESULT_FAILURE , RESULT_SUCCESS
6+ import click
7+
88from compiler_admin .services .google import USER_ARCHIVE , CallGAMCommand
99
1010
@@ -22,48 +22,37 @@ def _clean_config_dir(config_dir: Path) -> None:
2222 rmtree (path )
2323
2424
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.
3431
35- gyb (bool): If True, initialize a new GYB project.
32+ See:
3633
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
3936 """
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 :
4738 _clean_config_dir (GAM_CONFIG_PATH )
4839 # 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" ))
5344
54- if getattr ( args , "gyb" , False ) :
45+ if init_gyb :
5546 _clean_config_dir (GYB_CONFIG_PATH )
5647 # download GYB installer to config directory
5748 gyb = GYB_CONFIG_PATH / "gyb-install.sh"
5849 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 )
6051
61- res += subprocess .call (("chmod" , "+x" , str (gyb .absolute ())))
52+ subprocess .call (("chmod" , "+x" , str (gyb .absolute ())))
6253
6354 # install, giving values to some options
6455 # https://github.com/GAM-team/got-your-back/blob/main/install-gyb.sh
6556 #
6657 # 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