mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-25 16:41:35 +00:00
New buildings cleanup (#650)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
This document describes the GAM command line syntax in modified BNF, see https://en.wikipedia.org/wiki/Backus-Naur_Form
|
||||
This document describes the GAM command line syntax in modified BNF, see https://en.wikipedia.org/wiki/Backus-Naur_Form
|
||||
Skip the History section and start reading at Introduction.
|
||||
|
||||
Items on the command line are space separated, when an actual space character is required, it will be indicated by <Space>.
|
||||
@@ -116,6 +116,7 @@ Named items
|
||||
<AccessToken> ::= <String>
|
||||
<ACLScope> ::= [user:]<EmailAddress>|group:<EmailAddress>|domain[:<DomainName>]|default
|
||||
<ASPID> ::= <String>
|
||||
<BuildingID> ::= <String>|id:<String>
|
||||
<CalendarACLRole> ::= editor|freebusy|freebusyreader|owner|reader|writer
|
||||
<CalendarColorIndex> ::== <Number in range 1-24>
|
||||
<CalendarItem> ::= <EmailAddress>|<String>
|
||||
@@ -504,6 +505,14 @@ Specify a collection of Users by directly specifying them or by specifiying item
|
||||
(query <QueryUser>)
|
||||
|
||||
Item attributes
|
||||
<BuildingAttributes> ::=
|
||||
(buildingid <String>)|
|
||||
(description <String>)|
|
||||
(floors <FloorNameList>)|
|
||||
(latitude <Float>)|
|
||||
(longitude <Float>)|
|
||||
(name <String>)
|
||||
|
||||
<CalendarAttributes> ::=
|
||||
(selected <Boolean>)|(hidden <Boolean>)|(summary <String>)|(colorindex|colorid <CalendarColorIndex>)|(backgroundcolor <ColorHex>)|(foregroundcolor <ColorHex>)|
|
||||
(reminder clear|(email|sms|pop <Number>))|
|
||||
@@ -588,6 +597,18 @@ Item attributes
|
||||
(quotaenabled <Boolean>)|(status <Number>)|(type <String>)|(uuid <String>)|
|
||||
(setupurl <URL>)|(supporturl <URL>)|(updateurl <URL>)
|
||||
|
||||
<ResourceAttributes> ::=
|
||||
(buildingid <BuildingID>)|
|
||||
(capacity <Number>)|
|
||||
(category other|room|conference_room)|
|
||||
(description <String>)|
|
||||
(features <FeatureNameList>)|
|
||||
(floor <FloorName>)|
|
||||
(floorsection <String>)|
|
||||
(name <String>)|
|
||||
(type <String>)|
|
||||
(uservisibledescription <String>)
|
||||
|
||||
<SchemaFieldDefinition> ::=
|
||||
field <FieldName> (type bool|date|double|email|int64|phone|string) [multivalued|multivalue] [indexed] [restricted] [range <Number> <Number>] endfield
|
||||
|
||||
@@ -607,7 +628,7 @@ Item attributes
|
||||
(im clear|(type work|home|other|(custom <String>) protocol aim|gtalk|icq|jabber|msn|net_meeting|qq|skype|yahoo|(custom_protocol <String>) <String> [notprimary|primary]))|
|
||||
(ipwhitelisted <Boolean>)|
|
||||
(lastname|familyname <String>)|
|
||||
(location clear|(type default|desk|<String> area <String> [building|buildingid <String>] [floor|floorname <String>] [section|floorsection <String>] [desk|deskcode <String>] endlocation))|
|
||||
(location clear|(type default|desk|<String> area <String> [building|buildingid <BuildingID>] [floor|floorname <FloorName>] [section|floorsection <String>] [desk|deskcode <String>] endlocation))|
|
||||
(note clear|([text_plain|text_html] <String>|(file <FileName> [charset <Charset>])))|
|
||||
(organization clear|([type domain_only|school|unknown|work] [customtype <String>] [name <String>] [title <String>] [department <String>] [symbol <String>]
|
||||
[costcenter <String>] [location <String>] [description <String>] [domain <String>] notprimary|primary))|
|
||||
@@ -817,6 +838,16 @@ gam update notification|notifications [(id all)|(id <NotificationID>)*] unread|r
|
||||
gam delete notification|notifications [(id all)|(id <NotificationID>)*]
|
||||
gam info notification|notifications [unreadonly]
|
||||
|
||||
gam create building <BuildingID> <BuildingAttributes>*
|
||||
gam update building <BuildIngID> <BuildingAttributes>*
|
||||
gam delete building <BuildingID>
|
||||
gam info building <BuildingID>
|
||||
gam print buildings [todrive]
|
||||
|
||||
gam create feature <Name>
|
||||
gam update feature <Name> name <Name>
|
||||
gam print features [todrive]
|
||||
|
||||
gam create resource <ResourceID> <Name> [description <String>] [type <String>]
|
||||
gam update resource <ResourceID> [name <Name>] [description <String>] [type <String>]
|
||||
gam delete resource <ResourceID>
|
||||
|
||||
45
src/gam.py
45
src/gam.py
@@ -755,7 +755,7 @@ def callGAPIpages(service, function, items,
|
||||
total_items = 0
|
||||
while True:
|
||||
this_page = callGAPI(service, function, soft_errors=soft_errors,
|
||||
throw_reasons=throw_reasons, retry_reasons=retry_reasons, **kwargs)
|
||||
throw_reasons=throw_reasons, retry_reasons=retry_reasons, **kwargs)
|
||||
if this_page:
|
||||
if items in this_page:
|
||||
page_items = len(this_page[items])
|
||||
@@ -6902,7 +6902,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
||||
location[u'area'] = sys.argv[i+1]
|
||||
i += 2
|
||||
elif myopt in [u'building', u'buildingid']:
|
||||
location[u'buildingId'] = sys.argv[i+1]
|
||||
location[u'buildingId'] = _getBuildingByNameOrId(cd, sys.argv[i+1])
|
||||
i += 2
|
||||
elif myopt in [u'desk', u'deskcode']:
|
||||
location[u'deskCode'] = sys.argv[i+1]
|
||||
@@ -7987,7 +7987,7 @@ def _getBuildingByNameOrId(cd, which_building):
|
||||
return which_building[3:]
|
||||
fields = u'nextPageToken,buildings(buildingId,buildingName)'
|
||||
buildings = callGAPIpages(cd.resources().buildings(), u'list',
|
||||
u'buildings', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
u'buildings', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
ci_matches = []
|
||||
for building in buildings:
|
||||
# name is case sensitive. If case matches return immediately
|
||||
@@ -8011,14 +8011,11 @@ def _getBuildingByNameOrId(cd, which_building):
|
||||
sys.exit(3)
|
||||
|
||||
def _getBuildingNameById(cd, buildingId):
|
||||
global all_buildings
|
||||
try:
|
||||
all_buildings
|
||||
except NameError:
|
||||
if not GM_Globals[GM_MAP_BUILDING_ID_TO_NAME]:
|
||||
fields = u'nextPageToken,buildings(buildingId,buildingName)'
|
||||
all_buildings = callGAPIpages(cd.resources().buildings(), u'list',
|
||||
u'buildings', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
for building in all_buildings:
|
||||
GM_Globals[GM_MAP_BUILDING_ID_TO_NAME] = callGAPIpages(cd.resources().buildings(), u'list', u'buildings',
|
||||
customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
for building in GM_Globals[GM_MAP_BUILDING_ID_TO_NAME]:
|
||||
if buildingId == building[u'buildingId']:
|
||||
return building[u'buildingName']
|
||||
print u'ERROR: No such building %s' % buildingId
|
||||
@@ -8036,12 +8033,11 @@ def doGetBuildingInfo():
|
||||
cd = buildGAPIObject(u'directory')
|
||||
buildingId = _getBuildingByNameOrId(cd, sys.argv[3])
|
||||
building = callGAPI(cd.resources().buildings(), u'get',
|
||||
customer=GC_Values[GC_CUSTOMER_ID], buildingId=buildingId)
|
||||
customer=GC_Values[GC_CUSTOMER_ID], buildingId=buildingId)
|
||||
if u'floorNames' in building:
|
||||
building[u'floorNames'] = u' '.join(building[u'floorNames'])
|
||||
building[u'floorNames'] = u','.join(building[u'floorNames'])
|
||||
if u'buildingName' in building:
|
||||
sys.stdout.write(building[u'buildingName'])
|
||||
del(building[u'buildingName'])
|
||||
sys.stdout.write(building.pop(u'buildingName'))
|
||||
print_json(None, building)
|
||||
|
||||
def doDeleteBuilding():
|
||||
@@ -8086,7 +8082,10 @@ def _getResourceCalendarAttributes(cd, args, body={}):
|
||||
i = 0
|
||||
while i < len(args):
|
||||
myarg = args[i].lower().replace(u'_', u'')
|
||||
if myarg == u'description':
|
||||
if myarg == u'name':
|
||||
body[u'resourceName'] = args[i+1]
|
||||
i += 2
|
||||
elif myarg == u'description':
|
||||
body[u'resourceDescription'] = args[i+1].replace(u'\\n', u'\n')
|
||||
i += 2
|
||||
elif myarg == u'type':
|
||||
@@ -8117,7 +8116,7 @@ def _getResourceCalendarAttributes(cd, args, body={}):
|
||||
i += 2
|
||||
elif myarg in [u'uservisibledescription', u'userdescription']:
|
||||
body[u'userVisibleDescription'] = args[i+1]
|
||||
i += 2
|
||||
i += 2
|
||||
else:
|
||||
print u'ERROR: %s is not a valid argument for "gam create|update resource"' % args[i]
|
||||
sys.exit(2)
|
||||
@@ -9197,11 +9196,7 @@ def doGetResourceCalendarInfo():
|
||||
resource = callGAPI(cd.resources().calendars(), u'get',
|
||||
customer=GC_Values[GC_CUSTOMER_ID], calendarResourceId=resId)
|
||||
if u'featureInstances' in resource:
|
||||
features = []
|
||||
for a_feature in resource[u'featureInstances']:
|
||||
features.append(a_feature[u'feature'][u'name'])
|
||||
resource[u'features'] = u', '.join(features)
|
||||
del(resource[u'featureInstances'])
|
||||
resource[u'features'] = u', '.join([a_feature[u'feature'][u'name'] for a_feature in resource.pop(u'featureInstances')])
|
||||
if u'buildingId' in resource:
|
||||
resource[u'buildingName'] = _getBuildingNameById(cd, resource[u'buildingId'])
|
||||
print_json(None, resource)
|
||||
@@ -11321,7 +11316,7 @@ def doPrintFeatures():
|
||||
if fields:
|
||||
fields = fields % u','.join(fieldsList)
|
||||
features = callGAPIpages(cd.resources().features(), u'list',
|
||||
items=u'features', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
items=u'features', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
for feature in features:
|
||||
feature.pop(u'etags', None)
|
||||
feature.pop(u'etag', None)
|
||||
@@ -11369,20 +11364,20 @@ def doPrintBuildings():
|
||||
if fields:
|
||||
fields = fields % u','.join(fieldsList)
|
||||
buildings = callGAPIpages(cd.resources().buildings(), u'list',
|
||||
items=u'buildings', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
items=u'buildings', customer=GC_Values[GC_CUSTOMER_ID], fields=fields)
|
||||
for building in buildings:
|
||||
building.pop(u'etags', None)
|
||||
building.pop(u'etag', None)
|
||||
building.pop(u'kind', None)
|
||||
if u'floorNames' in building:
|
||||
building[u'floorNames'] = u' '.join(building[u'floorNames'])
|
||||
building[u'floorNames'] = u','.join(building[u'floorNames'])
|
||||
building = flatten_json(building)
|
||||
for item in building:
|
||||
if item not in titles:
|
||||
titles.append(item)
|
||||
csvRows.append(building)
|
||||
sortCSVTitles(u'buildingId', titles)
|
||||
writeCSVfile(csvRows, titles, u'Buildings', to_drive)
|
||||
writeCSVfile(csvRows, titles, u'Buildings', to_drive)
|
||||
|
||||
def doPrintResourceCalendars():
|
||||
cd = buildGAPIObject(u'directory')
|
||||
|
||||
@@ -463,7 +463,7 @@ CROS_ARGUMENT_TO_PROPERTY_MAP = {
|
||||
u'tag': [u'annotatedAssetId',],
|
||||
u'timeranges': [u'activeTimeRanges.activeTime', u'activeTimeRanges.date'],
|
||||
u'times': [u'activeTimeRanges.activeTime', u'activeTimeRanges.date'],
|
||||
u'tpmversioninfo': [u'tpmVersionInfo'],
|
||||
u'tpmversioninfo': [u'tpmVersionInfo',],
|
||||
u'user': [u'annotatedUser',],
|
||||
u'users': [u'recentUsers.email', u'recentUsers.type'],
|
||||
u'willautorenew': [u'willAutoRenew',],
|
||||
@@ -501,7 +501,7 @@ CROS_START_ARGUMENTS = [u'start', u'startdate', u'oldestdate']
|
||||
CROS_END_ARGUMENTS = [u'end', u'enddate']
|
||||
|
||||
# From https://www.chromium.org/chromium-os/tpm_firmware_update
|
||||
CROS_TPM_VULN_VERSIONS = [u'41f', u'420', u'628', u'8520',]
|
||||
CROS_TPM_VULN_VERSIONS = [u'41f', u'420', u'628', u'8520',]
|
||||
CROS_TPM_FIXED_VERSIONS = [u'422', u'62b', u'8521',]
|
||||
|
||||
#
|
||||
@@ -540,6 +540,8 @@ GM_MAP_USER_ID_TO_NAME = u'ui2n'
|
||||
GM_CACHE_DIR = u'gacd'
|
||||
# Reset GAM cache directory after discovery
|
||||
GM_CACHE_DISCOVERY_ONLY = u'gcdo'
|
||||
# Dictionary mapping Building ID to Name
|
||||
GM_MAP_BUILDING_ID_TO_NAME = u'bi2n'
|
||||
#
|
||||
GM_Globals = {
|
||||
GM_SYSEXITRC: 0,
|
||||
@@ -558,6 +560,7 @@ GM_Globals = {
|
||||
GM_MAP_USER_ID_TO_NAME: None,
|
||||
GM_CACHE_DIR: None,
|
||||
GM_CACHE_DISCOVERY_ONLY: True,
|
||||
GM_MAP_BUILDING_ID_TO_NAME: None
|
||||
}
|
||||
#
|
||||
# Global variables defined by environment variables/signal files
|
||||
|
||||
Reference in New Issue
Block a user