Skip to content

Instantly share code, notes, and snippets.

@gregneagle
Created January 3, 2014 19:00
Show Gist options
  • Save gregneagle/8244176 to your computer and use it in GitHub Desktop.
Save gregneagle/8244176 to your computer and use it in GitHub Desktop.
Some scripts from my MacSysAdmin 2013 demo
#!/usr/bin/env python
# encoding: utf-8
"""
finish_jenkins_autopkg_run.py
Created by Greg Neagle on 2013-08-23.
"""
import os
import plistlib
import pprint
import subprocess
import shutil
from CoreFoundation import CFPreferencesCopyAppValue
def consolidate_reports(report_dir):
event_types = ["failures", "new_downloads", "new_packages", "new_imports"]
# make empty report
report = {}
for event_type in event_types:
report[event_type] = []
# read and consolidate plists
for item in os.listdir(report_dir):
if item.endswith('.plist'):
plist = plistlib.readPlist(os.path.join(report_dir, item))
for event_type in event_types:
report[event_type].extend(plist.get(event_type, []))
return report
def main():
# consolidate the info from the recipe reports
cache_dir = os.path.join(os.environ["JENKINS_HOME"], "autopkg-jenkins")
report = consolidate_reports(cache_dir)
# "pretty"-print report
pprint.pprint(report)
if report["new_imports"]:
# need to run makecatalogs
# get path to munki_repo
munki_repo = CFPreferencesCopyAppValue(
"MUNKI_REPO", "com.github.autopkg")
# call makecatalogs
subprocess.check_call(["/usr/local/munki/makecatalogs", munki_repo])
# do some cleanup so our demo works
try:
shutil.rmtree("/Users/Shared/Jenkins/Library/AutoPkg/Cache")
except BaseException:
pass
if __name__ == '__main__':
main()
#!/usr/bin/env python
# encoding: utf-8
"""
setup_jenkins_autopkg_run.py
Created by Greg Neagle on 2013-08-23.
"""
import sys
import os
import shutil
import subprocess
MUNKI_REPO = "/Users/Shared/test_munki_repo"
def main():
cache_dir = os.path.join(os.environ['JENKINS_HOME'], 'autopkg-jenkins')
if os.path.isdir(cache_dir):
shutil.rmtree(cache_dir)
os.makedirs(cache_dir)
subprocess.check_call(
["/usr/bin/defaults", "write",
"com.github.autopkg", "MUNKI_REPO" MUNKI_REPO])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment