From 2c0026512d4432ceddc0c35165da0c36c3dd0e0c Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Wed, 2 Nov 2016 14:30:54 -0700 Subject: [PATCH 1/2] Fix doGamVersion (#311) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix doGamVersion doGamVersion is called by showUsage with checkForArgs=False to keep doGamVersion from wandering through some other command’s arguments * Update documentation * Further doGamVersion cleanup Allow simple and check, keep pylint happy * gam version simple is script only option, not exposed to user --- src/gam.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/gam.py b/src/gam.py index beb46c9e..f4def167 100755 --- a/src/gam.py +++ b/src/gam.py @@ -428,7 +428,7 @@ def indentMultiLineText(message, n=0): return message.replace(u'\n', u'\n{0}'.format(u' '*n)).rstrip() def showUsage(): - doGAMVersion(checkForCheck=False) + doGAMVersion(checkForArgs=False) print u''' Usage: gam [OPTIONS]... @@ -818,32 +818,32 @@ def doGAMCheckForUpdates(forceCheck=False): except (urllib2.HTTPError, urllib2.URLError): return -def doGAMVersion(checkForCheck=True): +def doGAMVersion(checkForArgs=True): force_check = False simple = False - i = 2 - while i < len(sys.argv): - myarg = sys.argv[i].lower().replace(u'_', u'') - force_check = True - if myarg == u'check': - force_check = True - i += 1 - elif myarg == u'simple': - simple = True - i += 1 - else: - print u'ERROR: %s is not a valid argument for "gam version"' % sys.argv[i] - sys.exit(2) + if checkForArgs: + i = 2 + while i < len(sys.argv): + myarg = sys.argv[i].lower().replace(u'_', u'') + if myarg == u'check': + force_check = True + i += 1 + elif myarg == u'simple': + simple = True + i += 1 + else: + print u'ERROR: %s is not a valid argument for "gam version"' % sys.argv[i] + sys.exit(2) if simple: sys.stdout.write(__version__) - sys.exit(0) + return import struct version_data = u'GAM {0} - {1}\n{2}\nPython {3}.{4}.{5} {6}-bit {7}\ngoogle-api-python-client {8}\n{9} {10}\nPath: {11}' print version_data.format(__version__, GAM_URL, __author__, sys.version_info[0], - sys.version_info[1], sys.version_info[2], struct.calcsize(u'P')*8, - sys.version_info[3], googleapiclient.__version__, platform.platform(), - platform.machine(), GM_Globals[GM_GAM_PATH]) - if checkForCheck or force_check: + sys.version_info[1], sys.version_info[2], struct.calcsize(u'P')*8, + sys.version_info[3], googleapiclient.__version__, platform.platform(), + platform.machine(), GM_Globals[GM_GAM_PATH]) + if force_check: doGAMCheckForUpdates(forceCheck=True) def handleOAuthTokenError(e, soft_errors): From 1454526e655009c66866e7754129823be4bf9633 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Thu, 3 Nov 2016 11:38:23 -0400 Subject: [PATCH 2/2] gam-setup.bat file to automate Windows setup part of #309 --- src/gam-setup.bat | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/gam-setup.bat diff --git a/src/gam-setup.bat b/src/gam-setup.bat new file mode 100644 index 00000000..9a52f300 --- /dev/null +++ b/src/gam-setup.bat @@ -0,0 +1,72 @@ +@echo( +@set /p adminemail= "Please enter your G Suite admin email address: " + +:createproject +@echo( +@set /p yn= "Are you ready to set up a Google API project for GAM? [y or n] " +@if /I "%yn%"=="n" ( +@ echo( +@ echo You can create an API project later by running: +@ echo( +@ echo gam create project +@ goto alldone + ) +@if /I not "%yn%"=="y" ( +@ echo( +@ echo Please answer y or n. +@ goto createproject + ) +@gam create project %adminemail% +@if not ERRORLEVEL 1 goto projectdone +@echo( +@echo Projection creation failed. Trying again. Say n to skip projection creation. +@goto createproject +:projectdone + +:adminauth +@echo( +@set /p yn= "Are you ready to authorize GAM to perform G Suite management operations as your admin account? [y or n] " +@if /I "%yn%"=="n" ( +@ echo( +@ echo You can authorize an admin later by running: +@ echo( +@ echo gam oauth create %adminemail% +@ goto admindone + ) +@if /I not "%yn%"=="y" ( +@ echo( +@ echo Please answer y or n. +@ goto adminauth + ) +@gam oauth create %adminemail% +@if not ERRORLEVEL 1 goto admindone +@echo( +@echo Admin authorization failed. Trying again. Say n to skip admin authorization. +@goto adminauth +:admindone + +:saauth +@echo( +@set /p yn= "Are you ready to authorize GAM to manage G Suite user data and settings? [y or n] " +@if /I "%yn%"=="n" ( +@ echo( +@ echo You can authorize a service account later by running: +@ echo( +@ echo gam user %adminemail% check serviceaccount +@ goto sadone + ) +@if /I not "%yn%"=="y" ( +@ echo( +@ echo Please answer y or n. +@ goto saauth + ) +@echo Great! Checking service account scopes. This will fail the first time. Follow the steps to authorize and retry. It can take a few minutes for scopes to PASS after they've been authorized in the admin console. +@gam user %adminemail% check serviceaccount +@if not ERRORLEVEL 1 goto sadone +@echo( +@echo Service account authorization failed. Confirm you entered the scopes correctly in the admin console. It can take a few minutes for scopes to PASS after they are entered in the admin console so if you're sure you entered them correctly, go grab a coffee and then hit Y to try again. Say N to skip admin authorization. +@goto saauth +:sadone + +echo GAM installation and setup complete! +:alldone \ No newline at end of file