Skip to content

Commit

Permalink
Added options timestamp [<Boolean>] and timeformat <String> to `g…
Browse files Browse the repository at this point in the history
…am <UserTypeEntity> create|update drivefile`
  • Loading branch information
taers232c committed Oct 9, 2024
1 parent e3ba323 commit dffdd2e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/GamUpdates.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Add the `-s` option to the end of the above commands to suppress creating the `g

See [Downloads-Installs-GAM7](https://github.com/GAM-team/GAM/wiki/Downloads-Installs) for Windows or other options, including manual installation

### 7.00.15

Added options `timestamp [<Boolean>]` and `timeformat <String>` to `gam <UserTypeEntity> create|update drivefile` that allow
adding a timestamp to a created/updated file name.

### 7.00.14

Retry the following unexpected errors in `gam print users`.
Expand Down
4 changes: 2 additions & 2 deletions docs/How-to-Upgrade-Legacy-GAM-to-GAM7.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ writes the credentials into the file oauth2.txt.
admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt
admin@server:/Users/admin$ gam version
WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found
GAM 7.00.14 - https://github.com/GAM-team/GAM - pyinstaller
GAM 7.00.15 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
MacOS Sonoma 14.5 x86_64
Expand Down Expand Up @@ -923,7 +923,7 @@ writes the credentials into the file oauth2.txt.
C:\>del C:\GAMConfig\oauth2.txt
C:\>gam version
WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found
GAM7 7.00.14 - https://github.com/GAM-team/GAM - pythonsource
GAM7 7.00.15 - https://github.com/GAM-team/GAM - pythonsource
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
Windows-10-10.0.17134 AMD64
Expand Down
14 changes: 13 additions & 1 deletion docs/Users-Drive-Files-Manage.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!# Users - Drive Files Manage
# Users - Drive Files Manage
- [API documentation](#api-documentation)
- [Query documentation](Users-Drive-Query)
- [Python Regular Expressions](Python-Regular-Expressions) Sub function
Expand Down Expand Up @@ -170,6 +170,7 @@ gam <UserTypeEntity> create|add drivefile
[(localfile <FileName>|-)|(url <URL>)]
[(drivefilename|newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
[stripnameprefix <String>] [noduplicate]
[timestamp [<Boolean>]] [timeformat <String>]
<DriveFileCreateAttribute>*
[(csv [todrive <ToDriveAttribute>*] (addcsvdata <FieldName> <String>)*) |
(returnidonly|returnlinkonly|returneditlinkonly|showdetails)]
Expand Down Expand Up @@ -205,6 +206,11 @@ These are the naming rules:

If `stripnameprefix <String>` is specified, `<String>` will be stripped from the front of the Google Drive file name if present.

You can add a timestamp to the FileName.
* `tdtimestamp` - Should a timestamp (of the time the file is uploaded to Google) be added to the title of the uploaded file.
* `tdtimeformat` - Format of the timestamp added to the title of the uploaded file; if not specified, an ISO format timestamp is added.
* See: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

If `noduplicate` is specfied, GAM will issue a warning and not perform the create if a non-trashed item with the same name (regardless of MIME type)
exists in the parent folder.

Expand Down Expand Up @@ -464,6 +470,7 @@ gam <UserTypeEntity> update drivefile <DriveFileEntity> [copy] [returnidonly|ret
[(localfile <FileName>|-)|(url <URL>)]
[retainname | (newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
[stripnameprefix <String>]
[timestamp [<Boolean>]] [timeformat <String>]
<DriveFileUpdateAttribute>*
[(gsheet|csvsheet <SheetEntity> [clearfilter])|(addsheet <String>)]
[charset <Charset>] [columndelimiter <Character>]
Expand Down Expand Up @@ -513,6 +520,11 @@ For more complex renaming, use `replacefilename <RegularExpression> <String>`:

If `retainname` is not specified and `stripnameprefix <String>` is specified, `<String>` will be stripped from the front of the Google Drive file name if present.

You can add a timestamp to the FileName.
* `tdtimestamp` - Should a timestamp (of the time the file is uploaded to Google) be added to the title of the uploaded file.
* `tdtimeformat` - Format of the timestamp added to the title of the uploaded file; if not specified, an ISO format timestamp is added.
* See: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

You can update a specific sheet within a Google spreadsheet or add a new sheet to the spreadsheet
* `gsheet|csvsheet <String>` - Specify a sheet by name in a Google Sheets file to be updated
* `gsheet|csvsheet id:<Number>` - Specify a sheet by ID in a Google Sheets file to be updated
Expand Down
12 changes: 6 additions & 6 deletions docs/Version-and-Help.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Print the current version of Gam with details
```
gam version
GAM 7.00.14 - https://github.com/GAM-team/GAM - pyinstaller
GAM 7.00.15 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
MacOS Sonoma 14.5 x86_64
Expand All @@ -15,7 +15,7 @@ Time: 2023-06-02T21:10:00-07:00
Print the current version of Gam with details and time offset information
```
gam version timeoffset
GAM 7.00.14 - https://github.com/GAM-team/GAM - pyinstaller
GAM 7.00.15 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
MacOS Sonoma 14.5 x86_64
Expand All @@ -27,7 +27,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
GAM 7.00.14 - https://github.com/GAM-team/GAM - pyinstaller
GAM 7.00.15 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
MacOS Sonoma 14.5 x86_64
Expand Down Expand Up @@ -64,15 +64,15 @@ MacOS High Sierra 10.13.6 x86_64
Path: /Users/Admin/bin/gam7
Version Check:
Current: 5.35.08
Latest: 7.00.14
Latest: 7.00.15
echo $?
1
```

Print the current version number without details
```
gam version simple
7.00.14
7.00.15
```
In Linux/MacOS you can do:
```
Expand All @@ -82,7 +82,7 @@ echo $VER
Print the current version of Gam and address of this Wiki
```
gam help
GAM 7.00.14 - https://github.com/GAM-team/GAM
GAM 7.00.15 - https://github.com/GAM-team/GAM
GAM Team <google-apps-manager@googlegroups.com>
Python 3.12.7 64-bit final
MacOS Sonoma 14.5 x86_64
Expand Down
2 changes: 2 additions & 0 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6414,6 +6414,7 @@ gam <UserTypeEntity> create|add drivefile
[(localfile <FileName>|-)|(url <URL>)]
[(drivefilename|newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
[stripnameprefix <String>] [noduplicate]
[timestamp [<Boolean>]] [timeformat <String>]
<DriveFileCreateAttribute>*
[(csv [todrive <ToDriveAttribute>*] (addcsvdata <FieldName> currenttime|<String>)*) |
(returnidonly|returnlinkonly|returneditlinkonly|showdetails)]
Expand All @@ -6434,6 +6435,7 @@ gam <UserTypeEntity> update drivefile <DriveFileEntity> [copy] [returnidonly|ret
[(localfile <FileName>|-)|(url <URL>)]
[retainname | (newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
[stripnameprefix <String>]
[timestamp [<Boolean>]] [timeformat <String>]
<DriveFileUpdateAttribute>*
[(gsheet|csvsheet <SheetEntity> [clearfilter])|(addsheet <String>)]
[charset <CharSet>] [columndelimiter <Character>]
Expand Down
5 changes: 5 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
7.00.15

Added options `timestamp [<Boolean>]` and `timeformat <String>` to `gam <UserTypeEntity> create|update drivefile` that allow
adding a timestamp to a created/updated file name.

7.00.14

Retry the following unexpected errors in `gam print users`.
Expand Down
28 changes: 26 additions & 2 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""

__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__version__ = '7.00.14'
__version__ = '7.00.15'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

#pylint: disable=wrong-import-position
Expand Down Expand Up @@ -52146,6 +52146,8 @@ def _identifyRoot():
DFA_KWARGS = 'kwargs'
DFA_SEARCHARGS = 'searchargs'
DFA_USE_CONTENT_AS_INDEXABLE_TEXT = 'useContentAsIndexableText'
DFA_TIMESTAMP = 'timestamp'
DFA_TIMEFORMAT = 'timeformat'

def _driveFileParentSpecified(parameters):
return (parameters[DFA_PARENTID] or parameters[DFA_PARENTQUERY] or
Expand Down Expand Up @@ -52420,7 +52422,9 @@ def initDriveFileAttributes():
DFA_SHAREDDRIVE_PARENTQUERY: None,
DFA_KWARGS: {},
DFA_SEARCHARGS: {},
DFA_USE_CONTENT_AS_INDEXABLE_TEXT: False}
DFA_USE_CONTENT_AS_INDEXABLE_TEXT: False,
DFA_TIMESTAMP: False,
DFA_TIMEFORMAT: None}

DRIVEFILE_PROPERTY_VISIBILITY_CHOICE_MAP = {
'private': 'appProperties',
Expand Down Expand Up @@ -52604,6 +52608,10 @@ def getDriveFileAttribute(myarg, body, parameters, updateCmd):
body['contentHints']['indexableText'] = getString(Cmd.OB_STRING)
elif myarg == 'securityupdate':
body['linkShareMetadata'] = {'securityUpdateEnabled': getBoolean(), 'securityUpdateEligible': True}
elif myarg == 'timestamp':
parameters[DFA_TIMESTAMP] = getBoolean()
elif myarg == 'timeformat':
parameters[DFA_TIMEFORMAT] = getString(Cmd.OB_STRING, minLen=0)
elif getDriveFileCopyAttribute(myarg, body, parameters):
pass
else:
Expand Down Expand Up @@ -57125,6 +57133,14 @@ def processFilenameReplacements(name, replacements):
name = re.sub(replacement[0], replacement[1], name)
return name

def addTimestampToFilename(parameters, body):
tdtime = datetime.datetime.now(GC.Values[GC.TIMEZONE])
body['name'] += ' - '
if not parameters[DFA_TIMEFORMAT]:
body['name'] += ISOformatTimeStamp(tdtime)
else:
body['name'] += tdtime.strftime(parameters[DFA_TIMEFORMAT])

createReturnItemMap = {
'returnidonly': 'id',
'returnlinkonly': 'webViewLink',
Expand All @@ -57135,6 +57151,7 @@ def processFilenameReplacements(name, replacements):
# [(localfile <FileName>|-)|(url <URL>)]
# [(drivefilename|newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
# [stripnameprefix <String>]
# [timestamp <Boolean>]] [timeformat <String>]
# <DriveFileCreateAttribute>* [noduplicate]
# [(csv [todrive <ToDriveAttribute>*] (addcsvdata <FieldName> <String>)*)) |
# (returnidonly|returnlinkonly|returneditlinkonly|showdetails)]
Expand Down Expand Up @@ -57180,6 +57197,8 @@ def createDriveFile(users):
body['name'] = newName
else:
body['name'] = 'Untitled'
if parameters[DFA_TIMESTAMP]:
addTimestampToFilename(parameters, body)
if parameters[DFA_LOCALFILEPATH]:
if parameters[DFA_LOCALFILEPATH] != '-' and parameters[DFA_PRESERVE_FILE_TIMES]:
setPreservedFileTimes(body, parameters, False)
Expand Down Expand Up @@ -57658,6 +57677,7 @@ def checkDriveFileShortcut(users):
# [(localfile <FileName>|-)|(url <URL>)]
# [retainname | (newfilename <DriveFileName>) | (replacefilename <RegularExpression> <String>)*]
# [stripnameprefix <String>]
# [timestamp <Boolean>]] [timeformat <String>]
# <DriveFileUpdateAttribute>*
# [(gsheet|csvsheet <SheetEntity> [clearfilter])|(addsheet <String>)]
# [charset <String>] [columndelimiter <Character>]
Expand Down Expand Up @@ -57763,6 +57783,8 @@ def updateDriveFile(users):
body['name'] = processFilenameReplacements(newName, parameters[DFA_REPLACEFILENAME])
else:
body['name'] = newName
if parameters[DFA_TIMESTAMP]:
addTimestampToFilename(parameters, body)
if addSheetEntity or updateSheetEntity:
entityValueList = [Ent.USER, user, Ent.DRIVE_FILE_ID, fileId]
try:
Expand Down Expand Up @@ -57891,6 +57913,8 @@ def updateDriveFile(users):
body['name'] = processFilenameReplacements(newName, parameters[DFA_REPLACEFILENAME])
else:
body['name'] = newName
if parameters[DFA_TIMESTAMP]:
addTimestampToFilename(parameters, body)
Ind.Increment()
j = 0
for fileId in fileIdEntity['list']:
Expand Down

0 comments on commit dffdd2e

Please sign in to comment.