← Back to team overview

bzr-mac team mailing list archive

Re: bzr-mac-installers project?

 

It should be possible to create a basic Installer package document using Package Maker (included in the developer tools), then use the command-line mode of the same program to build the package from a script.

I've actually recently switched away from bdist_mpkg to a more custom solution where I install the Python package in a temporary root and build the package directly from that "staged" package. This may be a better way going forward to build the Mac OS X package. The code for that is below:

def _curPath():
   return os.path.abspath(os.path.dirname(sys.argv[0]))

def run_shell_cmd(command, shell=True, env=None):
   command_env = dict(os.environ)
   if env:
       command_env.update(env)
   p = subprocess.Popen(command, shell=shell, env=command_env)
   p.wait()

class Package(Command):

description = "Stage in a destination root and build a native binary-only Mac OS X package."
   user_options = []

   def initialize_options(self):
       pass

   def finalize_options(self):
       pass

   def run(self):
install = self.reinitialize_command('install', reinit_subcommands=1)
       install.root = os.path.join(_curPath(), 'mypackage.dst')
       install.optimize = '2'

       log.info("staging to destination root")
       self.run_command('install')

       log.info("cleaning destination root")
run_shell_cmd(['/usr/bin/find', '-d', install.root, '-name', '.DS_Store', '-exec', 'rm', '{}', ';'], shell=False)

       log.info("building package")
       out_pkg = os.path.join(_curPath(), 'dist', 'My Package.pkg')
       run_shell_cmd(['/bin/rm', '-rf', out_pkg], shell=False)
       run_shell_cmd(
['/Developer/Applications/Utilities/PackageMaker.app/ Contents/MacOS/PackageMaker',
            '--doc', os.path.join(_curPath(), 'mypackage.pmdoc'),
            '--out', out_pkg,
           ],
           shell=False)

       log.info("building disk image")
       template = os.path.join(_curPath(), 'MyPackage_template.dmg')
run_shell_cmd(['/usr/bin/hdiutil', 'attach', template], shell=False) run_shell_cmd(['/bin/cp', '-rp', out_pkg, '/Volumes/My Package/'], shell=False) run_shell_cmd(['/usr/bin/hdiutil', 'detach', '/Volumes/My Package/'], shell=False)

       output = os.path.join(_curPath(), 'MyPackage-%s.dmg' % VERSION)
       run_shell_cmd(['/bin/rm', '-f', output], shell=False)
       run_shell_cmd(
           ['/usr/bin/hdiutil', 'convert', template, '-format', 'UDBZ',
            '-o', output],
           shell=False)

       log.info("cleaning up")
       run_shell_cmd(['/bin/rm', '-rf', install.root], shell=False)




Follow ups