Added option countsonly to gam <UserTypeEntity> print|show notes

This commit is contained in:
Ross Scroggs
2024-04-04 11:37:41 -07:00
parent 83d464d167
commit 23b0b0f203
7 changed files with 74 additions and 18 deletions

View File

@ -10,6 +10,11 @@ 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.72.08
Added option `countsonly` to `gam <UserTypeEntity> print|show notes` that displays
the number of notes a user owns and the number of notes of user can edit.
### 6.72.07
Updated commands that send emails to not downshift `'First Last<firstlast@domain.com>'` to `'first last<firstlast@domain.com>'`.

View File

@ -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.72.07 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.72.08 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -1006,7 +1006,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.72.07 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.72.08 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
Windows-10-10.0.17134 AMD64

View File

@ -131,13 +131,17 @@ Display all notes
```
gam <UserTypeEntity> show notes
[fields <NotesFieldList>] [filter <String>]
[role owner|writwer]
[role owner|writer]
[countsonly]
[compact|formatjson]
```
By default, GAM displays all non-trashed notes:
* `filter trashed` - Display notes in the trash
* `role owner|writer` - Display notes where the user has the specified role
When option `countsonly` is specified, the number of notes a user owns and the number of notes of user can edit
if displayed.
By default, Gam displays the information as an indented list of keys and values; the note text is displayed as individual lines.
* `compact` - Display the note text with escaped carriage returns as \r and newlines as \n
* `formatjson` - Display the note in JSON format
@ -145,7 +149,8 @@ By default, Gam displays the information as an indented list of keys and values;
```
gam <UserTypeEntity> print notes [todrive <ToDriveAttribute>*]
[fields <NotesFieldList>] [filter <String>]
[role owner|writwer]
[role owner|writer]
[countsonly]
[formatjson [quotechar <Character>]]
```
@ -153,6 +158,9 @@ By default, GAM displays all non-trashed notes:
* `filter trashed` - Display notes in the trash
* `role owner|writer` - Display notes where the user has the specified role
When option `countsonly` is specified, the number of notes a user owns and the number of notes of user can edit
if displayed.
By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain
the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled.
When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output.

View File

@ -3,7 +3,7 @@
Print the current version of Gam with details
```
gam version
GAMADV-XTD3 6.72.07 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.72.08 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -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
GAMADV-XTD3 6.72.07 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.72.08 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -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
GAMADV-XTD3 6.72.07 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
GAMADV-XTD3 6.72.08 - https://github.com/taers232c/GAMADV-XTD3 - pythonsource
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64
@ -64,7 +64,7 @@ MacOS High Sierra 10.13.6 x86_64
Path: /Users/Admin/bin/gamadv-xtd3
Version Check:
Current: 5.35.08
Latest: 6.72.07
Latest: 6.72.08
echo $?
1
```
@ -72,7 +72,7 @@ echo $?
Print the current version number without details
```
gam version simple
6.72.07
6.72.08
```
In Linux/MacOS you can do:
```
@ -82,7 +82,7 @@ echo $VER
Print the current version of Gam and address of this Wiki
```
gam help
GAM 6.72.07 - https://github.com/taers232c/GAMADV-XTD3
GAM 6.72.08 - https://github.com/taers232c/GAMADV-XTD3
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.12.2 64-bit final
MacOS Sonoma 14.2.1 x86_64

View File

@ -7391,10 +7391,12 @@ gam <UserTypeEntity> info note <NotesNameEntity>
gam <UserTypeEntity> show notes
[fields <NotesFieldList>] [filter <String>]
[role owner|writer]
[countsonly]
[compact|formatjson]
gam <UserTypeEntity> print notes [todrive <ToDriveAttribute>*]
[fields <NotesFieldList>] [filter <String>]
[role owner|writer]
[countsonly]
[formatjson [quotechar <Character>]]
gam <UserTypeEntity> get noteattachments <NotesNameEntity>

View File

@ -2,6 +2,11 @@
Merged GAM-Team version
6.72.08
Added option `countsonly` to `gam <UserTypeEntity> print|show notes` that displays
the number of notes a user owns and the number of notes of user can edit.
6.72.07
Updated commands that send emails to not downshift `'First Last<firstlast@domain.com>'` to `'first last<firstlast@domain.com>'`.

View File

@ -70998,7 +70998,7 @@ def _assignNoteOwner(note, user):
note['ownedByMe'] = noteOwner == user
break
def _checkNoteUserkRole(note, user, role):
def _checkNoteUserRole(note, user, role):
for permission in note['permissions']:
if permission['role'] == role and permission.get('user', {}).get('email', '').lower() == user:
return True
@ -71295,20 +71295,27 @@ NOTES_ROLE_CHOICE_MAP = {
'writer': 'WRITER',
}
NOTES_COUNTS_MAP = {
'OWNER': 'noteOwner',
'WRITER': 'noteWriter',
}
# gam <UserTypeEntity> show notes
# [fields <NotesFieldList>] [filter <String>]
# [role owner|writer]
# [countsonly]
# [compact] [formatjson]
# gam <UserTypeEntity> print notes [todrive <ToDriveAttribute>*]
# [fields <NotesFieldList>] [filter <String>]
# [role owner|writer]
# [countsonly]
# [formatjson [quotechar <Character>]]
def printShowNotes(users):
csvPF = CSVPrintFile(['User', 'name', 'title', 'owner', 'ownedByMe']) if Act.csvFormat() else None
if csvPF:
csvPF.SetNoEscapeChar(True)
FJQC = FormatJSONQuoteChar(csvPF)
compact = False
compact = countsOnly = False
fieldsList = []
noteFilter = None
role = None
@ -71325,6 +71332,8 @@ def printShowNotes(users):
role = getChoice(NOTES_ROLE_CHOICE_MAP, mapChoice=True)
elif not csvPF and myarg == 'compact':
compact = True
elif myarg == 'countsonly':
countsOnly = True
else:
FJQC.GetFormatJSONQuoteChar(myarg, True)
if FJQC.formatJSON:
@ -71333,10 +71342,16 @@ def printShowNotes(users):
showPermissions = False
fieldsList.append('permissions')
if csvPF:
if not FJQC.formatJSON:
csvPF.RemoveTitles(['owner', 'ownedByMe'])
else:
csvPF.RemoveJSONTitles(['owner', 'ownedByMe'])
if not countsOnly:
if not FJQC.formatJSON:
csvPF.RemoveTitles(['owner', 'ownedByMe'])
else:
csvPF.RemoveJSONTitles(['owner', 'ownedByMe'])
if countsOnly and csvPF:
if not FJQC.formatJSON:
csvPF.SetTitles(['User', 'noteOwner', 'noteWriter'])
else:
csvPF.SetJSONTitles(['User', 'JSON'])
fields = getItemFieldsFromFieldsList('notes', fieldsList, returnItemIfNoneList=False)
i, count, users = getEntityArgument(users)
for user in users:
@ -71354,6 +71369,27 @@ def printShowNotes(users):
pageMessage=pageMessage,
throwReasons=GAPI.KEEP_THROW_REASONS,
filter=noteFilter, fields=fields)
if countsOnly:
noteCounts = {'User': user, 'noteOwner': 0, 'noteWriter': 0}
for note in notes:
for permission in note['permissions']:
if permission.get('user', {}).get('email', '').lower() == user:
noteCounts[NOTES_COUNTS_MAP[permission['role']]] += 1
break
if not csvPF:
if not FJQC.formatJSON:
printEntityKVList([Ent.USER, user], ['noteOwner', noteCounts['noteOwner'], 'noteWriter', noteCounts['noteWriter']], i, count)
else:
printLine(json.dumps(cleanJSON(noteCounts), ensure_ascii=False, sort_keys=True))
else:
row = {'User': user, 'noteOwner': noteCounts['noteOwner'], 'noteWriter': noteCounts['noteWriter']}
if not FJQC.formatJSON:
csvPF.WriteRowTitles(row)
elif csvPF.CheckRowTitles(row):
row = {'User': noteCounts.pop('User')}
row['JSON'] = json.dumps(cleanJSON(noteCounts), ensure_ascii=False, sort_keys=True)
csvPF.WriteRowNoFilter(row)
continue
if not csvPF:
jcount = len(notes)
if not FJQC.formatJSON:
@ -71364,7 +71400,7 @@ def printShowNotes(users):
j += 1
if showPermissions:
_assignNoteOwner(note, user)
if role is None or _checkNoteUserkRole(note, user, role):
if role is None or _checkNoteUserRole(note, user, role):
if not showPermissions:
note.pop('permissions', None)
_showNote(note, j, jcount, FJQC, compact)
@ -71373,7 +71409,7 @@ def printShowNotes(users):
for note in notes:
if showPermissions:
_assignNoteOwner(note, user)
if role is None or _checkNoteUserkRole(note, user, role):
if role is None or _checkNoteUserRole(note, user, role):
if not showPermissions:
note.pop('permissions', None)
row = flattenJSON(note, flattened={'User': user}, timeObjects=NOTES_TIME_OBJECTS)