Skip to content

Commit

Permalink
Improve conversion of Shared Drive names to IDs, handle single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
taers232c committed Jan 30, 2022
1 parent 302aab4 commit 25c8b3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ call retries to fail with the following error:
Temporary error: notFound - @CourseNotFound The course was not found.
```

Improved performance when converting Shared Drive names to IDs.

Updated code to handle Shared Drive names that contain single quotes.

6.14.07

Corrected `gam.cfg` variable `cmdlog_max__backups` to be `cmdlog_max_backups`.
Expand Down
29 changes: 21 additions & 8 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41902,24 +41902,37 @@ def _getTDKeywordColonValue(kwColonValue):

def _convertTeamDriveNameToId(drive, user, i, count, fileIdEntity, useDomainAdminAccess=False):
try:
feed = callGAPIpages(drive.drives(), 'list', 'drives',
throwReasons=GAPI.DRIVE_USER_THROW_REASONS,
useDomainAdminAccess=useDomainAdminAccess,
fields='nextPageToken,drives(id,name)', pageSize=100)
if "\\'" in fileIdEntity['teamdrivename']:
name = fileIdEntity['teamdrivename']
else:
name = fileIdEntity['teamdrivename'].replace("'", "\\'")
tdlist = callGAPIpages(drive.drives(), 'list', 'drives',
throwReasons=GAPI.DRIVE_USER_THROW_REASONS,
useDomainAdminAccess=useDomainAdminAccess,
q=f"name='{name}'",
fields='nextPageToken,drives(id,name)', pageSize=100)
if "\\'" in fileIdEntity['teamdrivename']:
fileIdEntity['teamdrivename'] = fileIdEntity['teamdrivename'].replace("\\'", "'")
if not tdlist:
name = fileIdEntity['teamdrivename'].lower()
feed = callGAPIpages(drive.drives(), 'list', 'drives',
throwReasons=GAPI.DRIVE_USER_THROW_REASONS,
useDomainAdminAccess=useDomainAdminAccess,
fields='nextPageToken,drives(id,name)', pageSize=100)
tdlist = [td for td in feed if td['name'].lower() == name]
except (GAPI.serviceNotAvailable, GAPI.authError, GAPI.domainPolicy):
entityActionFailedWarning([Ent.USER, user, Ent.TEAMDRIVE_NAME, fileIdEntity['teamdrivename']], Msg.DOES_NOT_EXIST, i, count)
return False
tddrivenamelower = fileIdEntity['teamdrivename'].lower()
tdlist = [td['id'] for td in feed if td['name'].lower() == tddrivenamelower]
jcount = len(tdlist)
if jcount == 1:
fileIdEntity['teamdrive']['driveId'] = tdlist[0]
fileIdEntity['teamdrive']['driveId'] = tdlist[0]['id']
return True
if jcount == 0:
entityActionFailedWarning([Ent.USER, user, Ent.TEAMDRIVE_NAME, fileIdEntity['teamdrivename']], Msg.DOES_NOT_EXIST, i, count)
else:
entityActionFailedWarning([Ent.USER, user, Ent.TEAMDRIVE_NAME, fileIdEntity['teamdrivename']],
Msg.MULTIPLE_ENTITIES_FOUND.format(Ent.Plural(Ent.TEAMDRIVE_ID), jcount, ','.join(tdlist)), i, count)
Msg.MULTIPLE_ENTITIES_FOUND.format(Ent.Plural(Ent.TEAMDRIVE_ID), jcount,
','.join([td['id'] for td in tdlist])), i, count)
return False

def _getTeamDriveNameFromId(drive, teamDriveId):
Expand Down

0 comments on commit 25c8b3f

Please sign in to comment.