-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMunkiHelperAppDelegate.py
90 lines (72 loc) · 2.65 KB
/
MunkiHelperAppDelegate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# MunkiHelperAppDelegate.py
# MunkiHelper
#
# Created by Jesse Peterson on 5/19/12.
# Copyright __MyCompanyName__ 2012. All rights reserved.
#
from Foundation import *
from AppKit import *
import objc
import os
class MunkiHelperAppDelegate(NSObject):
munkiFolderPath = objc.ivar(u'munkiFolderPath')
def applicationDidFinishLaunching_(self, sender):
NSLog("Application did finish launching.")
@objc.IBAction
def openCatalogsFolder_(self, sender):
if self.munkiFolderPath != None:
ws = NSWorkspace.sharedWorkspace()
ws.selectFile_inFileViewerRootedAtPath_(os.path.join(self.munkiFolderPath, 'catalogs'), None)
@objc.IBAction
def openManifestsFolder_(self, sender):
if self.munkiFolderPath != None:
ws = NSWorkspace.sharedWorkspace()
ws.selectFile_inFileViewerRootedAtPath_(os.path.join(self.munkiFolderPath, 'manifests'), None)
@objc.IBAction
def openPkgsFolder_(self, sender):
if self.munkiFolderPath != None:
ws = NSWorkspace.sharedWorkspace()
ws.selectFile_inFileViewerRootedAtPath_(os.path.join(self.munkiFolderPath, 'pkgs'), None)
@objc.IBAction
def openPkgsinfoFolder_(self, sender):
if self.munkiFolderPath != None:
ws = NSWorkspace.sharedWorkspace()
ws.selectFile_inFileViewerRootedAtPath_(os.path.join(self.munkiFolderPath, 'pkgsinfo'), None)
@objc.IBAction
def rebuildCatalogs_(self, sender):
ascr = NSAppleScript.alloc().initWithSource_('''
tell application "Terminal"
activate
do script "/usr/local/munki/makecatalogs %s"
end tell
''' % self.munkiFolderPath)
ascr.executeAndReturnError_(None)
def isValidPackageDrag(self, pboard):
if self.munkiFolderPath is None:
return False
if NSFilenamesPboardType not in pboard.types():
return False
filesArray = pboard.propertyListForType_(NSFilenamesPboardType)
if len(filesArray) != 1:
return False
package = filesArray[0]
if os.path.isdir(package):
NSLog("Munki package cannot be a directory")
return False
if package.lower().endswith('.dmg') or package.lower().endswith('.pkg'):
return True
NSLog("Not a valid Munki package (DMG or PKG only)")
return False
def addPackage(self, pkg):
NSLog("Attempting to add package - sending AppleScript")
basename = os.path.basename(pkg)
ascr = NSAppleScript.alloc().initWithSource_('''
tell application "Terminal"
activate
set curWin to do script "cp -pv '%s' '%s/pkgs'"
do script "/usr/local/munki/makepkginfo '%s/pkgs/%s' > '%s/pkgsinfo/%s.pkginfo'" in curWin
do script "open -R '%s/pkgsinfo/%s.pkginfo'" in curWin
end tell
''' % (pkg, self.munkiFolderPath, self.munkiFolderPath, basename, self.munkiFolderPath, basename, self.munkiFolderPath, basename))
ascr.executeAndReturnError_(None)