mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-05 05:11:35 +00:00
Updates (#744)
* Three updates 973-1008 - Internally cache discovery documents 1857 - Use patch instead of update so customer address doesn't get wiped out 9917 - In writeCSVFiles, the number of columns is the number of titles. The number of columns in the first row may be smaller than that, think a file with one ACL where other ffiles have many 7171,7173, 10550, 10886, 11655, 12014, 12017 - Standardize error handling * Fix accidental delete
This commit is contained in:
32
src/gam.py
32
src/gam.py
@@ -970,10 +970,17 @@ def getValidOauth2TxtCredentials():
|
|||||||
|
|
||||||
def getService(api, http):
|
def getService(api, http):
|
||||||
api, version, api_version = getAPIVersion(api)
|
api, version, api_version = getAPIVersion(api)
|
||||||
|
if api in GM_Globals[GM_CURRENT_API_SERVICES] and version in GM_Globals[GM_CURRENT_API_SERVICES][api]:
|
||||||
|
service = googleapiclient.discovery.build_from_document(GM_Globals[GM_CURRENT_API_SERVICES][api][version], http=http)
|
||||||
|
if GM_Globals[GM_CACHE_DISCOVERY_ONLY]:
|
||||||
|
http.cache = None
|
||||||
|
return service
|
||||||
retries = 3
|
retries = 3
|
||||||
for n in range(1, retries+1):
|
for n in range(1, retries+1):
|
||||||
try:
|
try:
|
||||||
service = googleapiclient.discovery.build(api, version, http=http, cache_discovery=False)
|
service = googleapiclient.discovery.build(api, version, http=http, cache_discovery=False)
|
||||||
|
GM_Globals[GM_CURRENT_API_SERVICES].setdefault(api, {})
|
||||||
|
GM_Globals[GM_CURRENT_API_SERVICES][api][version] = service._rootDesc.copy()
|
||||||
if GM_Globals[GM_CACHE_DISCOVERY_ONLY]:
|
if GM_Globals[GM_CACHE_DISCOVERY_ONLY]:
|
||||||
http.cache = None
|
http.cache = None
|
||||||
return service
|
return service
|
||||||
@@ -997,6 +1004,8 @@ def getService(api, http):
|
|||||||
disc_file, discovery = readDiscoveryFile(api_version)
|
disc_file, discovery = readDiscoveryFile(api_version)
|
||||||
try:
|
try:
|
||||||
service = googleapiclient.discovery.build_from_document(discovery, http=http)
|
service = googleapiclient.discovery.build_from_document(discovery, http=http)
|
||||||
|
GM_Globals[GM_CURRENT_API_SERVICES].setdefault(api, {})
|
||||||
|
GM_Globals[GM_CURRENT_API_SERVICES][api][version] = service._rootDesc.copy()
|
||||||
if GM_Globals[GM_CACHE_DISCOVERY_ONLY]:
|
if GM_Globals[GM_CACHE_DISCOVERY_ONLY]:
|
||||||
http.cache = None
|
http.cache = None
|
||||||
return service
|
return service
|
||||||
@@ -1845,7 +1854,7 @@ def doUpdateCustomer():
|
|||||||
systemErrorExit(2, '%s is not a valid argument for "gam update customer"' % myarg)
|
systemErrorExit(2, '%s is not a valid argument for "gam update customer"' % myarg)
|
||||||
if not body:
|
if not body:
|
||||||
systemErrorExit(2, 'no arguments specified for "gam update customer"')
|
systemErrorExit(2, 'no arguments specified for "gam update customer"')
|
||||||
callGAPI(cd.customers(), u'update', customerKey=GC_Values[GC_CUSTOMER_ID], body=body)
|
callGAPI(cd.customers(), u'patch', customerKey=GC_Values[GC_CUSTOMER_ID], body=body)
|
||||||
print u'Updated customer'
|
print u'Updated customer'
|
||||||
|
|
||||||
def doDelDomain():
|
def doDelDomain():
|
||||||
@@ -7150,8 +7159,7 @@ and accept the Terms of Service (ToS). As soon as you've accepted the ToS popup,
|
|||||||
break
|
break
|
||||||
except (IndexError, KeyError):
|
except (IndexError, KeyError):
|
||||||
pass
|
pass
|
||||||
print status
|
systemErrorExit(1, status)
|
||||||
sys.exit(1)
|
|
||||||
if status.get(u'done', False):
|
if status.get(u'done', False):
|
||||||
break
|
break
|
||||||
sleep_time = i ** 2
|
sleep_time = i ** 2
|
||||||
@@ -7160,11 +7168,9 @@ and accept the Terms of Service (ToS). As soon as you've accepted the ToS popup,
|
|||||||
if create_again:
|
if create_again:
|
||||||
continue
|
continue
|
||||||
if not status.get(u'done', False):
|
if not status.get(u'done', False):
|
||||||
print u'Failed to create project: %s' % status
|
systemErrorExit(1, u'Failed to create project: %s' % status)
|
||||||
sys.exit(1)
|
|
||||||
elif u'error' in status:
|
elif u'error' in status:
|
||||||
print status[u'error']
|
systemErrorExit(2, status[u'error'])
|
||||||
sys.exit(2)
|
|
||||||
break
|
break
|
||||||
simplehttp = httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL])
|
simplehttp = httplib2.Http(disable_ssl_certificate_validation=GC_Values[GC_NO_VERIFY_SSL])
|
||||||
enableProjectAPIs(simplehttp, httpObj, project_name, False)
|
enableProjectAPIs(simplehttp, httpObj, project_name, False)
|
||||||
@@ -9908,7 +9914,7 @@ def writeCSVfile(csvRows, titles, list_type, todrive):
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
systemErrorExit(6, e)
|
systemErrorExit(6, e)
|
||||||
if todrive:
|
if todrive:
|
||||||
columns = len(csvRows[0])
|
columns = len(titles)
|
||||||
rows = len(csvRows)
|
rows = len(csvRows)
|
||||||
cell_count = rows * columns
|
cell_count = rows * columns
|
||||||
mimeType = u'application/vnd.google-apps.spreadsheet'
|
mimeType = u'application/vnd.google-apps.spreadsheet'
|
||||||
@@ -10541,7 +10547,7 @@ def doPrintAliases():
|
|||||||
for alias in user.get(u'nonEditableAliases', []):
|
for alias in user.get(u'nonEditableAliases', []):
|
||||||
csvRows.append({u'NonEditableAlias': alias, u'Target': user[u'primaryEmail'], u'TargetType': u'User'})
|
csvRows.append({u'NonEditableAlias': alias, u'Target': user[u'primaryEmail'], u'TargetType': u'User'})
|
||||||
if doGroups:
|
if doGroups:
|
||||||
printGettingAllItems(u'Group Aliasess', None)
|
printGettingAllItems(u'Group Aliases', None)
|
||||||
page_message = u'Got %%num_items%% Groups %%first_item%% - %%last_item%%\n'
|
page_message = u'Got %%num_items%% Groups %%first_item%% - %%last_item%%\n'
|
||||||
all_groups = callGAPIpages(cd.groups(), u'list', u'groups', page_message=page_message,
|
all_groups = callGAPIpages(cd.groups(), u'list', u'groups', page_message=page_message,
|
||||||
message_attribute=u'email', customer=GC_Values[GC_CUSTOMER_ID],
|
message_attribute=u'email', customer=GC_Values[GC_CUSTOMER_ID],
|
||||||
@@ -10877,7 +10883,7 @@ def doPrintCrosActivity():
|
|||||||
fields = u'chromeosdevices(%s),nextPageToken' % u','.join(fieldsList)
|
fields = u'chromeosdevices(%s),nextPageToken' % u','.join(fieldsList)
|
||||||
for query in queries:
|
for query in queries:
|
||||||
printGettingAllItems(u'CrOS Devices', query)
|
printGettingAllItems(u'CrOS Devices', query)
|
||||||
page_message = u'Got %%num_items%% CrOS devices...\n'
|
page_message = u'Got %%num_items%% CrOS Devices...\n'
|
||||||
all_cros = callGAPIpages(cd.chromeosdevices(), u'list', u'chromeosdevices', page_message=page_message,
|
all_cros = callGAPIpages(cd.chromeosdevices(), u'list', u'chromeosdevices', page_message=page_message,
|
||||||
query=query, customerId=GC_Values[GC_CUSTOMER_ID], projection=u'FULL',
|
query=query, customerId=GC_Values[GC_CUSTOMER_ID], projection=u'FULL',
|
||||||
fields=fields, maxResults=GC_Values[GC_DEVICE_MAX_RESULTS], orgUnitPath=orgUnitPath)
|
fields=fields, maxResults=GC_Values[GC_DEVICE_MAX_RESULTS], orgUnitPath=orgUnitPath)
|
||||||
@@ -12005,12 +12011,10 @@ def ProcessGAMCommand(args):
|
|||||||
run_batch(items)
|
run_batch(items)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
sys.stderr.write(u'{0}batch file: {1}, not processed, {2} error{3}\n'.format(ERROR_PREFIX, filename, errors, [u'', u's'][errors != 1]))
|
systemErrorExit(2, u'batch file: {0}, not processed, {1} error{2}'.format(filename, errors, [u'', u's'][errors != 1]))
|
||||||
sys.exit(2)
|
|
||||||
elif command == u'csv':
|
elif command == u'csv':
|
||||||
if httplib2.debuglevel > 0:
|
if httplib2.debuglevel > 0:
|
||||||
print u'Sorry, CSV commands are not compatible with debug. Delete debug.gam and try again.'
|
systemErrorExit(1, u'CSV commands are not compatible with debug. Delete debug.gam and try again.')
|
||||||
sys.exit(1)
|
|
||||||
i = 2
|
i = 2
|
||||||
filename = sys.argv[i]
|
filename = sys.argv[i]
|
||||||
i, encoding = getCharSet(i+1)
|
i, encoding = getCharSet(i+1)
|
||||||
|
|||||||
@@ -522,6 +522,8 @@ GM_WINDOWS = u'wndo'
|
|||||||
GM_SYS_ENCODING = u'syen'
|
GM_SYS_ENCODING = u'syen'
|
||||||
# Extra arguments to pass to GAPI functions
|
# Extra arguments to pass to GAPI functions
|
||||||
GM_EXTRA_ARGS_DICT = u'exad'
|
GM_EXTRA_ARGS_DICT = u'exad'
|
||||||
|
# Current API services
|
||||||
|
GM_CURRENT_API_SERVICES = u'caps'
|
||||||
# Current API user
|
# Current API user
|
||||||
GM_CURRENT_API_USER = u'capu'
|
GM_CURRENT_API_USER = u'capu'
|
||||||
# Current API scope
|
# Current API scope
|
||||||
@@ -554,6 +556,7 @@ GM_Globals = {
|
|||||||
GM_WINDOWS: os.name == u'nt',
|
GM_WINDOWS: os.name == u'nt',
|
||||||
GM_SYS_ENCODING: DEFAULT_CHARSET,
|
GM_SYS_ENCODING: DEFAULT_CHARSET,
|
||||||
GM_EXTRA_ARGS_DICT: {u'prettyPrint': False},
|
GM_EXTRA_ARGS_DICT: {u'prettyPrint': False},
|
||||||
|
GM_CURRENT_API_SERVICES: {},
|
||||||
GM_CURRENT_API_USER: None,
|
GM_CURRENT_API_USER: None,
|
||||||
GM_CURRENT_API_SCOPES: [],
|
GM_CURRENT_API_SCOPES: [],
|
||||||
GM_OAUTH2SERVICE_JSON_DATA: None,
|
GM_OAUTH2SERVICE_JSON_DATA: None,
|
||||||
|
|||||||
Reference in New Issue
Block a user