Certainly it seems like there is a core of others who agree when it
comes to Mac admin stuff (InstaDMG, Munki, this project).
Is there any roadmap or todo list for this project?
I think there is the assumption out there that pymacadmin == crankd
The fact that the core module is installed in /lib/appsupport/crankd
instead of site-packages struck me as odd
I'm interested in contributing to the core library - but given that
everyone is tremendously busy I understand that there isn't always
time to write up exhaustive roadmaps etc.
to kick things off a bit, I'm going to list a brainstorm of mac os
technologies that might be good candidates for coverage in a core
library, and hopefully others will add to, suggest outlines of
possible implementation, or suggest features of the below that would
be the most useful to expose. I'd be happy to clean up such a
discussion and turn it into a wiki page.
- hdiutil (Karl's object from InstaDMG seems like a great start)
- ACLs : add, remove, and propagate
- diskutil
ie:
d = DiskUtil()
d.disks['Macintosh HD'].uuid
>>11111111-2222-3333-4444-555555555555
d.disks['Macintosh HD'].eject()
etc
- dscl
- pmset
- working with finder aliases and alis plist data
- launch services (wrapper for lsregister, python version of duti)
- ioreg
- improve plistlib to handle binary plists (via plutil) and get back
into OSX/python trunk
some others that are probably easiest to keep using the command line
syntax?
ASR
installer
launchctl
-Preston
>
> On Fri, Jul 17, 2009 at 11:30 AM, Preston Holmes<sanroq...@gmail.com
> > wrote:
>>
>> - diskutil
>> ie:
>> d = DiskUtil()
>> d.disks['Macintosh HD'].uuid
>> >>11111111-2222-3333-4444-555555555555
>> d.disks['Macintosh HD'].eject()
>> etc
>
> I've actually got a lot of this done that I should check in and
> clean up.
>
Yes please ;-)
>
>
>
>>
>> - dscl
>
> If only we had an ObjC DirectoryServices API...
While preferred - seems that some of the more common/useful tasks
could be done by just wrapping dscl
>
>> - pmset
>> - working with finder aliases and alis plist data
>> - launch services (wrapper for lsregister, python version of duti)
>> - ioreg
>>
>> - improve plistlib to handle binary plists (via plutil) and get back
>> into OSX/python trunk
>
> I don't see why you'd do this when you can just import Foundation and
> use all the NSDictionary to/from file methods?
1) because plistlib is out there an used in code
2) because plistlib.readPlist(pathOrFile) is so simple
if getting changes into plistlib isn't feasible, then a pymacadmin
module that replaces its ease of use with calls to Foundation would
seem nearly as useful.
>
>>
>> some others that are probably easiest to keep using the command line
>> syntax?
>>
>> ASR
>> installer
>> launchctl
>
> If only we had an ObjC launchd framework....
again, in the absence of...
given python's good support for subprocesses, I don't see wrapping as
too objectionable
there is also always higher level goodness around monitoring and
reporting launchd events.
-Preston
...
> If only we had an ObjC DirectoryServices API...
...
We might, actually.
Included in Apple's open-source DSTools project (do a find in page for
"DSTools" at http://www.opensource.apple.com/release/mac-os-x-1057/ )
is a project called "DSObjCWrappers". The current version (112.1)
appears to be undocumented (and I was hoping to figure it out sometime
if I had the time).
Perhaps more interesting than that is that it appears to live on
Leopard machines in /System/Library/PrivateFrameworks/
DSObjCWrappers.framework.
As far as I can tell, they are the same version. (I'm running OS X
10.5.7, and the open source download is the one that corresponds to
it.) /System/Library/PrivateFrameworks/DSObjCWrappers.framework/
Versions/A/Resources/version.plist contains these keys (among others):
<key>CFBundleVersion</key>
<string>1.3</string>
<key>ProjectName</key>
<string>DSTools</string>
<key>SourceVersion</key>
<string>1120100</string>
I suspect that means that source version is 112.1 of the DSTools
project.
So, the source is open, but the framework is private. It may just be
safe to use, though. [Assuming we can get at it through the PyObjC
bridge].
Cheers,
Clinton
I've toyed with making modules in a package and then symlinking them for use
as command line tools, when that is needed for stuff that must be
standalone. It works. (I did a little bit of work on this across major Mac
OS X versions, since Tiger and Leopard shipped with different Python
versions and site-packages paths. I think I might have successfully use a
.pth file to jump between 2.3 and 2.5.)
Also, I only put stuff in site-packages, and I've taken to the use of a
package to namespace what I've written. The import statement may get
slightly longer but it's not usually a big deal.
Eventually, maybe some/all of this can just be contributed back to Python
itself. I think at that potential future time, if not sooner, issues of
namespacing and whatnot come up.
For that reason (as well as others), I'd suggest we try to follow PEP 8 for
contributions if it is not being done now. I try do that for my own stuff.
There is my random contribution of the month. You're welcome to it. :)
--
Jeremy
>>>
>>> - improve plistlib to handle binary plists (via plutil) and get back
>>> into OSX/python trunk
>>
>> I don't see why you'd do this when you can just import Foundation and
>> use all the NSDictionary to/from file methods?
>
> 1) because plistlib is out there an used in code
> 2) because plistlib.readPlist(pathOrFile) is so simple
It's really trivial to replace plistlb.readPlist() with something that
can handle binary plists as well as XML/text ones:
def readPlist(plistfile):
"""Read a plist, return a dict.
This method can deal with binary plists,
whereas plistlib cannot.
Args:
plistfile: Path to plist file to read
Returns:
dict of plist contents.
"""
from Foundation import NSDictionary
return NSDictionary.dictionaryWithContentsOfFile_(plistfile)
You don't need to modify/replace plistlib.writePlist() because it's
fine to write out a plist in XML/text format.
-Greg
>> I don't see why you'd do this when you can just import Foundation
>> and use all the NSDictionary to/from file methods?
>
> 1) because plistlib is out there an used in code
> 2) because plistlib.readPlist(pathOrFile) is so simple
>
> if getting changes into plistlib isn't feasible, then a pymacadmin
> module that replaces its ease of use with calls to Foundation would
> seem nearly as useful.
I agree with Nigel that plistlib is not worth using at this point.
And the Foundation replacements are easy drop-ins:
import Foundation
plist = Foundation.NSDictionary.dictionaryWithContentsOfFile_(plistPath)
Or if you are not sure that the root is a NSDictionary (or want more
to know the format):
import Foundation
plistData = Foundation.NSData.dataWithContentsOfFile_(plistPath)
dataObject, plistFormat, error =
Foundation.NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_
(plistData, Foundation.NSPropertyListMutableContainers)
And if you use the later form, then you can write things back out in
any format the Foundation supports:
import Foundation
plistData, error =
Foundation.NSPropertyListSerialization.dataFromPropertyList_format_errorDescription_
(dataObject, Foundation.NSPropertyListBinaryFormat_v1_0)
plistData.writeToFile_atomically_(plistPath, TRUE)
And the difference between wrapping a command line utility and
actually using a binary interface is huge. The latter is much more
dependable.
--
Karl Kuehn
lar...@softhome.net
> I agree with Nigel that plistlib is not worth using at this point.
> And the Foundation replacements are easy drop-ins:
Despite my reference to plutil, my basic point is that the need for a
working plistlib, or something like it persists.
I don't think there is anyway that
"Foundation
.NSPropertyListSerialization
.propertyListFromData_mutabilityOption_format_errorDescription_"
can be considered pythonic.
plistlib has been dropped from python as of 2.6 (yet I still see it in
[REDACTED])
http://svn.python.org/view/python/tags/r261/Lib/plat-mac/
Apple is in the business of extending python with mac/darwin specific
modules:
http://www.opensource.apple.com/source/python_modules/python_modules-12/
So either a plistlib replacement that uses foundation could be
contributed to Darwin, or to PyMacAdmin - but I'll stick my assertion
that PyObjC is not a drop in replacement for plistlib in general
purpose python scripts.
-Preston
> As soon as you start working with PyObjC your code isn't really
> pythonic at all.
I guess I'm really not communicating my point well.
I'm wondering whether anyone else agrees that PyMacAdmin module, as a
python module should generally offer pythonic functions and classes to
interact with Apple system technologies.
That the *implementation* of these functions and classes may heavily
use PyObjC, but that the PyObjC should, whenever possible, not be
exposed in a module's API.
To use our current example of plists
plists are heavily used in mac administration and are not going away
It would be useful for for Mac Python scripters to have a module that
did 4 simple things
convert from a python dictionary to and from a plist in either string
or file format
I think it reasonable for Mac Python scripters to be able to do this
without using PyObjC foundation calls *directly* in their script
I'm thinking of new potential users of Python and PyMacAdmin - not all
of them are going to come in wanting to simultaneously grok both
python and Cocoa frameworks
Sorry to keep banging on this, I'm just trying to get a read on
whether people think the USAGE of PyMacAdmin should be pythonic (I
think so) regardless of whether it uses non-pythonic PyObjC - all I'm
hearing is "Just use Foundation"
-Preston
> I guess I'm really not communicating my point well.
>
> I'm wondering whether anyone else agrees that PyMacAdmin module, as a
> python module should generally offer pythonic functions and classes to
> interact with Apple system technologies.
>
> That the *implementation* of these functions and classes may heavily
> use PyObjC, but that the PyObjC should, whenever possible, not be
> exposed in a module's API.
I was agreeing with you both before and after you re-explained. I'm pretty
happy to let others delve into PyObjC, myself. Having a Pythonic wrapper
around the system stuff while simultaneously making things work
better/faster/more broadly would be fantastic.
--
Jeremy
I missed out on most of this discussion (*slow* DSL installer at home)
but just wanted to note that the balance I've wanted to strike (if not
perhaps one I've consistently hit) is to be pythonic except in areas
which are so intrinsically Mac-specific that anyone using them will
need to learn a bit of Cocoa anyway - my feeling being that in such
cases it's better to have the terms be Google-able rather than a
Pythonic variant nobody else uses. As an example, if you're dealing
with NSWorkspace notifications, it's reasonable to say that you're
going to need to learn at least a little Cocoa.
Chris