implement commandline arguments for makedmg
authorDiane Trout <diane@caltech.edu>
Tue, 18 Apr 2006 08:24:49 +0000 (08:24 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 18 Apr 2006 08:24:49 +0000 (08:24 +0000)
makelib/osxdist.py

index 500cdd5b729b0f3616d5103e7746e2cea7d48aa3..9072a7a61ccebd2ec77a06e7b4cbec3ba4bfaf85 100644 (file)
@@ -2,6 +2,8 @@
 
 import os
 import sys
+import getopt
+
 from shutil import copy, copytree
 
 def system(cmdline):
@@ -26,6 +28,9 @@ def mkdir(path):
 # http://developer.apple.com/documentation/developertools/Conceptual/SoftwareDistribution/Concepts/sd_disk_images.html
 
 def makedmg(dirlist, volname):
+  """copy a list of directories into a dmg named volname
+  """
+
   # need to detect what the real volume name is
   mussa_mount = '/Volumes/%s' %(volname)
   mussarw_dmg = '%sw.dmg' %(volname)
@@ -42,27 +47,26 @@ def makedmg(dirlist, volname):
   system('hdiutil attach '+mussarw_dmg)
   # copy files
   for d in dirlist:
-    copytree(d, os.path.join(mussa_mount, d))
+    if d[-1] == '/':
+      d = d[:-1]
+    tail = os.path.split(d)[-1]
+    copytree(d, os.path.join(mussa_mount, tail))
 
   system('hdiutil detach '+mussa_mount)
   system('hdiutil convert '+mussarw_dmg +' -format UDZO -o '+mussa_dmg)
   #system('hdiutil internet-enable -yes '+mussa_dmg)
 
-def main(args):
+def prelinkqt(app_name, bundle_dir, qt_lib_dir):
+  """
+  OS X's treatment of dynamic loading is annoying
+  properly prelink all the annoying qt components.
+  """
   framework_subpath = os.path.join("%(framework)s.framework", "Versions", "4.0", "%(framework)s")
   frameworks = ['QtCore', 'QtGui', 'QtOpenGL']
 
-  qt_lib_dir="/usr/local/qt-4.1.1/lib"
   qt_framework=os.path.join(qt_lib_dir, framework_subpath)
-
-  app_name="mussagl"
-  app_dir=app_name+".app"
-  app_binary=app_dir+"/Contents/MacOS/"+app_name
-  app_framework=os.path.join(app_dir, "Contents", "Frameworks", framework_subpath)
-  if not os.path.exists(app_dir):
-    print >>sys.stderr, "please build mussagl first"
-    return 1
-
+  app_binary=bundle_dir+"/Contents/MacOS/"+app_name
+  app_framework=os.path.join(bundle_dir, "Contents", "Frameworks", framework_subpath)
   # install frameworks and update binary
   for frame in frameworks:
     qtframe = qt_framework % ({'framework': frame})
@@ -82,7 +86,49 @@ def main(args):
       contents_exe_path %= ({'framework': frame2})
       system("install_name_tool -change "+qtframe2+" "+contents_exe_path+" "+
              appframe)
-  makedmg([app_dir], 'mussa')
+
+def main(args):
+  qtroot = "/usr/local/qt-4.1.1"
+  bundle_dir = None
+  app_name = None
+  
+  opts, args = getopt.getopt(args, "b:n:q:h", 
+                             ["bundle=", "name=", "qt-root=", "help"])
+  for option, argument in opts:
+    if option in ("-b", "--bundle"):
+      bundle_dir = argument
+    elif option in ("-n", "--name"):
+      app_name = argument
+    elif option in ("-q", "--qt-root"):
+      qtroot = argument
+    elif option in ("-h", "--help"):
+      print "-b | --bundle   specify path to application bundle dir"
+      print "-n | --name     specify application name (and volume name)"
+      print "-q | --qtdir    where is qt is installed"
+      print "-h | --help     how to use"
+      return 0
+
+  # compute bundle name/dir
+  if bundle_dir is None and app_name is None:
+    print >>sys.stderr, "I need a name or bundle path"
+    return 1
+  elif bundle_dir is None:
+    bundle_dir = app_name + ".app"
+  elif app_name is None:
+    # strip off trailing /
+    if bundle_dir[-1] == os.path.sep:
+      bundle_dir = bundle_dir[:-1]
+    path, file = os.path.split(bundle_dir)
+    app_name = os.path.splitext(file)[0]
+
+  if not os.path.exists(bundle_dir):
+    print >>sys.stderr, "couldn't find an app at %s" % (app_bundle)
+    return 1
+  
+  qt_lib_dir = os.path.join(qtroot, 'lib')
+
+  prelinkqt(app_name, bundle_dir, qt_lib_dir)
+  makedmg([bundle_dir]+args, app_name)
 
 if __name__ == "__main__":
   main(sys.argv[1:])