This commit is contained in:
Jay Lee
2016-11-03 12:49:32 -04:00
2 changed files with 92 additions and 20 deletions

72
src/gam-setup.bat Normal file
View File

@ -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

View File

@ -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):