Skip to content

Commit

Permalink
Updated gam copy drivefile to handle the following error: ERROR: in…
Browse files Browse the repository at this point in the history
…ternalError - Internal Error
  • Loading branch information
taers232c committed Jun 7, 2021
1 parent fc386d3 commit 701f6fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ If an item contains spaces, it should be surrounded by ".
<CalendarItem> ::= <EmailAddress>|<String>
<GIGroupItem> ::= <EmailAddress>|<UniqueID>|groups/<String>
<CIGroupType> ::= customer|group|serviceaccount|user
<ChatRoom> ::= <String>
<ChatSpace> ::= <String>
<ClassroomInvitationID> ::= <String>
<ClientID> ::= <String>
<CommandID> ::= <String>
Expand Down Expand Up @@ -500,7 +500,7 @@ If an item contains spaces, it should be surrounded by ".
<AssetTagList> ::= "<AssetTag>(,<AssetTag>)*"
<CalendarACLScopeList> ::= "<CalendarACLScope>(,<CalendarACLScope>)*"
<CalendarList> ::= "<CalendarItem>(,<CalendarItem>)*"
<ChatRoomList> ::= "<ChatRoom>(,<ChatRoom>)*"
<ChatSpaceList> ::= "<ChatSpace>(,<ChatSpace>)*"
<CIGroupTypeList> ::= "<CIGroupType>(,<CIGroupType>)*"
<ClassroomInvitationIDList> ::= "<ClassroomInvitationID>(,<ClassroomInvitationID>)*"
<ContactGroupList> ::= "<ContactGroupItem>(,<ContactGroupItem>)*"
Expand Down Expand Up @@ -4593,8 +4593,9 @@ gam <UserTypeEntity> show datastudiopermissions
ignoredefaultvisibility|
usecontentasindexabletext

gam <UserTypeEntity> create|add drivefile [drivefilename <DriveFileName>]
<DriveFileCreateAttribute>* [stripnameprefix <String>]
gam <UserTypeEntity> create|add drivefile
[localfile <FileName>|-] [drivefilename <DriveFileName>] [stripnameprefix <String>]
<DriveFileCreateAttribute>*
[enforcesingleparent <Boolean>]
[csv [todrive <ToDriveAttribute>*]] [returnidonly|returnlinkonly|returneditlinkonly|showdetails]

Expand All @@ -4611,7 +4612,7 @@ gam <UserTypeEntity> create|add drivefile [drivefilename <DriveFileName>]
(removeanyownerparentname <DriveFolderName>))

gam <UserTypeEntity> update drivefile <DriveFileEntity> [copy] [returnidonly|returnlinkonly]
[retainname | (newfilename <DriveFileName>)] [stripnameprefix <String>]
[localfile <FileName>|-] [retainname | (newfilename <DriveFileName>)] [stripnameprefix <String>]
<DriveFileUpdateAttribute>* [enforcesingleparent <Boolean>]
[gsheet|csvsheet <SheetEntity>] [charset <CharSet>] [columndelimiter <Character>]

Expand Down
7 changes: 7 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
6.03.34

Updated `gam copy drivefile` to handle the following error:
```
ERROR: internalError - Internal Error
```

6.03.33

Added option `stripnameprefix <String>` to `gam create|copy|update drivefile` to aid in the following situation.
Expand Down
13 changes: 8 additions & 5 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__author__ = 'Ross Scroggs <[email protected]>'
__version__ = '6.03.33'
__version__ = '6.03.34'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

import base64
Expand Down Expand Up @@ -3987,6 +3987,7 @@ def getSvcAcctCredentials(scopesOrAPI, userEmail):
try:
credentials = JWTCredentials.from_service_account_info(GM.Globals[GM.OAUTH2SERVICE_JSON_DATA],
audience=f'https://{scopesOrAPI}.googleapis.com/')
credentials.project_id = GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['project_id']
except (ValueError, IndexError, KeyError):
invalidOauth2serviceJsonExit()
GM.Globals[GM.CURRENT_SVCACCT_USER] = userEmail
Expand Down Expand Up @@ -43828,7 +43829,8 @@ def _recursiveFolderCopy(drive, user, i, count, j, jcount, source, newFolderTitl
child.pop('writersCanShare', None)
try:
result = callGAPI(drive.files(), 'copy',
throwReasons=GAPI.DRIVE_COPY_THROW_REASONS,
bailOnInternalError=True,
throwReasons=GAPI.DRIVE_COPY_THROW_REASONS+[GAPI.INTERNAL_ERROR],
fileId=childId, body=child, fields='id,name', supportsAllDrives=True)
entityModifierNewValueItemValueListActionPerformed([Ent.USER, user, Ent.DRIVE_FILE, childTitle],
Act.MODIFIER_TO, result['name'], [Ent.DRIVE_FILE_ID, result['id']], k, kcount)
Expand All @@ -43839,7 +43841,7 @@ def _recursiveFolderCopy(drive, user, i, count, j, jcount, source, newFolderTitl
statistics, STAT_FILE_PERMISSIONS_FAILED, copyMoveOptions)
except (GAPI.fileNotFound, GAPI.forbidden, GAPI.internalError, GAPI.insufficientFilePermissions, GAPI.unknownError,
GAPI.invalid, GAPI.cannotCopyFile, GAPI.badRequest, GAPI.responsePreparationFailure, GAPI.fileNeverWritable,
GAPI.teamDrivesSharingRestrictionNotAllowed, GAPI.rateLimitExceeded, GAPI.userRateLimitExceeded) as e:
GAPI.teamDrivesSharingRestrictionNotAllowed, GAPI.rateLimitExceeded, GAPI.userRateLimitExceeded, GAPI.internalError) as e:
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE, childTitle], str(e), k, kcount)
_incrStatistic(statistics, STAT_FILE_FAILED)
Ind.Decrement()
Expand Down Expand Up @@ -43996,7 +43998,8 @@ def _recursiveFolderCopy(drive, user, i, count, j, jcount, source, newFolderTitl
source.pop('writersCanShare', None)
source.update(copyBody)
result = callGAPI(drive.files(), 'copy',
throwReasons=GAPI.DRIVE_COPY_THROW_REASONS,
bailOnInternalError=True,
throwReasons=GAPI.DRIVE_COPY_THROW_REASONS+[GAPI.INTERNAL_ERROR],
fileId=fileId,
ignoreDefaultVisibility=copyParameters[DFA_IGNORE_DEFAULT_VISIBILITY],
keepRevisionForever=copyParameters[DFA_KEEP_REVISION_FOREVER],
Expand All @@ -44012,7 +44015,7 @@ def _recursiveFolderCopy(drive, user, i, count, j, jcount, source, newFolderTitl
statistics, STAT_FILE_PERMISSIONS_FAILED, copyMoveOptions)
except (GAPI.fileNotFound, GAPI.forbidden, GAPI.internalError, GAPI.insufficientFilePermissions, GAPI.unknownError,
GAPI.invalid, GAPI.cannotCopyFile, GAPI.badRequest, GAPI.responsePreparationFailure, GAPI.fileNeverWritable,
GAPI.teamDrivesSharingRestrictionNotAllowed, GAPI.rateLimitExceeded, GAPI.userRateLimitExceeded) as e:
GAPI.teamDrivesSharingRestrictionNotAllowed, GAPI.rateLimitExceeded, GAPI.userRateLimitExceeded, GAPI.internalError) as e:
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER_ID, fileId], str(e), j, jcount)
_incrStatistic(statistics, STAT_FILE_FAILED)
except (GAPI.serviceNotAvailable, GAPI.authError, GAPI.domainPolicy) as e:
Expand Down

0 comments on commit 701f6fe

Please sign in to comment.