mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 12:51:36 +00:00
Add [listlimit <Number>] to gam print cros
This limits the number of entries shown for activeTimeRanges and recentUsers
This commit is contained in:
21
src/gam.py
21
src/gam.py
@@ -7390,21 +7390,23 @@ def output_csv(csv_list, titles, list_type, todrive):
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open(file_url)
|
webbrowser.open(file_url)
|
||||||
|
|
||||||
def flatten_json(structure, key="", path="", flattened=None):
|
def flatten_json(structure, key="", path="", flattened=None, listLimit=None):
|
||||||
if flattened == None:
|
if flattened == None:
|
||||||
flattened = {}
|
flattened = {}
|
||||||
if type(structure) not in(dict, list):
|
if not isinstance(structure, (dict, list)):
|
||||||
flattened[((path + ".") if path else "") + key] = structure
|
flattened[((path + ".") if path else "") + key] = structure
|
||||||
elif isinstance(structure, list):
|
elif isinstance(structure, list):
|
||||||
for i, item in enumerate(structure):
|
for i, item in enumerate(structure):
|
||||||
flatten_json(item, "%d" % i, ".".join(filter(None, [path, key])), flattened)
|
if listLimit and (i >= listLimit):
|
||||||
|
break
|
||||||
|
flatten_json(item, "%d" % i, ".".join(filter(None, [path, key])), flattened=flattened, listLimit=listLimit)
|
||||||
else:
|
else:
|
||||||
for new_key, value in structure.items():
|
for new_key, value in structure.items():
|
||||||
if new_key in [u'kind', u'etag']:
|
if new_key in [u'kind', u'etag']:
|
||||||
continue
|
continue
|
||||||
if value == u'1970-01-01T00:00:00.000Z':
|
if value == u'1970-01-01T00:00:00.000Z':
|
||||||
value = u'Never'
|
value = u'Never'
|
||||||
flatten_json(value, new_key, ".".join(filter(None, [path, key])), flattened)
|
flatten_json(value, new_key, ".".join(filter(None, [path, key])), flattened=flattened, listLimit=listLimit)
|
||||||
return flattened
|
return flattened
|
||||||
|
|
||||||
def doPrintUsers():
|
def doPrintUsers():
|
||||||
@@ -8010,7 +8012,7 @@ def doPrintCrosDevices():
|
|||||||
todrive = False
|
todrive = False
|
||||||
query = projection = orderBy = sortOrder = None
|
query = projection = orderBy = sortOrder = None
|
||||||
noLists = False
|
noLists = False
|
||||||
selectAttrib = None
|
listLimit = selectAttrib = None
|
||||||
i = 3
|
i = 3
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
my_arg = sys.argv[i].lower().replace(u'_', u'')
|
my_arg = sys.argv[i].lower().replace(u'_', u'')
|
||||||
@@ -8032,6 +8034,9 @@ def doPrintCrosDevices():
|
|||||||
selectAttrib = u'activeTimeRanges'
|
selectAttrib = u'activeTimeRanges'
|
||||||
noLists = False
|
noLists = False
|
||||||
i += 1
|
i += 1
|
||||||
|
elif my_arg == u'listlimit':
|
||||||
|
listLimit = int(sys.argv[i+1])
|
||||||
|
i += 2
|
||||||
elif my_arg == u'orderby':
|
elif my_arg == u'orderby':
|
||||||
orderBy = sys.argv[i+1].lower().replace(u'_', u'')
|
orderBy = sys.argv[i+1].lower().replace(u'_', u'')
|
||||||
allowed_values = [u'location', u'user', u'lastsync', u'notes', u'serialnumber', u'status', u'supportenddate']
|
allowed_values = [u'location', u'user', u'lastsync', u'notes', u'serialnumber', u'status', u'supportenddate']
|
||||||
@@ -8068,7 +8073,7 @@ def doPrintCrosDevices():
|
|||||||
if all_cros:
|
if all_cros:
|
||||||
if (not noLists) and (not selectAttrib):
|
if (not noLists) and (not selectAttrib):
|
||||||
for cros in all_cros:
|
for cros in all_cros:
|
||||||
cros_attributes.append(flatten_json(cros))
|
cros_attributes.append(flatten_json(cros, listLimit=listLimit))
|
||||||
for item in cros_attributes[-1]:
|
for item in cros_attributes[-1]:
|
||||||
if item not in cros_attributes[0]:
|
if item not in cros_attributes[0]:
|
||||||
cros_attributes[0][item] = item
|
cros_attributes[0][item] = item
|
||||||
@@ -8094,7 +8099,9 @@ def doPrintCrosDevices():
|
|||||||
cros_attributes[0][xattrib] = xattrib
|
cros_attributes[0][xattrib] = xattrib
|
||||||
titles.append(xattrib)
|
titles.append(xattrib)
|
||||||
attribMap[attrib] = xattrib
|
attribMap[attrib] = xattrib
|
||||||
for item in cros[selectAttrib]:
|
for i, item in enumerate(cros[selectAttrib]):
|
||||||
|
if listLimit and(i >= listLimit):
|
||||||
|
break
|
||||||
new_row = row.copy()
|
new_row = row.copy()
|
||||||
for attrib in item:
|
for attrib in item:
|
||||||
if isinstance(item[attrib], (bool, int)):
|
if isinstance(item[attrib], (bool, int)):
|
||||||
|
|||||||
Reference in New Issue
Block a user