Skip to content

Commit

Permalink
Updated gam <UserTypeEntity> modify messages to improve error handl…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
taers232c committed Aug 29, 2024
1 parent d4e6ab4 commit 515288e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: taers232c.GAMADV-XTD3
release-tag: v6.80.16
release-tag: v6.80.17
max-versions-to-keep: 1 # keep only latest versions
installers-regex: '\.msi$'
token: ${{ secrets.WINGET_TOKEN }}
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ deploy:
file: gamadv-xtd3-$GAMVERSION-*
skip_cleanup: true
draft: true
# edge: true
edge:
branch: v2.0.3-beta.4
edge: true
# edge:
# branch: v2.0.3-beta.4
on:
repo: taers232c/GAMADV-XTD3

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

Updated `gam <UserTypeEntity> modify messages` to improve error handling.

6.80.16

Fixed bug in `gam print vaultcounts` that caused a trap.
Expand Down
38 changes: 27 additions & 11 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""

__author__ = 'Ross Scroggs <ross.scroggs@gmail.com>'
__version__ = '6.80.16'
__version__ = '6.80.17'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

#pylint: disable=wrong-import-position
Expand Down Expand Up @@ -2409,6 +2409,12 @@ def entityDoesNotExistWarning(entityType, entityName, i=0, count=0):
[Ent.Singular(entityType), entityName, Msg.DOES_NOT_EXIST],
currentCountNL(i, count)))

def entityListDoesNotExistWarning(entityValueList, i=0, count=0):
setSysExitRC(ENTITY_DOES_NOT_EXIST_RC)
writeStderr(formatKeyValueList(Ind.Spaces(),
Ent.FormatEntityValueList(entityValueList)+[Msg.DOES_NOT_EXIST],
currentCountNL(i, count)))

def entityUnknownWarning(entityType, entityName, i=0, count=0):
domain = getEmailAddressDomain(entityName)
if (domain.endswith(GC.Values[GC.DOMAIN])) or (domain.endswith('google.com')):
Expand Down Expand Up @@ -67502,12 +67508,12 @@ def createLabels(users, labelEntity):
if not buildPath:
try:
callGAPI(gmail.users().labels(), 'create',
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.DUPLICATE, GAPI.PERMISSION_DENIED],
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.DUPLICATE, GAPI.INVALID, GAPI.PERMISSION_DENIED],
userId='me', body=body, fields='')
entityActionPerformed([Ent.USER, user, Ent.LABEL, label], l, lcount)
except GAPI.duplicate:
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], Msg.DUPLICATE, l, lcount)
except GAPI.permissionDenied as e:
except (GAPI.invalid, GAPI.permissionDenied) as e:
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], str(e), l, lcount)
except (GAPI.serviceNotAvailable, GAPI.badRequest):
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
Expand Down Expand Up @@ -68036,7 +68042,7 @@ def _initLabelNameMap(userGmailLabels):
labelNameMap[label['name']] = labelNameMap[label['name'].upper()] = label['id']
return labelNameMap

def _convertLabelNamesToIds(gmail, bodyLabels, labelNameMap, addLabelIfMissing):
def _convertLabelNamesToIds(gmail, user, i, count, bodyLabels, labelNameMap, addLabel):
labelIds = []
for label in bodyLabels:
if label in labelNameMap:
Expand All @@ -68045,14 +68051,19 @@ def _convertLabelNamesToIds(gmail, bodyLabels, labelNameMap, addLabelIfMissing):
if label.upper() in labelNameMap:
labelIds.append(labelNameMap[label.upper()])
continue
if not addLabelIfMissing:
if not addLabel:
entityListDoesNotExistWarning([Ent.USER, user, Ent.LABEL, label], i, count)
continue
try:
results = callGAPI(gmail.users().labels(), 'create',
throwReasons=[GAPI.INVALID],
userId='me', body={'labelListVisibility': 'labelShow', 'messageListVisibility': 'show', 'name': label}, fields='id')
except GAPI.invalid as e:
entityActionFailedExit([Ent.LABEL, label], str(e))
action = Act.Get()
Act.Set(Act.CREATE)
entityActionFailedWarning([Ent.USER, user, Ent.LABEL, label], str(e), i, count)
Act.Set(action)
continue
labelNameMap[label] = labelNameMap[label.upper()] = results['id']
labelIds.append(results['id'])
if label.find('/') != -1:
Expand Down Expand Up @@ -68289,7 +68300,7 @@ def _batchDeleteModifyMessages(gmail, function, user, jcount, messageIds, body):
idsList += ',...'
try:
callGAPI(gmail.users().messages(), function,
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.INVALID_MESSAGE_ID, GAPI.INVALID,
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.INVALID_MESSAGE_ID, GAPI.INVALID, GAPI.INVALID_ARGUMENT,
GAPI.FAILED_PRECONDITION, GAPI.PERMISSION_DENIED],
userId='me', body=body)
for messageId in body['ids']:
Expand All @@ -68300,7 +68311,7 @@ def _batchDeleteModifyMessages(gmail, function, user, jcount, messageIds, body):
csvPF.WriteRow({'User': user, entityHeader: messageId, 'action': Act.Performed()})
except (GAPI.serviceNotAvailable, GAPI.badRequest):
mcount += bcount
except (GAPI.invalid, GAPI.permissionDenied) as e:
except (GAPI.invalid, GAPI.invalidArgument, GAPI.permissionDenied) as e:
_processMessageFailed(user, idsList, f'{str(e)} ({mcount+1}-{mcount+bcount}/{jcount})')
mcount += bcount
except GAPI.invalidMessageId:
Expand Down Expand Up @@ -68369,6 +68380,8 @@ def _batchProcessMessagesThreads(service, function, user, jcount, messageIds, **
csvPF.GetTodriveParameters()
else:
unknownArgumentExit()
if function == 'modify' and not addLabelNames and not removeLabelNames:
missingArgumentExit('(addlabel <LabelName>)|(removelabel <LabelName>)')
_finalizeMessageSelectParameters(parameters, True)
includeSpamTrash = Act.Get() in [Act.DELETE, Act.MODIFY, Act.UNTRASH]
if function == 'spam':
Expand All @@ -68387,8 +68400,11 @@ def _batchProcessMessagesThreads(service, function, user, jcount, messageIds, **
if not userGmailLabels:
continue
labelNameMap = _initLabelNameMap(userGmailLabels)
addLabelIds = _convertLabelNamesToIds(gmail, addLabelNames, labelNameMap, True)
removeLabelIds = _convertLabelNamesToIds(gmail, removeLabelNames, labelNameMap, False)
addLabelIds = _convertLabelNamesToIds(gmail, user, i, count, addLabelNames, labelNameMap, True)
removeLabelIds = _convertLabelNamesToIds(gmail, user, i, count, removeLabelNames, labelNameMap, False)
if not addLabelIds and not removeLabelIds:
entityActionNotPerformedWarning([Ent.USER, user], Msg.NO_LABELS_TO_PROCESS, i, count)
continue
try:
if parameters['messageEntity'] is None:
printGettingAllEntityItemsForWhom(Ent.MESSAGE, user, i, count)
Expand Down Expand Up @@ -69039,7 +69055,7 @@ def _appendToHeader(header, value):
if not userGmailLabels:
continue
labelNameMap = _initLabelNameMap(userGmailLabels)
body['labelIds'] = _convertLabelNamesToIds(gmail, addLabelNames, labelNameMap, True)
body['labelIds'] = _convertLabelNamesToIds(gmail, user, i, count, addLabelNames, labelNameMap, True)
else:
body['labelIds'] = ['INBOX']
result = callGAPI(gmail.users().messages(), function,
Expand Down
1 change: 1 addition & 0 deletions src/gam/gamlib/glmsgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
NO_FILTER_ACTIONS = 'No {0} actions specified'
NO_FILTER_CRITERIA = 'No {0} criteria specified'
NO_LABELS_MATCH = 'No Labels match'
NO_LABELS_TO_PROCESS = 'No Labels to process'
NO_MESSAGES_WITH_LABEL = 'No Messages with Label'
NO_PARENTS_TO_CONVERT_TO_SHORTCUTS = 'No parents to convert to shortcuts'
NO_REPORT_AVAILABLE = 'No {0} report available.'
Expand Down

0 comments on commit 515288e

Please sign in to comment.