Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Python for Mac Admins
Tim Sutton
Concordia University,
Faculty of Fine Arts, Montreal
https://github.com/timsutton/
python-macadmins-2015
Common script tasks
Common script tasks
• Work with files on disk (copy, read, delete, check)
Common script tasks
• Work with files on disk (copy, read, delete, check)
• Parse structured formats (plist, XML, JSON)
Common script tasks
• Work with files on disk (copy, read, delete, check)
• Parse structured formats (plist, XML, JSON)
xpa...
Common script tasks
• Work with files on disk (copy, read, delete, check)
• Parse structured formats (plist, XML, JSON)
• E...
Common script tasks
• Work with files on disk (copy, read, delete, check)
• Parse structured formats (plist, XML, JSON)
• E...
Bashisms
• Quoting and escaping for file names, command
arguments
• Looping over separated fields (OLDIFS=$IFS)
• Primitive ...
Why Python?
• Large standard library (“batteries included”) for
sysadmin-type tasks
• Safer and more readable
• PyObjC: li...
Further study
Google Mac Python module
https://github.com/google/macops/tree/master/gmacpyutil
Munki
https://github.com/mu...
Use a linter and editor plugin
(e.g. pylint/flake8, SublimeLinter)
Dash doc browser
https://kapeli.com/dash ($20)
Dash doc browser
https://kapeli.com/dash ($20)
Learning resources
• http://stackoverflow.com/questions/tagged/python
• http://www.diveintopython.net
• http://learnpythont...
Thank you!
Python for Mac Admins
Upcoming SlideShare
Loading in …5
×

Python for Mac Admins

322 views

Published on

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

Published in: Technology
  • Be the first to comment

  • Be the first to like this

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!

×