Skip to content

Commit 7609638

Browse files
committed
Added option parentpathonly [<Boolean>]
1 parent b0b572a commit 7609638

3 files changed

Lines changed: 45 additions & 27 deletions

File tree

src/GamCommands.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7032,7 +7032,7 @@ gam <UserTypeEntity> untrash drivefile <DriveFileEntity> [shortcutandtarget [<Bo
70327032

70337033
gam <UserTypeEntity> info drivefile <DriveFileEntity>
70347034
[returnidonly]
7035-
[filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
7035+
[filepath|fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
70367036
[allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
70377037
[includepermissionsforview published]
70387038
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
@@ -7513,7 +7513,7 @@ gam <UserTypeEntity> collect orphans
75137513

75147514
gam <UserTypeEntity> show fileinfo <DriveFileEntity>
75157515
[returnidonly]
7516-
[filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
7516+
[filepath|fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
75177517
[allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
75187518
[includepermissionsforview published]
75197519
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
@@ -7527,12 +7527,12 @@ gam <UserTypeEntity> show filepath <DriveFileEntity>
75277527
[returnpathonly]
75287528
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
75297529
[stripcrsfromname]
7530-
[fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
7530+
[fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
75317531
[followshortcuts [<Boolean>]]
75327532
gam <UserTypeEntity> print filepath <DriveFileEntity> [todrive <ToDriveAttribute>*]
75337533
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
75347534
[stripcrsfromname] [oneitemperrow]
7535-
[fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
7535+
[fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
75367536
[followshortcuts [<Boolean>]]
75377537

75387538
gam <UserTypeEntity> print filecounts [todrive <ToDriveAttribute>*]
@@ -7635,7 +7635,7 @@ gam <UserTypeEntity> print filelist [todrive <ToDriveAttribute>*]
76357635
[countsonly [summary none|only|plus] [summaryuser <String>]
76367636
[showsource] [showsize] [showsizeunits] [showmimetypesize]]
76377637
[countsrowfilter]
7638-
[filepath|fullpath [folderpathonly [<Boolean>]] [pathdelimiter <Character>] [addpathstojson] [showdepth]] [buildtree]
7638+
[filepath|fullpath [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>] [addpathstojson] [showdepth]] [buildtree]
76397639
[allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
76407640
[showdrivename] [showshareddrivepermissions]
76417641
[(showlabels details|ids)|(includelabels <ClassificationLabelIDList>)]

src/GamUpdate.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
7.43.03
2+
3+
Added option `parentpathonly [<Boolean>]` to the following commands that causes GAM
4+
to display only the parent folder names when displaying the path to a file.
5+
```
6+
gam <UserTypeEntity> info drivefile ... filepath|fullpath
7+
gam <UserTypeEntity> show fileinfo ... filepath|fullpath
8+
gam <UserTypeEntity> print|show filepath
9+
gam <UserTypeEntity> print filelist ... filepath|fullpath
10+
```
11+
112
7.43.02
213

314
Added option `maxactivities <Number>` to `gam <UserTypeEntity> print driveactivity` to limit

src/gam/__init__.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
28-
__version__ = '7.43.02'
28+
__version__ = '7.43.03'
2929
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
3030

3131
# pylint: disable=wrong-import-position
@@ -57541,7 +57541,7 @@ def initFilePathInfo(delimiter):
5754157541
return {'ids': {}, 'allPaths': {}, 'localPaths': None, 'delimiter': delimiter}
5754257542

5754357543
def getFilePaths(drive, fileTree, initialResult, filePathInfo, addParentsToTree=False,
57544-
fullpath=False, showDepth=False, folderPathOnly=False):
57544+
fullpath=False, showDepth=False, folderPathOnly=False, parentPathOnly=False):
5754557545
def _getParentName(result):
5754657546
if (result['mimeType'] == MIMETYPE_GA_FOLDER) and result.get('driveId') and (result['name'] == TEAM_DRIVE):
5754757547
parentName = _getSharedDriveNameFromId(drive, result['driveId'])
@@ -57595,8 +57595,9 @@ def _makeFilePaths(localPaths, fplist, filePaths, name, maxDepth):
5759557595
if depth > maxDepth:
5759657596
maxDepth = depth-1
5759757597
fp.reverse()
57598-
if initialMimeType == MIMETYPE_GA_FOLDER or not folderPathOnly:
57599-
fp.append(name)
57598+
if not parentPathOnly:
57599+
if initialMimeType == MIMETYPE_GA_FOLDER or not folderPathOnly:
57600+
fp.append(name)
5760057601
filePaths.append(filePathInfo['delimiter'].join(fp))
5760157602
else:
5760257603
maxDepth = _makeFilePaths(v, fplist, filePaths, name, maxDepth)
@@ -58112,7 +58113,7 @@ def _formatFileDriveLabels(showLabels, labels, result, printMode, delimiter):
5811258113

5811358114
# gam <UserTypeEntity> info drivefile <DriveFileEntity>
5811458115
# [returnidonly]
58115-
# [filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
58116+
# [filepath|fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
5811658117
# [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)] [formatjson]
5811758118
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
5811858119
# [showdrivename] [showshareddrivepermissions]
@@ -58122,7 +58123,7 @@ def _formatFileDriveLabels(showLabels, labels, result, printMode, delimiter):
5812258123
# [stripcrsfromname] [formatjson]
5812358124
# gam <UserTypeEntity> show fileinfo <DriveFileEntity>
5812458125
# [returnidonly]
58125-
# [filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
58126+
# [filepath|fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
5812658127
# [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)] [formatjson]
5812758128
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
5812858129
# [showdrivename] [showshareddrivepermissions]
@@ -58140,7 +58141,7 @@ def _setSelectionFields():
5814058141
if followShortcuts:
5814158142
_setSkipObjects(skipObjects, ['mimeType', 'shortcutDetails'], DFF.fieldsList)
5814258143

58143-
getPermissionsForSharedDrives = filepath = fullpath = folderPathOnly = followShortcuts = \
58144+
getPermissionsForSharedDrives = filepath = fullpath = folderPathOnly = parentPathOnly = followShortcuts = \
5814458145
returnIdOnly = showParentsIdsAsList = showNoParents = stripCRsFromName = False
5814558146
pathDelimiter = '/'
5814658147
showLabels = None
@@ -58158,6 +58159,8 @@ def _setSelectionFields():
5815858159
filepath = fullpath = True
5815958160
elif myarg == 'folderpathonly':
5816058161
folderPathOnly = getBoolean()
58162+
elif myarg == 'parentpathonly':
58163+
parentPathOnly = getBoolean()
5816158164
elif myarg == 'pathdelimiter':
5816258165
pathDelimiter = getCharacter()
5816358166
elif myarg == 'showparentsidsaslist':
@@ -58274,7 +58277,7 @@ def _setSelectionFields():
5827458277
extendFileTreeParents(drive, fileTree, pathFields)
5827558278
if not FJQC.formatJSON:
5827658279
_, paths, _ = getFilePaths(drive, fileTree, result, filePathInfo, addParentsToTree=True,
58277-
fullpath=fullpath, folderPathOnly=folderPathOnly)
58280+
fullpath=fullpath, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5827858281
kcount = len(paths)
5827958282
printKeyValueList(['paths', kcount])
5828058283
Ind.Increment()
@@ -58283,7 +58286,7 @@ def _setSelectionFields():
5828358286
Ind.Decrement()
5828458287
else:
5828558288
addFilePathsToInfo(drive, fileTree, result, filePathInfo,
58286-
addParentsToTree=True, folderPathOnly=folderPathOnly)
58289+
addParentsToTree=True, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5828758290
if fullpath:
5828858291
# Save simple parents list as mappings turn it into a list of dicts
5828958292
fpparents = result['parents'][:]
@@ -58960,9 +58963,9 @@ def buildFileTree(feed, drive):
5896058963
return fileTree
5896158964

5896258965
def addFilePathsToRow(drive, fileTree, fileEntryInfo, filePathInfo, csvPF, row,
58963-
fullpath=False, showDepth=False, folderPathOnly=False):
58966+
fullpath=False, showDepth=False, folderPathOnly=False, parentPathOnly=False):
5896458967
_, paths, maxDepth = getFilePaths(drive, fileTree, fileEntryInfo, filePathInfo,
58965-
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly)
58968+
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5896658969
kcount = len(paths)
5896758970
if showDepth:
5896858971
row['depth'] = maxDepth
@@ -58977,9 +58980,9 @@ def addFilePathsToRow(drive, fileTree, fileEntryInfo, filePathInfo, csvPF, row,
5897758980
row[key] = path
5897858981
k += 1
5897958982

58980-
def addFilePathsToInfo(drive, fileTree, fileEntryInfo, filePathInfo, addParentsToTree=False, folderPathOnly=False):
58983+
def addFilePathsToInfo(drive, fileTree, fileEntryInfo, filePathInfo, addParentsToTree=False, folderPathOnly=False, parentPathOnly=False):
5898158984
_, paths, _ = getFilePaths(drive, fileTree, fileEntryInfo, filePathInfo, addParentsToTree=addParentsToTree,
58982-
showDepth=False, folderPathOnly=folderPathOnly)
58985+
showDepth=False, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5898358986
fileEntryInfo['paths'] = []
5898458987
for path in sorted(paths):
5898558988
if GC.Values[GC.CSV_OUTPUT_CONVERT_CR_NL] and (path.find('\n') >= 0 or path.find('\r') >= 0):
@@ -59572,7 +59575,7 @@ def _getGettingEntity(user, fileIdEntity):
5957259575
# [countsonly [summary none|only|plus] [summaryuser <String>]
5957359576
# [showsource] [showsize] [showsizeunits] [showmimetypesize]]
5957459577
# [countsrowfilter]
59575-
# [filepath|fullpath [folderpathonly [<Boolean>]] [pathdelimiter <Character>] [addpathstojson] [showdepth]] [buildtree]
59578+
# [filepath|fullpath [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>] [addpathstojson] [showdepth]] [buildtree]
5957659579
# [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
5957759580
# [showdrivename] [showshareddrivepermissions]
5957859581
# (showlabels details|ids)|(includelabels <DriveLabelIDList>)]
@@ -59676,9 +59679,9 @@ def _printFileInfo(drive, user, f_file, cleanFileName):
5967659679
if filepath:
5967759680
if not FJQC.formatJSON or not addPathsToJSON:
5967859681
addFilePathsToRow(drive, fileTree, fileInfo, filePathInfo, csvPF, row,
59679-
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly)
59682+
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5968059683
else:
59681-
addFilePathsToInfo(drive, fileTree, fileInfo, filePathInfo, folderPathOnly=folderPathOnly)
59684+
addFilePathsToInfo(drive, fileTree, fileInfo, filePathInfo, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
5968259685
_mapDriveInfo(fileInfo, DFF.parentsSubFields, showParentsIdsAsList)
5968359686
if showParentsIdsAsList and 'parentsIds' in fileInfo:
5968459687
fileInfo['parents'] = len(fileInfo['parentsIds'])
@@ -59812,7 +59815,7 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5981259815
csvPF = CSVPrintFile('Owner', indexedTitles=DRIVE_INDEXED_TITLES)
5981359816
csvPFco = None
5981459817
FJQC = FormatJSONQuoteChar(csvPF)
59815-
addPathsToJSON = continueOnInvalidQuery = countsRowFilter = buildTree = countsOnly = filepath = fullpath = folderPathOnly = \
59818+
addPathsToJSON = continueOnInvalidQuery = countsRowFilter = buildTree = countsOnly = filepath = fullpath = folderPathOnly = parentPathOnly = \
5981659819
getPermissionDetailsForMyDrive = getPermissionsForSharedDrives = mimeTypeInQuery = noRecursion = oneItemPerRow = stripCRsFromName = \
5981759820
showParentsIdsAsList = showDepth = showParent = showSize = showSizeUnits = showMimeTypeSize = showSource = False
5981859821
sizeField = 'quotaBytesUsed'
@@ -59870,6 +59873,8 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5987059873
fullpath = myarg == 'fullpath'
5987159874
elif myarg == 'folderpathonly':
5987259875
folderPathOnly = getBoolean()
59876+
elif myarg == 'parentpathonly':
59877+
parentPathOnly = getBoolean()
5987359878
elif myarg == 'pathdelimiter':
5987459879
pathDelimiter = getCharacter()
5987559880
elif myarg == 'addpathstojson':
@@ -60168,7 +60173,7 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
6016860173
break
6016960174
if fullpath:
6017060175
getFilePaths(drive, fileTree, fileEntryInfo, filePathInfo, addParentsToTree=True,
60171-
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly)
60176+
fullpath=fullpath, showDepth=showDepth, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
6017260177
if ((showParent and (fileEntryInfo['id'] not in {ORPHANS, SHARED_WITHME, SHARED_DRIVES})) or
6017360178
fileEntryInfo['mimeType'] != MIMETYPE_GA_FOLDER or noRecursion):
6017460179
if fileId not in filesPrinted:
@@ -60463,18 +60468,18 @@ def _printComment(comment, commentId, replyId, baserow):
6046360468
# gam <UserTypeEntity> print filepaths <DriveFileEntity> [todrive <ToDriveAttribute>*]
6046460469
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
6046560470
# [stripcrsfromname] [oneitemperrow]
60466-
# [fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
60471+
# [fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
6046760472
# [followshortcuts [<Boolean>]]
6046860473
# gam <UserTypeEntity> show filepaths <DriveFileEntity>
6046960474
# [returnpathonly]
6047060475
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
6047160476
# [stripcrsfromname]
60472-
# [fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
60477+
# [fullpath] [folderpathonly|parentpathonly [<Boolean>]] [pathdelimiter <Character>]
6047360478
# [followshortcuts [<Boolean>]]
6047460479
def printShowFilePaths(users):
6047560480
csvPF = CSVPrintFile(['Owner', 'id', 'name', 'paths'], 'sortall', ['paths']) if Act.csvFormat() else None
6047660481
fileIdEntity = getDriveFileEntity()
60477-
fullpath = folderPathOnly = followShortcuts = oneItemPerRow = returnPathOnly = stripCRsFromName = False
60482+
fullpath = folderPathOnly = parentPathOnly = followShortcuts = oneItemPerRow = returnPathOnly = stripCRsFromName = False
6047860483
pathDelimiter = '/'
6047960484
OBY = OrderBy(DRIVEFILE_ORDERBY_CHOICE_MAP)
6048060485
while Cmd.ArgumentsRemaining():
@@ -60485,6 +60490,8 @@ def printShowFilePaths(users):
6048560490
fullpath = True
6048660491
elif myarg == 'folderpathonly':
6048760492
folderPathOnly = getBoolean()
60493+
elif myarg == 'parentpathonly':
60494+
parentPathOnly = getBoolean()
6048860495
elif myarg == 'pathdelimiter':
6048960496
pathDelimiter = getCharacter()
6049060497
elif myarg == 'stripcrsfromname':
@@ -60556,7 +60563,7 @@ def printShowFilePaths(users):
6055660563
extendFileTree(fileTree, [result], None, False)
6055760564
extendFileTreeParents(drive, fileTree, pathFields)
6055860565
entityType, paths, _ = getFilePaths(drive, fileTree, result, filePathInfo, addParentsToTree=True,
60559-
fullpath=fullpath, folderPathOnly=folderPathOnly)
60566+
fullpath=fullpath, folderPathOnly=folderPathOnly, parentPathOnly=parentPathOnly)
6056060567
if returnPathOnly:
6056160568
for path in paths:
6056260569
writeStdout(f'{path}\n')

0 commit comments

Comments
 (0)