aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mekanisti.fi>2009-10-21 22:44:59 +0300
committerFilipp Lepalaan <filipp@mekanisti.fi>2009-10-21 22:44:59 +0300
commit881aed35576be8a35a33ed1c6ebde06a2d9722cf (patch)
tree27a50887653f30e88c7a9e650a5a5dbd2aab255f
downloadBatchDMG-881aed35576be8a35a33ed1c6ebde06a2d9722cf.tar.gz
BatchDMG-881aed35576be8a35a33ed1c6ebde06a2d9722cf.tar.bz2
BatchDMG-881aed35576be8a35a33ed1c6ebde06a2d9722cf.zip
Initial commit
-rw-r--r--batchdmg.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/batchdmg.py b/batchdmg.py
new file mode 100644
index 0000000..63570ff
--- /dev/null
+++ b/batchdmg.py
@@ -0,0 +1,40 @@
+"""
+ batchdmg.py
+ Batch-create DMG files from mounted media
+ @author Filipp Lepalaan <filipp@mac.com>
+ @created 20.10.2009
+ @updated 21.10.2009
+ http://developer.apple.com/cocoa/pyobjc.html
+ NSRunLoop must be used instead of threads or forking
+"""
+import sys, time
+from AppKit import *
+from subprocess import Popen
+
+class Imager(NSObject):
+ def init(self):
+ nc = NSWorkspace.sharedWorkspace().notificationCenter()
+ nc.addObserver_selector_name_object_(self, "observeCenter:", "NSWorkspaceDidMountNotification", None)
+ print "Waiting for media..."
+
+ def observeCenter_(self, notification):
+ ui = notification.userInfo()
+ path = ui['NSDevicePath'].encode("utf-8")
+ name = ui['NSWorkspaceVolumeLocalizedNameKey'].encode("utf-8")
+ util = "/usr/bin/hdiutil"
+ print " - imaging '%s'" % (name)
+ cmd = [util, "create", "-format", "UDBZ", "-srcfolder", path, name+".dmg"]
+
+ Popen(cmd, shell=False).communicate()
+ Popen([util, "eject", "-quiet", path], shell=False).communicate()
+
+ print "Ejecting '%s'" % (name)
+ print "Waiting for media..."
+
+ def dealloc(self):
+ nc = NSWorkspace.sharedWorkspace().notificationCenter()
+ nc.removeObserver_(self)
+
+rl = NSRunLoop.currentRunLoop()
+s = Imager.alloc().init()
+rl.run() \ No newline at end of file