From 12f5c5e6702d25ee084ae4f063f5ffdbff6e9797 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Tue, 27 May 2025 13:21:31 -0700 Subject: [PATCH] Added option `showitemcountonly` to `gam [] print|show shareddrives` --- src/GamUpdate.txt | 5 +++++ src/gam/__init__.py | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 28ef2ff3..cfea57f8 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -1,3 +1,8 @@ +7.07.13 + +Added option `showitemcountonly` to `gam [] print|show shareddrives` that causes GAM to display the +number of Shared Drives on stdout; no CSV file is written. + 7.07.12 Fixed bug in `gam print|show oushareddrives` that caused a trap. diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 8948c5ca..1ab28a0c 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki """ __author__ = 'GAM Team ' -__version__ = '7.07.12' +__version__ = '7.07.13' __license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)' #pylint: disable=wrong-import-position @@ -59838,6 +59838,7 @@ def copyDriveFile(users): # Source at root of Shared Drive? sourceMimeType = source['mimeType'] if sourceMimeType == MIMETYPE_GA_FOLDER and source.get('driveId') and source['name'] == TEAM_DRIVE and not source.get('parents', []): + copyMoveOptions['sourceIsMyDriveSharedDrive'] = True source['name'] = _getSharedDriveNameFromId(drive, source['driveId']) sourceName = source['name'] sourceNameId = f"{sourceName}({source['id']})" @@ -65416,12 +65417,14 @@ SHAREDDRIVE_ACL_ROLES_MAP = { # (role|roles )* # [fields ] [noorgunits []] # [guiroles []] [formatjson [quotechar ]] +# [showitemcountonly] # gam show shareddrives # [asadmin [shareddriveadminquery|query ]] # [matchname ] [orgunit|org|ou ] # (role|roles )* # [fields ] [noorgunits []] # [guiroles []] [formatjson] +# [showitemcountonly] def printShowSharedDrives(users, useDomainAdminAccess=False): def stripNonShowFields(shareddrive): if orgUnitIdToPathMap: @@ -65445,7 +65448,7 @@ def printShowSharedDrives(users, useDomainAdminAccess=False): SHAREDDRIVE_FIELDS_CHOICE_MAP.update(SHAREDDRIVE_LIST_FIELDS_CHOICE_MAP) showOrgUnitPaths = True orgUnitIdToPathMap = None - guiRoles = False + guiRoles = showItemCountOnly = False while Cmd.ArgumentsRemaining(): myarg = getArgument() if csvPF and myarg == 'todrive': @@ -65475,6 +65478,9 @@ def printShowSharedDrives(users, useDomainAdminAccess=False): showOrgUnitPaths = not getBoolean() elif myarg == 'guiroles': guiRoles = getBoolean() + elif myarg == 'showitemcountonly': + showItemCountOnly = True + showOrgUnitPaths = False else: FJQC.GetFormatJSONQuoteChar(myarg, True) if query and not useDomainAdminAccess: @@ -65544,6 +65550,9 @@ def printShowSharedDrives(users, useDomainAdminAccess=False): jcount = len(matchedFeed) if jcount == 0: setSysExitRC(NO_ENTITIES_FOUND_RC) + if showItemCountOnly: + writeStdout(f'{jcount}\n') + return if not csvPF: if not FJQC.formatJSON: entityPerformActionNumItems([Ent.USER, user], jcount, Ent.SHAREDDRIVE, i, count) @@ -65574,9 +65583,11 @@ def doPrintShowSharedDrives(): # gam print oushareddrives [todrive *] # [ou|org|orgunit ] # [formatjson [quotechar ]] +# [showitemcountonly] # gam show oushareddrives # [ou|org|orgunit ] # [formatjson] +# [showitemcountonly] def doPrintShowOrgunitSharedDrives(): def _getOrgUnitSharedDriveInfo(shareddrive): shareddrive['driveId'] = shareddrive['name'].rsplit(';')[1] @@ -65605,12 +65616,15 @@ def doPrintShowOrgunitSharedDrives(): csvPF = CSVPrintFile(['name', 'type', 'member', 'memberUri', 'driveId', 'driveName', 'orgUnitPath']) if Act.csvFormat() else None FJQC = FormatJSONQuoteChar(csvPF) orgUnitPath = '/' + showItemCountOnly = False while Cmd.ArgumentsRemaining(): myarg = getArgument() if csvPF and myarg == 'todrive': csvPF.GetTodriveParameters() elif myarg in {'ou', 'org', 'orgunit'}: orgUnitPath = getString(Cmd.OB_ORGUNIT_ITEM) + elif myarg == 'showitemcountonly': + showItemCountOnly = True else: FJQC.GetFormatJSONQuoteChar(myarg, True) if csvPF and FJQC.formatJSON: @@ -65625,6 +65639,9 @@ def doPrintShowOrgunitSharedDrives(): jcount = len(sds) if jcount == 0: setSysExitRC(NO_ENTITIES_FOUND_RC) + if showItemCountOnly: + writeStdout(f'{jcount}\n') + return if not csvPF: if not FJQC.formatJSON: entityPerformActionNumItems([Ent.ORGANIZATIONAL_UNIT, orgUnitPath], jcount, Ent.SHAREDDRIVE)