Successfully reported this slideshow.
Your SlideShare is downloading. ×

Python for Mac Admins

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffers
Loading in …3
×

Check these out next

1 of 17 Ad

Python for Mac Admins

Download to read offline

These slides accompanied a talk that was given at the MacDevOps YVR 2015 conference in Vancouver and the MacDeployment 2015 workshop at the University of Calgary.

These slides are brief, as the talk was mostly live demonstration. A video recording of the MacDevOps YVR presentation is available here:

http://macdevops.ca/MDO2015/tim/Default.html

These slides accompanied a talk that was given at the MacDevOps YVR 2015 conference in Vancouver and the MacDeployment 2015 workshop at the University of Calgary.

These slides are brief, as the talk was mostly live demonstration. A video recording of the MacDevOps YVR presentation is available here:

http://macdevops.ca/MDO2015/tim/Default.html

Advertisement
Advertisement

More Related Content

Similar to Python for Mac Admins (20)

Advertisement

Recently uploaded (20)

Python for Mac Admins

  1. 1. Python for Mac Admins Tim Sutton Concordia University, Faculty of Fine Arts, Montreal
  2. 2. https://github.com/timsutton/ python-macadmins-2015
  3. 3. Common script tasks
  4. 4. Common script tasks • Work with files on disk (copy, read, delete, check)
  5. 5. Common script tasks • Work with files on disk (copy, read, delete, check) • Parse structured formats (plist, XML, JSON)
  6. 6. Common script tasks • Work with files on disk (copy, read, delete, check) • Parse structured formats (plist, XML, JSON) xpath /tmp/ Date.xml // LastSeen/text | sed -e 's/ <text>//g' | sed -e $'s/</ text>/n/g'
  7. 7. Common script tasks • Work with files on disk (copy, read, delete, check) • Parse structured formats (plist, XML, JSON) • Execute commands, do things based on results and output defaults launchctl installer pkgutil lsbom pkgbuild productbuild dscl scutil PlistBuddy plutil diskutil hdiutil ditto fdesetup system_profiler
  8. 8. Common script tasks • Work with files on disk (copy, read, delete, check) • Parse structured formats (plist, XML, JSON) • Execute commands, do things based on results and output • Wish there was a command-line tool for X
 (example: github.com/timsutton/customdisplayprofiles) defaults launchctl installer pkgutil lsbom pkgbuild productbuild dscl scutil PlistBuddy plutil diskutil hdiutil ditto fdesetup system_profiler
  9. 9. Bashisms • Quoting and escaping for file names, command arguments • Looping over separated fields (OLDIFS=$IFS) • Primitive types/structures - strings, numbers, arrays • Portability of command options (BSD vs. GNU versions of e.g. `find`, `sed`) • Handling the unexpected • Hard to maintain (sharing code, state, options)
  10. 10. Why Python? • Large standard library (“batteries included”) for sysadmin-type tasks • Safer and more readable • PyObjC: lightweight use of OS X APIs • Exists on every OS X, works the same on other OSes • Proven, popular language
  11. 11. Further study Google Mac Python module https://github.com/google/macops/tree/master/gmacpyutil Munki https://github.com/munki/munki And (60!) more projects https://github.com/timsutton/python-macadmin-tools
  12. 12. Use a linter and editor plugin (e.g. pylint/flake8, SublimeLinter)
  13. 13. Dash doc browser https://kapeli.com/dash ($20)
  14. 14. Dash doc browser https://kapeli.com/dash ($20)
  15. 15. Learning resources • http://stackoverflow.com/questions/tagged/python • http://www.diveintopython.net • http://learnpythonthehardway.org • #python channel on Freenode IRC
  16. 16. Thank you!

×