mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-08 13:43:35 +00:00
Merge branch 'master' of github.com:jay0lee/GAM
This commit is contained in:
46
gam.py
46
gam.py
@ -24,7 +24,7 @@ For more information, see http://code.google.com/p/google-apps-manager
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = u'Jay Lee <jay0lee@gmail.com>'
|
__author__ = u'Jay Lee <jay0lee@gmail.com>'
|
||||||
__version__ = u'3.31'
|
__version__ = u'3.32-unreleased'
|
||||||
__license__ = u'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
__license__ = u'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
|
||||||
|
|
||||||
import sys, os, time, datetime, random, socket, csv, platform, re, calendar, base64, hashlib
|
import sys, os, time, datetime, random, socket, csv, platform, re, calendar, base64, hashlib
|
||||||
@ -6096,6 +6096,8 @@ def doPrintCrosDevices():
|
|||||||
def doPrintLicenses(return_list=False):
|
def doPrintLicenses(return_list=False):
|
||||||
lic = buildGAPIObject(u'licensing')
|
lic = buildGAPIObject(u'licensing')
|
||||||
products = [u'Google-Apps', u'Google-Drive-storage', u'Google-Coordinate', u'Google-Vault']
|
products = [u'Google-Apps', u'Google-Drive-storage', u'Google-Coordinate', u'Google-Vault']
|
||||||
|
skus = None
|
||||||
|
licenses = []
|
||||||
lic_attributes = [{}]
|
lic_attributes = [{}]
|
||||||
todrive = False
|
todrive = False
|
||||||
i = 3
|
i = 3
|
||||||
@ -6106,24 +6108,36 @@ def doPrintLicenses(return_list=False):
|
|||||||
elif sys.argv[i].lower() in [u'products', u'product']:
|
elif sys.argv[i].lower() in [u'products', u'product']:
|
||||||
products = sys.argv[i+1].split(',')
|
products = sys.argv[i+1].split(',')
|
||||||
i += 2
|
i += 2
|
||||||
|
elif sys.argv[i].lower() in [u'sku', u'skus']:
|
||||||
|
skus = sys.argv[i+1].split(',')
|
||||||
|
i += 2
|
||||||
else:
|
else:
|
||||||
print u'Error: %s is not a valid argument to gam print licenses' % sys.argv[i]
|
print u'Error: %s is not a valid argument to gam print licenses' % sys.argv[i]
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
for productId in products:
|
if skus:
|
||||||
page_message = u'Got %%%%total_items%%%% Licenses for %s...\n' % productId
|
for sku in skus:
|
||||||
try:
|
product, sku = getProductAndSKU(sku)
|
||||||
licenses = callGAPIpages(service=lic.licenseAssignments(), function=u'listForProduct', throw_reasons=[u'invalid', u'forbidden'], page_message=page_message, customerId=domain, productId=productId, fields=u'items(productId,skuId,userId),nextPageToken')
|
page_message = u'Got %%%%total_items%%%% Licenses for %s...\n' % sku
|
||||||
except apiclient.errors.HttpError:
|
try:
|
||||||
licenses = []
|
licenses += callGAPIpages(service=lic.licenseAssignments(), function=u'listForProductAndSku', throw_reasons=[u'invalid', u'forbidden'], page_message=page_message, customerId=domain, productId=product, skuId=sku, fields=u'items(productId,skuId,userId),nextPageToken')
|
||||||
for license in licenses:
|
except apiclient.errors.HttpError:
|
||||||
a_license = dict()
|
licenses += []
|
||||||
for title in license.keys():
|
else:
|
||||||
if title in [u'kind', u'etags', u'selfLink']:
|
for productId in products:
|
||||||
continue
|
page_message = u'Got %%%%total_items%%%% Licenses for %s...\n' % productId
|
||||||
if title not in lic_attributes[0]:
|
try:
|
||||||
lic_attributes[0][title] = title
|
licenses += callGAPIpages(service=lic.licenseAssignments(), function=u'listForProduct', throw_reasons=[u'invalid', u'forbidden'], page_message=page_message, customerId=domain, productId=productId, fields=u'items(productId,skuId,userId),nextPageToken')
|
||||||
a_license[title] = license[title]
|
except apiclient.errors.HttpError:
|
||||||
lic_attributes.append(a_license)
|
licenses = +[]
|
||||||
|
for license in licenses:
|
||||||
|
a_license = dict()
|
||||||
|
for title in license.keys():
|
||||||
|
if title in [u'kind', u'etags', u'selfLink']:
|
||||||
|
continue
|
||||||
|
if title not in lic_attributes[0]:
|
||||||
|
lic_attributes[0][title] = title
|
||||||
|
a_license[title] = license[title]
|
||||||
|
lic_attributes.append(a_license)
|
||||||
if return_list:
|
if return_list:
|
||||||
return lic_attributes
|
return lic_attributes
|
||||||
output_csv(lic_attributes, lic_attributes[0], u'Licenses', todrive)
|
output_csv(lic_attributes, lic_attributes[0], u'Licenses', todrive)
|
||||||
|
Reference in New Issue
Block a user