(self, pkgpath, mounted_sparsebundle)
return package_report
Installs all packages in pkgpath into sparsebundle.
Installs all packages in pkgpath into sparsebundle.
Installs all packages in pkgpath into sparsebundle .
def InstallPackages(self, pkgpath, mounted_sparsebundle):
    """Installs all packages in pkgpath into sparsebundle."""
    package_report = []
    for (path, unused_dirs, files) in os.walk(pkgpath):
      for f in files:
        print 'Installing %s into %s' % (f, mounted_sparsebundle)
        cmd = ['hdiutil', 'attach', os.path.join(path, f)]
        (stdout, stderr, unused_rc) = RunProcess(cmd)
        if stderr:
          package_report.append('Failure mounting %s: %s' % (f, stderr))
        else:
          mountpoint = stdout.split('\n')[-2].split('\t')[-1]
          # If there's any folder in that dmg that looks like a valid app
          # we'll copy it to /Applications
          apps_to_install = []
          for item in os.listdir(mountpoint):
            app_path = os.path.join(mountpoint, item)
            if not os.path.islink(app_path) and app_path.endswith('.app'):
              apps_to_install.append(item)

          if apps_to_install:
            # If we go this route, this is an bundled app
            for app in apps_to_install:
              cmd = ['cp', '-pR', os.path.join(mountpoint, app),
                     os.path.join(mounted_sparsebundle, 'Applications')]
              (stdout, stderr, rc) = RunProcess(cmd)
              if rc == 0:
                print('Successfully copied %s to %s' %
                      (app, mounted_sparsebundle))
                package_report.append('Successfully copied %s to %s' %
                                      (app, mounted_sparsebundle))
              else:
                print('Failed to copy %s to %s due to %s' %
                      (app, mounted_sparsebundle, stderr))
                package_report.append('Failed to copy %s to %s due to %s' %
                                      (app, mounted_sparsebundle, stderr))
                return package_report
          else:
            # This route is for .pkgs
            package = '%s.pkg' % mountpoint.split('/')[-1]
            if not os.path.exists(os.path.join(mountpoint, package)):
              for (unused_packagepath, dirs, content) in os.walk(mountpoint):
                for filename in content:
                  if filename.endswith('.pkg') or filename.endswith('.mpkg'):
                    package = filename
                    print 'Nonstandard package: %s/%s' % (mountpoint, package)
                for dirname in dirs:
                  if dirname.endswith('.pkg') or dirname.endswith('.mpkg'):
                    package = dirname
                    print 'Nonstandard package: %s/%s' % (mountpoint, package)
            cmd = ['installer', '-pkg', os.path.join(mountpoint, package),
                   '-target', mounted_sparsebundle, '-verboseR']
            (stdout, stderr, unused_rc) = RunProcess(cmd)
            if stderr:
              package_report.append('Failure installing %s: %s' % (package,
                                                                   stderr))
            else:
              package_report.append('Success installing %s' % package)
        cmd = ['hdiutil', 'detach', mountpoint]
        (unused_stdout, stderr, unused_rc) = RunProcess(cmd)
        if stderr:
          print 'Failed to unmount dmg: %s' % f

    return package_report
def InstallPackages ( self , pkgpath , mounted_sparsebundle ) : package_report = [ ] for ( path , unused_dirs , files ) in os . walk ( pkgpath ) : for f in files : print 'Installing %s into %s' % ( f , mounted_sparsebundle ) cmd = [ 'hdiutil' , 'attach' , os . path . join ( path , f ) ] ( stdout , stderr , unused_rc ) = RunProcess ( cmd ) if stderr : package_report . append ( 'Failure mounting %s: %s' % ( f , stderr ) ) else : mountpoint = stdout . split ( '\n' ) [ - 2 ] . split ( '\t' ) [ - 1 ] # If there's any folder in that dmg that looks like a valid app # we'll copy it to /Applications apps_to_install = [ ] for item in os . listdir ( mountpoint ) : app_path = os . path . join ( mountpoint , item ) if not os . path . islink ( app_path ) and app_path . endswith ( '.app' ) : apps_to_install . append ( item ) if apps_to_install : # If we go this route, this is an bundled app for app in apps_to_install : cmd = [ 'cp' , '-pR' , os . path . join ( mountpoint , app ) , os . path . join ( mounted_sparsebundle , 'Applications' ) ] ( stdout , stderr , rc ) = RunProcess ( cmd ) if rc == 0 : print ( 'Successfully copied %s to %s' % ( app , mounted_sparsebundle ) ) package_report . append ( 'Successfully copied %s to %s' % ( app , mounted_sparsebundle ) ) else : print ( 'Failed to copy %s to %s due to %s' % ( app , mounted_sparsebundle , stderr ) ) package_report . append ( 'Failed to copy %s to %s due to %s' % ( app , mounted_sparsebundle , stderr ) ) return package_report else : # This route is for .pkgs package = '%s.pkg' % mountpoint . split ( '/' ) [ - 1 ] if not os . path . exists ( os . path . join ( mountpoint , package ) ) : for ( unused_packagepath , dirs , content ) in os . walk ( mountpoint ) : for filename in content : if filename . endswith ( '.pkg' ) or filename . endswith ( '.mpkg' ) : package = filename print 'Nonstandard package: %s/%s' % ( mountpoint , package ) for dirname in dirs : if dirname . endswith ( '.pkg' ) or dirname . endswith ( '.mpkg' ) : package = dirname print 'Nonstandard package: %s/%s' % ( mountpoint , package ) cmd = [ 'installer' , '-pkg' , os . path . join ( mountpoint , package ) , '-target' , mounted_sparsebundle , '-verboseR' ] ( stdout , stderr , unused_rc ) = RunProcess ( cmd ) if stderr : package_report . append ( 'Failure installing %s: %s' % ( package , stderr ) ) else : package_report . append ( 'Success installing %s' % package ) cmd = [ 'hdiutil' , 'detach' , mountpoint ] ( unused_stdout , stderr , unused_rc ) = RunProcess ( cmd ) if stderr : print 'Failed to unmount dmg: %s' % f return package_report