mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-07 21:23:34 +00:00
Merge pull request #130 from taers232c/master
Apply convertUTF8 to more fields, clean up gam create resource/print resources
This commit is contained in:
82
src/gam.py
Normal file → Executable file
82
src/gam.py
Normal file → Executable file
@ -1529,15 +1529,15 @@ def doGetCourseInfo():
|
|||||||
print u' Teachers:'
|
print u' Teachers:'
|
||||||
for teacher in teachers:
|
for teacher in teachers:
|
||||||
try:
|
try:
|
||||||
print u' %s - %s' % (teacher[u'profile'][u'name'][u'fullName'], teacher[u'profile'][u'emailAddress'])
|
print convertUTF8(u' %s - %s' % (teacher[u'profile'][u'name'][u'fullName'], teacher[u'profile'][u'emailAddress']))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print u' %s' % teacher[u'profile'][u'name'][u'fullName']
|
print convertUTF8(u' %s' % teacher[u'profile'][u'name'][u'fullName'])
|
||||||
print u' Students:'
|
print u' Students:'
|
||||||
for student in students:
|
for student in students:
|
||||||
try:
|
try:
|
||||||
print u' %s - %s' % (student[u'profile'][u'name'][u'fullName'], student[u'profile'][u'emailAddress'])
|
print convertUTF8(u' %s - %s' % (student[u'profile'][u'name'][u'fullName'], student[u'profile'][u'emailAddress']))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print u' %s' % student[u'profile'][u'name'][u'fullName']
|
print convertUTF8(u' %s' % student[u'profile'][u'name'][u'fullName'])
|
||||||
|
|
||||||
def doPrintCourses():
|
def doPrintCourses():
|
||||||
croom = buildGAPIObject(u'classroom')
|
croom = buildGAPIObject(u'classroom')
|
||||||
@ -2815,7 +2815,7 @@ def doDriveActivity(users):
|
|||||||
feed = callGAPIpages(service=activity.activities(), function=u'list', items=u'activities',
|
feed = callGAPIpages(service=activity.activities(), function=u'list', items=u'activities',
|
||||||
page_message=page_message, source=u'drive.google.com', userId=u'me',
|
page_message=page_message, source=u'drive.google.com', userId=u'me',
|
||||||
drive_ancestorId=drive_ancestorId, groupingStrategy=u'none',
|
drive_ancestorId=drive_ancestorId, groupingStrategy=u'none',
|
||||||
drive_fileId=drive_fileId, pageSize=500)
|
drive_fileId=drive_fileId, pageSize=100)
|
||||||
for item in feed:
|
for item in feed:
|
||||||
activity_attributes.append(flatten_json(item[u'combinedEvent']))
|
activity_attributes.append(flatten_json(item[u'combinedEvent']))
|
||||||
for an_item in activity_attributes[-1]:
|
for an_item in activity_attributes[-1]:
|
||||||
@ -3458,7 +3458,7 @@ def downloadDriveFile(users):
|
|||||||
extension = None
|
extension = None
|
||||||
result = callGAPI(service=drive.files(), function=u'get', fileId=fileId, fields=u'fileSize,title,mimeType,downloadUrl,exportLinks')
|
result = callGAPI(service=drive.files(), function=u'get', fileId=fileId, fields=u'fileSize,title,mimeType,downloadUrl,exportLinks')
|
||||||
if result[u'mimeType'] == u'application/vnd.google-apps.folder':
|
if result[u'mimeType'] == u'application/vnd.google-apps.folder':
|
||||||
print u'Skipping download of folder %s' % result[u'title']
|
print convertUTF8(u'Skipping download of folder %s' % result[u'title'])
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
result[u'fileSize'] = int(result[u'fileSize'])
|
result[u'fileSize'] = int(result[u'fileSize'])
|
||||||
@ -3485,10 +3485,10 @@ def downloadDriveFile(users):
|
|||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print u'Skipping download of file {0}, Format {1} not available'.format(result[u'title'], ','.join(export_formats))
|
print convertUTF8(u'Skipping download of file {0}, Format {1} not available'.format(result[u'title'], ','.join(export_formats)))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
print u'Skipping download of file {0}, Format not downloadable'
|
print convertUTF8(u'Skipping download of file {0}, Format not downloadable')
|
||||||
continue
|
continue
|
||||||
file_title = result[u'title']
|
file_title = result[u'title']
|
||||||
safe_file_title = ''.join(c for c in file_title if c in safe_filename_chars)
|
safe_file_title = ''.join(c for c in file_title if c in safe_filename_chars)
|
||||||
@ -3505,7 +3505,7 @@ def downloadDriveFile(users):
|
|||||||
if not os.path.isfile(new_filename):
|
if not os.path.isfile(new_filename):
|
||||||
break
|
break
|
||||||
filename = new_filename
|
filename = new_filename
|
||||||
print my_line % filename
|
print convertUTF8(my_line % filename)
|
||||||
_, content = drive._http.request(download_url)
|
_, content = drive._http.request(download_url)
|
||||||
f = open(filename, 'wb')
|
f = open(filename, 'wb')
|
||||||
f.write(content)
|
f.write(content)
|
||||||
@ -3530,16 +3530,16 @@ def showDriveFileInfo(users):
|
|||||||
for setti in settin:
|
for setti in settin:
|
||||||
if setti == u'kind':
|
if setti == u'kind':
|
||||||
continue
|
continue
|
||||||
print u' %s: %s' % (setti, settin[setti])
|
print convertUTF8(u' %s: %s' % (setti, settin[setti]))
|
||||||
print ''
|
print ''
|
||||||
elif setting_type == u"<type 'dict'>":
|
elif setting_type == u"<type 'dict'>":
|
||||||
print u'%s:' % setting
|
print u'%s:' % setting
|
||||||
for settin in feed[setting]:
|
for settin in feed[setting]:
|
||||||
if settin == u'kind':
|
if settin == u'kind':
|
||||||
continue
|
continue
|
||||||
print u' %s: %s' % (settin, feed[setting][settin])
|
print convertUTF8(u' %s: %s' % (settin, feed[setting][settin]))
|
||||||
else:
|
else:
|
||||||
print u'%s: %s' % (setting, feed[setting])
|
print convertUTF8(u'%s: %s' % (setting, feed[setting]))
|
||||||
|
|
||||||
def transferSecCals(users):
|
def transferSecCals(users):
|
||||||
target_user = sys.argv[5]
|
target_user = sys.argv[5]
|
||||||
@ -5093,7 +5093,7 @@ def doCreateResource():
|
|||||||
if sys.argv[i].lower() == u'description':
|
if sys.argv[i].lower() == u'description':
|
||||||
description = sys.argv[i+1]
|
description = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower() == u'resType':
|
elif sys.argv[i].lower() == u'type':
|
||||||
resType = sys.argv[i+1]
|
resType = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
@ -5932,9 +5932,9 @@ def doGetUserInfo(user_email=None):
|
|||||||
user = callGAPI(service=cd.users(), function=u'get', userKey=user_email, projection=projection, customFieldMask=customFieldMask, viewType=viewType)
|
user = callGAPI(service=cd.users(), function=u'get', userKey=user_email, projection=projection, customFieldMask=customFieldMask, viewType=viewType)
|
||||||
print u'User: %s' % user[u'primaryEmail']
|
print u'User: %s' % user[u'primaryEmail']
|
||||||
if u'name' in user and u'givenName' in user[u'name']:
|
if u'name' in user and u'givenName' in user[u'name']:
|
||||||
print u'First Name: %s' % user[u'name'][u'givenName']
|
print convertUTF8(u'First Name: %s' % user[u'name'][u'givenName'])
|
||||||
if u'name' in user and u'familyName' in user[u'name']:
|
if u'name' in user and u'familyName' in user[u'name']:
|
||||||
print u'Last Name: %s' % user[u'name'][u'familyName']
|
print convertUTF8(u'Last Name: %s' % user[u'name'][u'familyName'])
|
||||||
if u'isAdmin' in user:
|
if u'isAdmin' in user:
|
||||||
print u'Is a Super Admin: %s' % user[u'isAdmin']
|
print u'Is a Super Admin: %s' % user[u'isAdmin']
|
||||||
if u'isDelegatedAdmin' in user:
|
if u'isDelegatedAdmin' in user:
|
||||||
@ -5972,13 +5972,13 @@ def doGetUserInfo(user_email=None):
|
|||||||
print u'IMs:'
|
print u'IMs:'
|
||||||
for im in user[u'ims']:
|
for im in user[u'ims']:
|
||||||
for key in im:
|
for key in im:
|
||||||
print u' %s: %s' % (key, im[key])
|
print convertUTF8(u' %s: %s' % (key, im[key]))
|
||||||
print u''
|
print u''
|
||||||
if u'addresses' in user:
|
if u'addresses' in user:
|
||||||
print u'Addresses:'
|
print u'Addresses:'
|
||||||
for address in user[u'addresses']:
|
for address in user[u'addresses']:
|
||||||
for key in address:
|
for key in address:
|
||||||
print u' %s: %s' % (key, address[key])
|
print convertUTF8(u' %s: %s' % (key, address[key]))
|
||||||
print ''
|
print ''
|
||||||
if u'organizations' in user:
|
if u'organizations' in user:
|
||||||
print u'Organizations:'
|
print u'Organizations:'
|
||||||
@ -5986,13 +5986,13 @@ def doGetUserInfo(user_email=None):
|
|||||||
for key in org:
|
for key in org:
|
||||||
if key == u'customType' and not org[key]:
|
if key == u'customType' and not org[key]:
|
||||||
continue
|
continue
|
||||||
print u' %s: %s' % (key, org[key])
|
print convertUTF8(u' %s: %s' % (key, org[key]))
|
||||||
print u''
|
print u''
|
||||||
if u'phones' in user:
|
if u'phones' in user:
|
||||||
print u'Phones:'
|
print u'Phones:'
|
||||||
for phone in user[u'phones']:
|
for phone in user[u'phones']:
|
||||||
for key in phone:
|
for key in phone:
|
||||||
print u' %s: %s' % (key, phone[key])
|
print convertUTF8(u' %s: %s' % (key, phone[key]))
|
||||||
print u''
|
print u''
|
||||||
if u'emails' in user:
|
if u'emails' in user:
|
||||||
if len(user[u'emails']) > 1:
|
if len(user[u'emails']) > 1:
|
||||||
@ -6004,9 +6004,9 @@ def doGetUserInfo(user_email=None):
|
|||||||
if key == u'type' and an_email[key] == u'custom':
|
if key == u'type' and an_email[key] == u'custom':
|
||||||
continue
|
continue
|
||||||
if key == u'customType':
|
if key == u'customType':
|
||||||
print u' type: %s' % an_email[key]
|
print convertUTF8(u' type: %s' % an_email[key])
|
||||||
else:
|
else:
|
||||||
print u' %s: %s' % (key, an_email[key])
|
print convertUTF8(u' %s: %s' % (key, an_email[key]))
|
||||||
print u''
|
print u''
|
||||||
if u'relations' in user:
|
if u'relations' in user:
|
||||||
print u'Relations:'
|
print u'Relations:'
|
||||||
@ -6015,9 +6015,9 @@ def doGetUserInfo(user_email=None):
|
|||||||
if key == u'type' and relation[key] == u'custom':
|
if key == u'type' and relation[key] == u'custom':
|
||||||
continue
|
continue
|
||||||
elif key == u'customType':
|
elif key == u'customType':
|
||||||
print u' %s: %s' % (u'type', relation[key])
|
print convertUTF8(u' %s: %s' % (u'type', relation[key]))
|
||||||
else:
|
else:
|
||||||
print u' %s: %s' % (key, relation[key])
|
print convertUTF8(u' %s: %s' % (key, relation[key]))
|
||||||
print u''
|
print u''
|
||||||
if u'externalIds' in user:
|
if u'externalIds' in user:
|
||||||
print u'External IDs:'
|
print u'External IDs:'
|
||||||
@ -6026,9 +6026,9 @@ def doGetUserInfo(user_email=None):
|
|||||||
if key == u'type' and externalId[key] == u'custom':
|
if key == u'type' and externalId[key] == u'custom':
|
||||||
continue
|
continue
|
||||||
elif key == u'customType':
|
elif key == u'customType':
|
||||||
print u' %s: %s' % (u'type', externalId[key])
|
print convertUTF8(u' %s: %s' % (u'type', externalId[key]))
|
||||||
else:
|
else:
|
||||||
print u' %s: %s' % (key, externalId[key])
|
print convertUTF8(u' %s: %s' % (key, externalId[key]))
|
||||||
print u''
|
print u''
|
||||||
if getSchemas:
|
if getSchemas:
|
||||||
if u'customSchemas' in user:
|
if u'customSchemas' in user:
|
||||||
@ -6037,11 +6037,11 @@ def doGetUserInfo(user_email=None):
|
|||||||
print u' Schema: %s' % schema
|
print u' Schema: %s' % schema
|
||||||
for field in user[u'customSchemas'][schema]:
|
for field in user[u'customSchemas'][schema]:
|
||||||
if type(user[u'customSchemas'][schema][field]) is list:
|
if type(user[u'customSchemas'][schema][field]) is list:
|
||||||
print ' %s:' % field
|
print u' %s:' % field
|
||||||
for an_item in user[u'customSchemas'][schema][field]:
|
for an_item in user[u'customSchemas'][schema][field]:
|
||||||
print ' %s' % an_item[u'value']
|
print convertUTF8(u' %s' % an_item[u'value'])
|
||||||
else:
|
else:
|
||||||
print u' %s: %s' % (field, user[u'customSchemas'][schema][field])
|
print convertUTF8(u' %s: %s' % (field, user[u'customSchemas'][schema][field]))
|
||||||
print
|
print
|
||||||
if getAliases:
|
if getAliases:
|
||||||
if u'aliases' in user:
|
if u'aliases' in user:
|
||||||
@ -6103,7 +6103,7 @@ def doGetGroupInfo(group_name=None):
|
|||||||
for val in value:
|
for val in value:
|
||||||
print u' %s' % val
|
print u' %s' % val
|
||||||
else:
|
else:
|
||||||
print u' %s: %s' % (key, value)
|
print convertUTF8(u' %s: %s' % (key, value))
|
||||||
try:
|
try:
|
||||||
for key, value in settings.items():
|
for key, value in settings.items():
|
||||||
if key in [u'kind', u'etag', u'description', u'email', u'name']:
|
if key in [u'kind', u'etag', u'description', u'email', u'name']:
|
||||||
@ -7756,14 +7756,15 @@ def doPrintResources():
|
|||||||
res_attributes = []
|
res_attributes = []
|
||||||
res_attributes.append({u'Name': u'Name'})
|
res_attributes.append({u'Name': u'Name'})
|
||||||
titles = ['Name']
|
titles = ['Name']
|
||||||
printid = printdesc = printemail = todrive = False
|
printid = printdesc = printemail = printtype = todrive = False
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
if sys.argv[i].lower() == u'allfields':
|
if sys.argv[i].lower() == u'allfields':
|
||||||
printid = printdesc = printemail = True
|
printid = printdesc = printemail = True
|
||||||
res_attributes[0].update(ID=u'ID', Description=u'Description', Email=u'Email')
|
res_attributes[0].update(ID=u'ID', Description=u'Description', Email=u'Email', Type=u'Type')
|
||||||
titles.append(u'ID')
|
titles.append(u'ID')
|
||||||
titles.append(u'Description')
|
titles.append(u'Description')
|
||||||
titles.append(u'Email')
|
titles.append(u'Email')
|
||||||
|
titles.append(u'Type')
|
||||||
i += 1
|
i += 1
|
||||||
elif sys.argv[i].lower() == u'todrive':
|
elif sys.argv[i].lower() == u'todrive':
|
||||||
todrive = True
|
todrive = True
|
||||||
@ -7783,11 +7784,16 @@ def doPrintResources():
|
|||||||
res_attributes[0].update(Email=u'Email')
|
res_attributes[0].update(Email=u'Email')
|
||||||
titles.append(u'Email')
|
titles.append(u'Email')
|
||||||
i += 1
|
i += 1
|
||||||
|
elif sys.argv[i].lower() == u'type':
|
||||||
|
printtype = True
|
||||||
|
res_attributes[0].update(Type=u'Type')
|
||||||
|
titles.append(u'Type')
|
||||||
|
i += 1
|
||||||
else:
|
else:
|
||||||
print 'ERROR: %s is not a valid argument for "gam print resources"' % sys.argv[i]
|
print 'ERROR: %s is not a valid argument for "gam print resources"' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
resObj = getResCalObject()
|
resObj = getResCalObject()
|
||||||
sys.stderr.write(u"Retrieving All Resource Calendars for your account (may take some time on a large domain)")
|
sys.stderr.write(u"Retrieving All Resource Calendars for your account (may take some time on a large domain)\n")
|
||||||
resources = callGData(service=resObj, function=u'RetrieveAllResourceCalendars')
|
resources = callGData(service=resObj, function=u'RetrieveAllResourceCalendars')
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
resUnit = {}
|
resUnit = {}
|
||||||
@ -7802,6 +7808,8 @@ def doPrintResources():
|
|||||||
resUnit.update({u'Description': desc})
|
resUnit.update({u'Description': desc})
|
||||||
if printemail:
|
if printemail:
|
||||||
resUnit.update({u'Email': resource[u'resourceEmail']})
|
resUnit.update({u'Email': resource[u'resourceEmail']})
|
||||||
|
if printtype:
|
||||||
|
resUnit.update({u'Type': resource[u'resourceType']})
|
||||||
res_attributes.append(resUnit)
|
res_attributes.append(resUnit)
|
||||||
output_csv(res_attributes, titles, u'Resources', todrive)
|
output_csv(res_attributes, titles, u'Resources', todrive)
|
||||||
|
|
||||||
@ -8265,12 +8273,16 @@ def getUsersToModify(entity_type=None, entity=None, silent=False, return_uids=Fa
|
|||||||
page_message = u'Got %%total_items%% teachers...'
|
page_message = u'Got %%total_items%% teachers...'
|
||||||
teachers = callGAPIpages(service=croom.courses().teachers(), function=u'list', items=u'teachers', page_message=page_message, courseId=entity)
|
teachers = callGAPIpages(service=croom.courses().teachers(), function=u'list', items=u'teachers', page_message=page_message, courseId=entity)
|
||||||
for teacher in teachers:
|
for teacher in teachers:
|
||||||
users.append(teacher[u'profile'][u'emailAddress'])
|
email = teacher[u'profile'].get(u'emailAddress', None)
|
||||||
|
if email:
|
||||||
|
users.append(email)
|
||||||
if entity_type in [u'courseparticipants', u'students']:
|
if entity_type in [u'courseparticipants', u'students']:
|
||||||
page_message = u'Got %%total_items%% students...'
|
page_message = u'Got %%total_items%% students...'
|
||||||
students = callGAPIpages(service=croom.courses().students(), function=u'list', page_message=page_message, items=u'students', courseId=entity)
|
students = callGAPIpages(service=croom.courses().students(), function=u'list', page_message=page_message, items=u'students', courseId=entity)
|
||||||
for student in students:
|
for student in students:
|
||||||
users.append(student[u'profile'][u'emailAddress'])
|
email = student[u'profile'].get(u'emailAddress', None)
|
||||||
|
if email:
|
||||||
|
users.append(email)
|
||||||
elif entity_type == u'all':
|
elif entity_type == u'all':
|
||||||
got_uids = True
|
got_uids = True
|
||||||
users = []
|
users = []
|
||||||
@ -8960,7 +8972,7 @@ try:
|
|||||||
print user
|
print user
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
try:
|
try:
|
||||||
autoBatch = int(os.environ[u'GAM_AUTOBATCH', '0'])
|
autoBatch = int(os.environ.get(u'GAM_AUTOBATCH', '0'))
|
||||||
if (autoBatch > 0) and (len(users) > autoBatch):
|
if (autoBatch > 0) and (len(users) > autoBatch):
|
||||||
items = []
|
items = []
|
||||||
for user in users:
|
for user in users:
|
||||||
|
Reference in New Issue
Block a user