Add view all|company|personal to print devices (#1254)

* Add view all|company|personal to print devices

Update documentation

* sync devices cleanup

* Update sync devices documentation

* Cleanup;

The advantage here is that they will be no filter errors unless you specify a particular view and a filter that doesn't match

* Simplify selection of devices to print

Default - all
Positve choices
Negative choices - backwards compatible
This commit is contained in:
Ross Scroggs
2020-09-29 11:47:06 -07:00
committed by GitHub
parent dc90fb9c94
commit 5e38137916
3 changed files with 29 additions and 25 deletions

View File

@ -1146,18 +1146,17 @@ gam block deviceuser [id] <DeviceUserID>
gam delete deviceuser [id] <DeviceUserID>
gam cancelwipe deviceuser [id] <DeviceUserID>
gam wipe deviceuser [id] <DeviceUserID>
gam print devices [todrive] [query <QueryDevice>]
gam print devices [todrive] [filter|query <QueryDevice>]
[orderby <DeviceOrderByFieldName> [ascending|descending]]
[nocompanydevices] [nouserdevices] [nousers]
[formatjson [quotechar <Character>]]
gam sync devices
[company|personal|nocompanydevices|nopersonaldevices]
[nodeviceusers]
gam sync devices [filter|query <QueryDevice>]
csvfile <FileName>
[serialnumber_column <String>]
[devicetype_column <String>]
[assetid_column <String>]
[static_devicetype <DeviceType>]
[unassigned_missing_action delete|wipe|nonothing]
[assigned_missing_action delete|wipe|nonothing]
(devicetype_column <String>)|(static_devicetype <DeviceType>)
serialnumber_column <String>
[assettag_column <String>]
[unassigned_missing_action delete|wipe|donothing]
[assigned_missing_action delete|wipe|donothing]
gam update mobile <MobileID>|query:<QueryMobile> action <MobileAction> [doit] [if_users|match_users <UserTypeEntity>]
gam delete mobile <MobileID>

View File

@ -117,7 +117,7 @@ def print_():
parent = 'devices/-'
device_filter = None
get_device_users = True
get_device_views = ['COMPANY_INVENTORY', 'USER_ASSIGNED_DEVICES']
view = None
orderByList = []
titles = []
csvRows = []
@ -129,11 +129,17 @@ def print_():
if myarg in ['filter', 'query']:
device_filter = sys.argv[i+1]
i += 2
elif myarg == 'company':
view = 'COMPANY_INVENTORY'
i += 1
elif myarg == 'personal':
view = 'USER_ASSIGNED_DEVICES'
i += 1
elif myarg == 'nocompanydevices':
get_device_views.remove('COMPANY_INVENTORY')
view = 'USER_ASSIGNED_DEVICES'
i += 1
elif myarg == 'nopersonaldevices':
get_device_views.remove('USER_ASSIGNED_DEVICES')
view = 'COMPANY_INVENTORY'
i += 1
elif myarg == 'nodeviceusers':
get_device_users = False
@ -166,6 +172,7 @@ def print_():
else:
controlflow.invalid_argument_exit(sys.argv[i], 'gam print devices')
view_name_map = {
None: 'Devices',
'COMPANY_INVENTORY': 'Company Devices',
'USER_ASSIGNED_DEVICES': 'Personal Devices',
}
@ -174,9 +181,7 @@ def print_():
else:
orderBy = None
devices = []
for view in get_device_views:
view_name = view_name_map.get(view, 'Devices')
page_message = gapi.got_total_items_msg(view_name, '...\n')
page_message = gapi.got_total_items_msg(view_name_map[view], '...\n')
devices += gapi.get_all_pages(ci.devices(), 'list', 'devices',
customer=customer, page_message=page_message,
pageSize=100, filter=device_filter, view=view, orderBy=orderBy)
@ -273,8 +278,7 @@ def sync():
for row in input_file:
# upper() is very important to comparison since Google
# always return uppercase serials
serialnumber = row[serialnumber_column].strip().upper()
local_device = {'serialNumber': serialnumber}
local_device = {'serialNumber': row[serialnumber_column].strip().upper()}
if static_devicetype:
local_device['deviceType'] = static_devicetype
else:
@ -294,10 +298,10 @@ def sync():
remote_device_map = {}
for remote_device in remote_devices:
sn = remote_device['serialNumber']
last_sync = remote_device.pop('lastSyncTime')
last_sync = remote_device.pop('lastSyncTime', NEVER_TIME_NOMS)
name = remote_device.pop('name')
remote_device_map[sn] = {'name': name}
if last_sync == '1970-01-01T00:00:00Z':
if last_sync == NEVER_TIME_NOMS:
remote_device_map[sn]['unassigned'] = True
devices_to_add = [device for device in local_devices if device not in remote_devices]
missing_devices = [device for device in remote_devices if device not in local_devices]

View File

@ -1359,6 +1359,7 @@ GC_VAR_INFO = {
# Google API constants
NEVER_TIME = '1970-01-01T00:00:00.000Z'
NEVER_TIME_NOMS = '1970-01-01T00:00:00Z'
ROLE_MANAGER = 'MANAGER'
ROLE_MEMBER = 'MEMBER'
ROLE_OWNER = 'OWNER'