Closed jwrn3 closed 4 years ago
Thanks @jwrn3, I hadn't tested that endpoint.
As a quick proof of concept I came up with the following:
Change the sort to use the key function:
strings = sorted(get_histogram_strings(model_counts, padding=8),
key=model_compare)
The key function
def model_compare(histogram_string):
"""Return Model Identifier for use as key in sorted() function.
Args:
histogram_string: Histogram string comprising of Mac model, count and emoji e.g.
iMac Intel (21.5-inch, Late 2013) / iMac14,1 (2): ππππππ
Returns:
Model Identifier e.g. iMac14,1
"""
pattern = re.compile(r"(\D+\d+,\d+)")
string_search = re.search(pattern, histogram_string)
if string_search:
return string_search.group(1)
This sorts the model histogram purely on the model identifier e.g. iMac14,1. I've done a few tests on py2.7 and 3.x and it sorts as expected. Nothing more than a proof of concept though!
Thanks a lot for this work! I put in the code and it worked well in my tests with both py2 and 3. So, I've pushed it to tag/release 3.0.0b3.
I see to still have TypeErrors when using the latest release from this repo.
Unrelated?
JSS: https://server.com:8443
Preferences used: ~/Library/Preferences/com.github.autopkg.plist
* Building: Computer Report... *
Traceback (most recent call last):
File "/Users/autopkg/src/Spruce/spruce.py", line 2436, in <module>
main()
File "/Users/autopkg/src/Spruce/spruce.py", line 2432, in main
run_reports(args)
File "/Users/autopkg/src/Spruce/spruce.py", line 2187, in run_reports
results.append(func(**args_dict))
File "/Users/autopkg/src/Spruce/spruce.py", line 650, in build_computers_report
report = build_device_report(check_in_period, all_computers)
File "/Users/autopkg/src/Spruce/spruce.py", line 448, in build_device_report
) = get_version_and_model_spread(devices)
File "/Users/autopkg/src/Spruce/spruce.py", line 601, in get_version_and_model_spread
strings = sorted(get_histogram_strings(model_counts, padding=8), key=model_compare)
TypeError: '<' not supported between instances of 'NoneType' and 'str'```
I'm getting this error too @krispayne. Did you ever find a solution for that?
never mind, figured it out and will share for anyone else that might have this issue:
if you have a computer/device enrollment that doesn't have a histogram/model name then this will fail. Easy way to tell is by searching all of your computers at once (blank search) and sort by Model. Anything that's blank will need to be fixed or deleted, and then the script will run fine.
Autopkg v2.0.1RC2 python-jss v2.1 JSSImporter v1.1.0
When invoking Spruce either via
/Library/AutoPkg/Python3/Python.framework/Versions/Current/bin/python3 ./spruce.py --computers
or/Library/AutoPkg/Python3/Python.framework/Versions/Current/bin/python3 ./spruce.py
the report fails with the following error:I have no mobile devices in this JSS so cannot test --mobile_devices but all other reports succeed.
If I drop the .decode I get further but then hit the following error:
After doing a little digging it looks like the sort() function is rather different in Py3 so a lot of the code in model_identifier_cmp() needs reworking. Additionally cmp() isn't available in python3 I'm not sure how viable it is to ensure compatibility with both py2 & py3.
I'll try and kick the issue around a little.