chilcote / outset

Automatically process packages, profiles, and scripts during boot, login, or on demand.
572 stars 58 forks source link

Outset 3.0.0/3.0.1 Error adding excluded users #78

Closed gsmc-alx closed 4 years ago

gsmc-alx commented 4 years ago

I get the following error when attempting to add excluded users with the command /usr/local/outset/outset --add-ignored-user FOO

Traceback (most recent call last):
  File "/usr/local/outset/outset", line 634, in <module>
    main()
  File "/usr/local/outset/outset", line 450, in main
    prefs = plistlib.readPlist(outset_preferences)
AttributeError: module 'plistlib' has no attribute 'readPlist'

MacOS 10.15.7 I have Python3 installed from the Developer Tools.

gsmc-alx commented 4 years ago

Ah, plistlib.readPlist is no longer present in Python 3.9 (I had forgotten I'd also installed it from the Python.org package). https://docs.python.org/3.9/library/plistlib.html#plistlib.load

I have Python 3.9 installed, it seems.

gsmc-alx commented 4 years ago

plistlib.writePlist has also been removed from Python 3.9.

chilcote commented 4 years ago

Thanks, can you try the change in https://github.com/chilcote/outset/tree/plistlib and see if that fixes it for you?

gsmc-alx commented 4 years ago

Hi, that was quick!

Sadly that doesn't work. I now get this error, when trying to add an ignored user:

Traceback (most recent call last): File "/usr/local/outset/outset", line 634, in main() File "/usr/local/outset/outset", line 450, in main prefs = plistlib.load(outset_preferences) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/plistlib.py", line 840, in load header = fp.read(32) AttributeError: 'str' object has no attribute 'read'

I don't know any Python, but did manage to hack together a test script to read from the Outset prefs file, using the plistlib docs and a bit of trial-and-error.

I don't have it to hand right now, but from memory, I think I had to open the file first, (presumably into RAM), then load that.

Something like:

with open(outset_preferences, 'rb') as fp:
    prefs = plistlib.load(fp)

I didn't get round to attempting to fix the writing back to the plist, but I guess it's something like:

with open(outset_preferences, 'wb') as fp:
    plistlib.dump(prefs, fp)
gsmc-alx commented 4 years ago

I replaced all occurrences of plistlib.load() and plistlib.dump() with the above, and prefs reading and writing now does seem to work (at least for adding and removing ignored users)!

I don't know enough about Python to be sure it's not going to cause other issues later.

I also don't know if more has to be done, in order to create the prefs file on disk, if it doesn't exist, though. Maybe plistlib.dump creates the file if it doesn't already exist. Or maybe opening a non-existent file creates it automatically if it doesn't exist on disk.

chilcote commented 4 years ago

I'm happy to take a PR for that if you want, or I can update the branch I have. Then if it all works out, I can cut a new release.

gsmc-alx commented 4 years ago

I issued a pull-request. I hope I did it right. I'm not a big GitHub user, so I may have done it wrong.

chilcote commented 4 years ago

Is this issue fixed now?

gsmc-alx commented 4 years ago

Seems to be!

Thanks for the quick release.

chilcote commented 4 years ago

Thanks. After Allister is done fixing everything else I'll cut a new pkg :)