From 5c27695613be7366ae8b86d182c5e62b9936f314 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Thu, 27 Oct 2016 10:08:49 -0700 Subject: [PATCH] Handle newlines in CrOS notes field; fix print tokens to show clientId (#308) * Handle newlines in CrOS notes field * Fix gam print tokens to show clientId * Generalize print.show tokens --- src/gam.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gam.py b/src/gam.py index 755ed788..29c9f4dd 100755 --- a/src/gam.py +++ b/src/gam.py @@ -7198,7 +7198,7 @@ def doUpdateCros(): body[u'annotatedLocation'] = sys.argv[i + 1] i += 2 elif sys.argv[i].lower() == u'notes': - body[u'notes'] = sys.argv[i + 1] + body[u'notes'] = sys.argv[i + 1].replace(u'\\n', u'\n') i += 2 elif sys.argv[i].lower() == u'action': update_device = False @@ -7827,6 +7827,8 @@ def doGetCrosInfo(): cros = callGAPI(cd.chromeosdevices(), u'get', customerId=GC_Values[GC_CUSTOMER_ID], deviceId=deviceId, projection=projection, fields=fields) print u'CrOS Device: {0}'.format(deviceId) + if u'notes' in cros: + cros[u'notes'] = cros[u'notes'].replace(u'\n', u'\\n') for up in CROS_SCALAR_PROPERTY_PRINT_ORDER: if up in cros: print u' {0}: {1}'.format(up, cros[up]) @@ -8195,8 +8197,9 @@ def doDelTokens(users): def printShowTokens(i, entityType, users, csvFormat): def _showToken(token): print u' Client ID: %s' % token[u'clientId'] - for item in [u'displayText', u'anonymous', u'nativeApp', u'userKey']: - print convertUTF8(u' %s: %s' % (item, token.get(item, u''))) + for item in token: + if item not in [u'clientId', u'scopes']: + print convertUTF8(u' %s: %s' % (item, token.get(item, u''))) item = u'scopes' print u' %s:' % item for it in token.get(item, []): @@ -8253,8 +8256,9 @@ def printShowTokens(i, entityType, users, csvFormat): continue for token in results: row = {u'user': user, u'scopes': u' '.join(token.get(u'scopes', []))} - for item in [u'displayText', u'anonymous', u'nativeApp', u'userKey']: - row[item] = token.get(item, u'') + for item in token: + if item not in [u'scopes']: + row[item] = token.get(item, u'') csvRows.append(row) except googleapiclient.errors.HttpError: pass @@ -9273,6 +9277,8 @@ def doPrintCrosDevices(): if all_cros: if (not noLists) and (not selectActiveTimeRanges) and (not selectRecentUsers): for cros in all_cros: + if u'notes' in cros: + cros[u'notes'] = cros[u'notes'].replace(u'\n', u'\\n') addRowTitlesToCSVfile(flatten_json(cros, listLimit=listLimit), csvRows, titles) else: if not noLists: @@ -9283,6 +9289,8 @@ def doPrintCrosDevices(): for attrib in [u'recentUsers.email', u'recentUsers.type']: titles.append(attrib) for cros in all_cros: + if u'notes' in cros: + cros[u'notes'] = cros[u'notes'].replace(u'\n', u'\\n') row = {} for attrib in cros: if attrib in [u'kind', u'etag', u'recentUsers', u'activeTimeRanges']: