Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Computers Report fails with homebysix-patch-1 branch #45

Closed
jwrn3 opened this issue Feb 4, 2020 · 6 comments
Closed

Computers Report fails with homebysix-patch-1 branch #45

jwrn3 opened this issue Feb 4, 2020 · 6 comments

Comments

@jwrn3
Copy link

jwrn3 commented Feb 4, 2020

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:

jwrn3@iMac Spruce % /Library/AutoPkg/Python3/Python.framework/Versions/Current/bin/python3 ./spruce.py --computers
JSS: https://jssdev.jamfcloud.com
Preferences used: ~/Library/Preferences/com.github.autopkg.plist
🌲  Building: Computer Report... 🌲
Traceback (most recent call last):
  File "./spruce.py", line 2170, in <module>
    main()
  File "./spruce.py", line 2166, in main
    run_reports(args)
  File "./spruce.py", line 1945, in run_reports
    results.append(func(**args_dict))
  File "./spruce.py", line 644, in build_computers_report
    report = build_device_report(check_in_period, all_computers)
  File "./spruce.py", line 425, in build_device_report
    "Hardware Model Spread"] = get_version_and_model_spread(devices)
  File "./spruce.py", line 561, in get_version_and_model_spread
    strings = sorted(get_histogram_strings(version_counts, padding=8))
  File "./spruce.py", line 1661, in get_histogram_strings
    result.append((preamble + histogram_bar).decode("utf-8"))
AttributeError: 'str' object has no attribute 'decode'

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:

jwrn3@iMac Spruce % /Library/AutoPkg/Python3/Python.framework/Versions/Current/bin/python3 ./spruce.py --computers
JSS: https://jssdev.jamfcloud.com
Preferences used: ~/Library/Preferences/com.github.autopkg.plist
🌲  Building: Computer Report... 🌲
Traceback (most recent call last):
  File "./spruce.py", line 2173, in <module>
    main()
  File "./spruce.py", line 2169, in main
    run_reports(args)
  File "./spruce.py", line 1948, in run_reports
    results.append(func(**args_dict))
  File "./spruce.py", line 644, in build_computers_report
    report = build_device_report(check_in_period, all_computers)
  File "./spruce.py", line 425, in build_device_report
    "Hardware Model Spread"] = get_version_and_model_spread(devices)
  File "./spruce.py", line 569, in get_version_and_model_spread
    cmp=model_identifier_cmp)
TypeError: 'cmp' is an invalid keyword argument for sort()

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.

@grahampugh
Copy link
Member

Thanks @jwrn3, I hadn't tested that endpoint.

@jwrn3
Copy link
Author

jwrn3 commented Feb 5, 2020

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!

@grahampugh
Copy link
Member

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.

@krispayne
Copy link

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'```

@dev-yeet
Copy link

I'm getting this error too @krispayne. Did you ever find a solution for that?

@dev-yeet
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants