Added option addcsvdata <FieldName> <String> to gam print courses

This commit is contained in:
Ross Scroggs
2025-10-28 07:35:52 -07:00
parent dd5616ec0e
commit 6a5052f8a2
3 changed files with 21 additions and 1 deletions

View File

@@ -3279,6 +3279,7 @@ gam print courses [todrive <ToDriveAttribute>*]
[show all|students|teachers] [countsonly] [show all|students|teachers] [countsonly]
[timefilter creationtime|updatetime] [start|starttime <Date>|<Time>] [end|endtime <Date>|<Time>] [timefilter creationtime|updatetime] [start|starttime <Date>|<Time>] [end|endtime <Date>|<Time>]
[fields <CourseFieldNameList>] [skipfields <CourseFieldNameList>] [fields <CourseFieldNameList>] [skipfields <CourseFieldNameList>]
(addcsvdata <FieldName> <String>)*
[formatjson [quotechar <Character>]] [formatjson [quotechar <Character>]]
[showitemcountonly] [showitemcountonly]

View File

@@ -1,3 +1,8 @@
7.27.05
Added option `addcsvdata <FieldName> <String>` to `gam print courses`
that adds additional columns of data to the CSV file output.
7.27.04 7.27.04
Added options to `gam <UserTypeEntity> create delegate` that support Added options to `gam <UserTypeEntity> create delegate` that support

View File

@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
""" """
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>' __author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__version__ = '7.27.04' __version__ = '7.27.05'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
#pylint: disable=wrong-import-position #pylint: disable=wrong-import-position
@@ -49166,6 +49166,7 @@ def _getCoursesInfo(croom, courseSelectionParameters, courseShowProperties, getO
# [show none|all|students|teachers] [countsonly] # [show none|all|students|teachers] [countsonly]
# [fields <CourseFieldNameList>] [skipfields <CourseFieldNameList>] # [fields <CourseFieldNameList>] [skipfields <CourseFieldNameList>]
# [timefilter creationtime|updatetime] [start|starttime <Date>|<Time>] [end|endtime <Date>|<Time>] # [timefilter creationtime|updatetime] [start|starttime <Date>|<Time>] [end|endtime <Date>|<Time>]
# (addcsvdata <FieldName> <String>)*
# [showitemcountonly] [formatjson [quotechar <Character>]] # [showitemcountonly] [formatjson [quotechar <Character>]]
def doPrintCourses(): def doPrintCourses():
def _saveParticipants(course, participants, role, rtitles): def _saveParticipants(course, participants, role, rtitles):
@@ -49209,6 +49210,7 @@ def doPrintCourses():
delimiter = GC.Values[GC.CSV_OUTPUT_FIELD_DELIMITER] delimiter = GC.Values[GC.CSV_OUTPUT_FIELD_DELIMITER]
showItemCountOnly = False showItemCountOnly = False
useOwnerAccess = GC.Values[GC.USE_COURSE_OWNER_ACCESS] useOwnerAccess = GC.Values[GC.USE_COURSE_OWNER_ACCESS]
addCSVData = {}
while Cmd.ArgumentsRemaining(): while Cmd.ArgumentsRemaining():
myarg = getArgument() myarg = getArgument()
if myarg == 'todrive': if myarg == 'todrive':
@@ -49223,6 +49225,9 @@ def doPrintCourses():
pass pass
elif myarg == 'showitemcountonly': elif myarg == 'showitemcountonly':
showItemCountOnly = True showItemCountOnly = True
elif myarg == 'addcsvdata':
k = getString(Cmd.OB_STRING)
addCSVData[k] = getString(Cmd.OB_STRING, minLen=0)
else: else:
FJQC.GetFormatJSONQuoteChar(myarg, True) FJQC.GetFormatJSONQuoteChar(myarg, True)
applyCourseItemFilter = _setApplyCourseItemFilter(courseItemFilter, None) applyCourseItemFilter = _setApplyCourseItemFilter(courseItemFilter, None)
@@ -49234,6 +49239,11 @@ def doPrintCourses():
if showItemCountOnly: if showItemCountOnly:
writeStdout('0\n') writeStdout('0\n')
return return
if addCSVData:
csvPF.AddTitles(sorted(addCSVData.keys()))
if FJQC.formatJSON:
csvPF.AddJSONTitles(sorted(addCSVData.keys()))
csvPF.MoveJSONTitlesToEnd(['JSON'])
if courseShowProperties['aliases']: if courseShowProperties['aliases']:
if FJQC.formatJSON: if FJQC.formatJSON:
csvPF.AddJSONTitles('JSON-aliases') csvPF.AddJSONTitles('JSON-aliases')
@@ -49291,11 +49301,15 @@ def doPrintCourses():
if courseShowProperties['members'] != 'teachers': if courseShowProperties['members'] != 'teachers':
_saveParticipants(course, students, 'students', stitles) _saveParticipants(course, students, 'students', stitles)
row = flattenJSON(course, timeObjects=COURSE_TIME_OBJECTS, noLenObjects=COURSE_NOLEN_OBJECTS) row = flattenJSON(course, timeObjects=COURSE_TIME_OBJECTS, noLenObjects=COURSE_NOLEN_OBJECTS)
if addCSVData:
row.update(addCSVData)
if not FJQC.formatJSON: if not FJQC.formatJSON:
csvPF.WriteRowTitles(row) csvPF.WriteRowTitles(row)
elif csvPF.CheckRowTitles(row): elif csvPF.CheckRowTitles(row):
row = {'id': courseId, 'JSON': json.dumps(cleanJSON(course, timeObjects=COURSE_TIME_OBJECTS), row = {'id': courseId, 'JSON': json.dumps(cleanJSON(course, timeObjects=COURSE_TIME_OBJECTS),
ensure_ascii=False, sort_keys=True)} ensure_ascii=False, sort_keys=True)}
if addCSVData:
row.update(addCSVData)
if courseShowProperties['aliases']: if courseShowProperties['aliases']:
row['JSON-aliases'] = json.dumps(list(aliases)) row['JSON-aliases'] = json.dumps(list(aliases))
if courseShowProperties['members'] != 'none': if courseShowProperties['members'] != 'none':