From 06a4c7a8c93aed118c7e10f6ef54b7246cfd8698 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Wed, 20 Dec 2023 12:32:10 -0800 Subject: [PATCH] Added option `copysubfilesownedby any|me|others` to `gam copy drivefile --- docs/GamUpdates.md | 6 ++++++ docs/How-to-Upgrade-from-Standard-GAM.md | 4 ++-- docs/Users-Drive-Copy-Move.md | 6 ++++++ docs/Users-Gmail-Messages-Threads.md | 3 +++ docs/Version-and-Help.md | 12 ++++++------ src/GamCommands.txt | 4 +++- src/GamUpdate.txt | 6 ++++++ src/gam/__init__.py | 13 ++++++++++--- 8 files changed, 42 insertions(+), 12 deletions(-) diff --git a/docs/GamUpdates.md b/docs/GamUpdates.md index 8290f8ce..7faea96a 100644 --- a/docs/GamUpdates.md +++ b/docs/GamUpdates.md @@ -10,6 +10,12 @@ Add the `-s` option to the end of the above commands to suppress creating the `g See [Downloads](https://github.com/taers232c/GAMADV-XTD3/wiki/Downloads) for Windows or other options, including manual installation +### 6.66.15 + +Added option `copysubfilesownedby any|me|others` to `gam copy drivefile` that allows +specification of which source folder sub files to copy based on file ownership; the default is `all`. +This only applies when files are being copied from a 'My Drive'. + ### 6.66.14 Updated `gam modify messages` to recognize the following error: diff --git a/docs/How-to-Upgrade-from-Standard-GAM.md b/docs/How-to-Upgrade-from-Standard-GAM.md index dfce0b4d..8b83784a 100644 --- a/docs/How-to-Upgrade-from-Standard-GAM.md +++ b/docs/How-to-Upgrade-from-Standard-GAM.md @@ -334,7 +334,7 @@ writes the credentials into the file oauth2.txt. admin@server:/Users/admin/bin/gamadv-xtd3$ rm -f /Users/admin/GAMConfig/oauth2.txt admin@server:/Users/admin/bin/gamadv-xtd3$ ./gam version WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found -GAMADV-XTD3 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.10.8 64-bit final MacOS High Sierra 10.13.6 x86_64 @@ -1002,7 +1002,7 @@ writes the credentials into the file oauth2.txt. C:\GAMADV-XTD3>del C:\GAMConfig\oauth2.txt C:\GAMADV-XTD3>gam version WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found -GAMADV-XTD3 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.0 64-bit final Windows-10-10.0.17134 AMD64 diff --git a/docs/Users-Drive-Copy-Move.md b/docs/Users-Drive-Copy-Move.md index 2a9c2cfc..32e79d97 100644 --- a/docs/Users-Drive-Copy-Move.md +++ b/docs/Users-Drive-Copy-Move.md @@ -68,6 +68,7 @@ gam copy drivefile [mergewithparent []] [recursive [depth ]] [copysubfiles []] [filenamematchpattern ] [filemimetype [not] ] + [copysubfilesownedby any|me|others] [copysubfolders []] [foldernamematchpattern ] [copysubshortcuts []] [shortcutnamematchpattern ] * @@ -148,6 +149,11 @@ You can specify `` patterns that limit the items copied based * `foldernamematchpattern ` - Only folders whose name matches `` are copied * `shortcutnamematchpattern ` - Only shortcuts whose name matches `` are copied +### By default, when copying sub files, all files, regardless of ownership, are copied. +* `copysubfilesownedby all` - All files, regardless of ownership, are copied. +* `copysubfilesownedby me` - Only files owned by `` are copied. +* `copysubfilesownedby others` - Only files not owned by `` are copied. + ### Specify a new name for the file/folder * `newfilename ` - The copied file/folder will be named `` * If `stripnameprefix ` is specified, `` will be stripped from the front of `` diff --git a/docs/Users-Gmail-Messages-Threads.md b/docs/Users-Gmail-Messages-Threads.md index ef31a44a..f4ce1fd0 100644 --- a/docs/Users-Gmail-Messages-Threads.md +++ b/docs/Users-Gmail-Messages-Threads.md @@ -204,6 +204,9 @@ You can also replace ` ` with `-` but it doesn't seem to be required. * `query "label:Foo -Bar-"` - Select messages with label `Foo (Bar)` +You can have GAM do the substitutions for you with the `matchlabel ` option. +* `matchlabel "Foo (Bar)"` is converted to `query "label:Foo -Bar-"` + ## Draft messages Add a draft message to a user's mailbox. ``` diff --git a/docs/Version-and-Help.md b/docs/Version-and-Help.md index d8e27696..9d78b459 100644 --- a/docs/Version-and-Help.md +++ b/docs/Version-and-Help.md @@ -4,7 +4,7 @@ Print the current version of Gam with details ``` gam version -GAMADV-XTD3 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.0 64-bit final MacOS Monterey 12.7 x86_64 @@ -16,7 +16,7 @@ Time: 2023-06-02T21:10:00-07:00 Print the current version of Gam with details and time offset information ``` gam version timeoffset -GAMADV-XTD3 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.0 64-bit final MacOS Monterey 12.7 x86_64 @@ -28,7 +28,7 @@ Your system time differs from www.googleapis.com by less than 1 second Print the current version of Gam with extended details and SSL information ``` gam version extended -GAMADV-XTD3 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource +GAMADV-XTD3 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource Ross Scroggs Python 3.12.0 64-bit final MacOS Monterey 12.7 x86_64 @@ -65,7 +65,7 @@ MacOS High Sierra 10.13.6 x86_64 Path: /Users/Admin/bin/gamadv-xtd3 Version Check: Current: 5.35.08 - Latest: 6.66.14 + Latest: 6.66.15 echo $? 1 ``` @@ -73,7 +73,7 @@ echo $? Print the current version number without details ``` gam version simple -6.66.14 +6.66.15 ``` In Linux/MacOS you can do: ``` @@ -83,7 +83,7 @@ echo $VER Print the current version of Gam and address of this Wiki ``` gam help -GAM 6.66.14 - https://github.com/taers232c/GAMADV-XTD3 +GAM 6.66.15 - https://github.com/taers232c/GAMADV-XTD3 Ross Scroggs Python 3.12.0 64-bit final MacOS Monterey 12.7 x86_64 diff --git a/src/GamCommands.txt b/src/GamCommands.txt index fbab9420..c798f599 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -6006,7 +6006,9 @@ gam copy drivefile [summary []] [showpermissionmessages []] [] [mergewithparent []] [recursive [depth ]] - [copysubfiles []] [filenamematchpattern ] [filemimetype [not] ] + [copysubfiles []] [filenamematchpattern ] + [filemimetype [not] ] + [copysubfilesownedby any|me|others] [copysubfolders []] [foldernamematchpattern ] [copysubshortcuts []] [shortcutnamematchpattern ] * diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 9a0019a2..7714bc8e 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -2,6 +2,12 @@ Merged GAM-Team version +6.66.15 + +Added option `copysubfilesownedby any|me|others` to `gam copy drivefile` that allows +specification of which source folder sub files to copy based on file ownership; the default is `all`. +This only applies when files are being copied from a 'My Drive'. + 6.66.14 Updated `gam modify messages` to recognize the following error: diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 1c2ac9d8..7317c3d2 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -55263,6 +55263,7 @@ def initCopyMoveOptions(copyCmd): 'shortcutNameMatchPattern': None, 'fileMimeTypes': set(), 'notMimeTypes': False, + 'copySubFilesOwnedBy': None, } DUPLICATE_FILE_CHOICES = { @@ -55378,6 +55379,8 @@ def getCopyMoveOptions(myarg, copyMoveOptions): copyMoveOptions['notMimeTypes'] = checkArgumentPresent('not') for mimeType in getString(Cmd.OB_MIMETYPE_LIST).lower().replace(',', ' ').split(): copyMoveOptions['fileMimeTypes'].add(validateMimeType(mimeType)) + elif myarg == 'copysubfilesownedby': + copyMoveOptions['copySubFilesOwnedBy'] = getChoice(SHOW_OWNED_BY_CHOICE_MAP, mapChoice=True) else: return False return True @@ -56100,7 +56103,7 @@ def copyDriveFile(users): entityActionFailedWarning(kvList+[Ent.DRIVE_FILE_SHORTCUT, childName], str(e), k, kcount) _incrStatistic(statistics, STAT_FILE_FAILED) - def _checkChildCopyAllowed(childMimeType, childName): + def _checkChildCopyAllowed(childMimeType, childName, child): if childMimeType == MIMETYPE_GA_FOLDER: if not copyMoveOptions['copySubFolders']: return False @@ -56112,6 +56115,9 @@ def copyDriveFile(users): else: if not copyMoveOptions['copySubFiles']: return False + if copyMoveOptions['copySubFilesOwnedBy'] is not None: + if child.get('driveId', None) is None and child.get('ownedByMe', False) != copyMoveOptions['copySubFilesOwnedBy']: + return False if copyMoveOptions['fileMimeTypes']: if not copyMoveOptions['notMimeTypes']: if childMimeType not in copyMoveOptions['fileMimeTypes']: @@ -56143,7 +56149,7 @@ def copyDriveFile(users): q=WITH_PARENTS.format(folderId), orderBy='folder desc,name,modifiedTime desc', fields='nextPageToken,files(id,name,parents,appProperties,capabilities,contentHints,copyRequiresWriterPermission,'\ - 'description,folderColorRgb,mimeType,modifiedTime,properties,starred,driveId,trashed,viewedByMeTime,writersCanShare,'\ + 'description,folderColorRgb,mimeType,modifiedTime,ownedByMe,properties,starred,driveId,trashed,viewedByMeTime,writersCanShare,'\ 'shortcutDetails(targetId,targetMimeType))', pageSize=GC.Values[GC.DRIVE_MAX_RESULTS], **sourceSearchArgs) kcount = len(sourceChildren) @@ -56169,10 +56175,11 @@ def copyDriveFile(users): if childId in copiedTargetFiles: # Don't recopy file/folder copied into a sub-folder continue kvList = [Ent.USER, user, _getEntityMimeType(child), childNameId] - if not _checkChildCopyAllowed(childMimeType, childName): + if not _checkChildCopyAllowed(childMimeType, childName, child): if not suppressNotSelectedMessages: entityActionNotPerformedWarning(kvList, Msg.NOT_SELECTED, k, kcount) continue + child.pop('ownedByMe', None) trashed = child.pop('trashed', False) if (childId == newFolderId) or (excludeTrashed and trashed): entityActionNotPerformedWarning(kvList,