Skip to content

Commit

Permalink
Merge branch 'yosemite'
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Olofsson authored and Per Olofsson committed Oct 16, 2014
2 parents 38d4a28 + 0b38daf commit 7d9651d
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 219 deletions.
16 changes: 5 additions & 11 deletions AutoDMG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
0506B97C17F0849C0011CCC2 /* AutoDMG.iconset in Resources */ = {isa = PBXBuildFile; fileRef = 0506B97B17F0849C0011CCC2 /* AutoDMG.iconset */; };
051626A618E2D1BE000288D1 /* IEDMountInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 051626A518E2D1BE000288D1 /* IEDMountInfo.m */; };
051B177117F446560026E12B /* progresswatcher.py in Resources */ = {isa = PBXBuildFile; fileRef = 051B177017F446560026E12B /* progresswatcher.py */; };
05429D761816715300CD61E6 /* Package blue arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 05429D721816715300CD61E6 /* Package blue arrow.png */; };
05429D771816715300CD61E6 /* Package blue [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 05429D731816715300CD61E6 /* Package blue [email protected] */; };
Expand Down Expand Up @@ -54,8 +53,6 @@

/* Begin PBXFileReference section */
0506B97B17F0849C0011CCC2 /* AutoDMG.iconset */ = {isa = PBXFileReference; lastKnownFileType = folder.iconset; path = AutoDMG.iconset; sourceTree = "<group>"; };
051626A418E2D1BE000288D1 /* IEDMountInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IEDMountInfo.h; sourceTree = "<group>"; };
051626A518E2D1BE000288D1 /* IEDMountInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IEDMountInfo.m; sourceTree = "<group>"; };
051B177017F446560026E12B /* progresswatcher.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = progresswatcher.py; sourceTree = "<group>"; };
05429D721816715300CD61E6 /* Package blue arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Package blue arrow.png"; sourceTree = "<group>"; };
05429D731816715300CD61E6 /* Package blue [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Package blue [email protected]"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -172,8 +169,6 @@
children = (
66EA72DA17EB1586009B8350 /* main.m */,
66EA72DC17EB1587009B8350 /* AutoDMG-Prefix.pch */,
051626A418E2D1BE000288D1 /* IEDMountInfo.h */,
051626A518E2D1BE000288D1 /* IEDMountInfo.m */,
);
name = ObjC;
sourceTree = "<group>";
Expand Down Expand Up @@ -284,7 +279,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = IED;
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = "University of Gothenburg";
TargetAttributes = {
66EA72C817EB1585009B8350 = {
Expand Down Expand Up @@ -408,7 +403,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
051626A618E2D1BE000288D1 /* IEDMountInfo.m in Sources */,
66EA72DB17EB1586009B8350 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -477,7 +471,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx10.8;
SDKROOT = macosx;
};
name = Debug;
};
Expand Down Expand Up @@ -509,7 +503,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.8;
SDKROOT = macosx10.8;
SDKROOT = macosx;
};
name = Release;
};
Expand All @@ -521,7 +515,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "AutoDMG/AutoDMG-Prefix.pch";
INFOPLIST_FILE = "AutoDMG/AutoDMG-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_NAME = AutoDMG;
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = app;
Expand All @@ -536,7 +530,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "AutoDMG/AutoDMG-Prefix.pch";
INFOPLIST_FILE = "AutoDMG/AutoDMG-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
MACOSX_DEPLOYMENT_TARGET = 10.8;
PRODUCT_NAME = AutoDMG;
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = app;
Expand Down
4 changes: 2 additions & 2 deletions AutoDMG.xcodeproj/xcshareddata/xcschemes/AutoDMG.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
LastUpgradeVersion = "0600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -87,7 +87,7 @@
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "#!/bin/bash&#10;&#10;&#10;exec &gt; &quot;/tmp/$PRODUCT_NAME-archive.log&quot; 2&gt;&amp;1&#10;&#10;declare -r DIST_ID=&quot;Developer ID Application: University of Gothenburg&quot;&#10;&#10;export PATH=&quot;${PATH}:$HOME/Dropbox/bin&quot;&#10;&#10;&#10;while read -r v; do&#10;echo &quot; export $v&quot;&#10;done &lt; &lt;(env | sort)&#10;&#10;appdir=&quot;$ARCHIVE_PRODUCTS_PATH/$INSTALL_PATH&quot;&#10;&#10;version=$(/usr/libexec/PlistBuddy -c &quot;Print :CFBundleShortVersionString&quot; &quot;$appdir/$INFOPLIST_PATH&quot;)&#10;if [[ &quot;$version&quot; == *b ]]; then&#10;version=&quot;$version$(/usr/libexec/PlistBuddy -c &quot;Print :CFBundleVersion&quot; &quot;$appdir/$INFOPLIST_PATH&quot;)&quot;&#10;fi&#10;&#10;distdir=&quot;$PROJECT_DIR/Distributions&quot;&#10;releasedir=&quot;$distdir/$PRODUCT_NAME-$version&quot;&#10;dmgpath=&quot;$releasedir.dmg&quot;&#10;&#10;rm -rf &quot;$releasedir&quot; &quot;$dmgpath&quot;&#10;&#10;echo &quot;Creating $releasedir&quot;&#10;mkdir -p &quot;$releasedir&quot;&#10;open -R &quot;$releasedir&quot;&#10;&#10;echo &quot;Copying $appdir/$FULL_PRODUCT_NAME&quot;&#10;ditto &quot;$appdir/$FULL_PRODUCT_NAME&quot; &quot;$releasedir/$FULL_PRODUCT_NAME&quot;&#10;&#10;echo &quot;Signing app as $DIST_ID&quot;&#10;codesign -f -vv -s &quot;$DIST_ID&quot; &quot;$releasedir/$FULL_PRODUCT_NAME&quot; || exit 1&#10;&#10;echo &quot;Creating $releasedir/$PRODUCT_NAME.html&quot;&#10;markdown &quot;$PROJECT_DIR/README.markdown&quot; | cat &quot;$PROJECT_DIR/README.css&quot; - | tidy -q -i &gt; &quot;$releasedir/$PRODUCT_NAME.html&quot; 2&gt;/dev/null&#10;&#10;echo &quot;Creating $dmgpath&quot;&#10;hdiutil create -srcfolder &quot;$releasedir&quot; -ov &quot;$dmgpath&quot;&#10;&#10;open -R &quot;$dmgpath&quot;&#10;&#10;&#10;exit 0&#10;"
scriptText = "#!/bin/bash&#10;&#10;&#10;exec &gt; &quot;/tmp/$PRODUCT_NAME-archive.log&quot; 2&gt;&amp;1&#10;&#10;declare -r DIST_ID=&quot;Developer ID Application: University of Gothenburg&quot;&#10;&#10;export PATH=&quot;${PATH}:$HOME/Dropbox/bin:$HOME/Dropbox/.gem/bin&quot;&#10;export GEM_HOME=&quot;$HOME/Dropbox/.gem&quot;&#10;&#10;echo &quot;# Environment:&quot;&#10;while read -r v; do&#10;echo &quot; export $v&quot;&#10;done &lt; &lt;(env | sort)&#10;&#10;appdir=&quot;$ARCHIVE_PRODUCTS_PATH/$INSTALL_PATH&quot;&#10;&#10;version=$(/usr/libexec/PlistBuddy -c &quot;Print :CFBundleShortVersionString&quot; &quot;$appdir/$INFOPLIST_PATH&quot;)&#10;if [[ &quot;$version&quot; == *b ]]; then&#10; version=&quot;$version$(/usr/libexec/PlistBuddy -c &quot;Print :CFBundleVersion&quot; &quot;$appdir/$INFOPLIST_PATH&quot;)&quot;&#10;fi&#10;echo &quot;# Archiving $PRODUCT_NAME version $version&quot;&#10;&#10;distdir=&quot;$PROJECT_DIR/Distributions&quot;&#10;releasedir=&quot;$distdir/$PRODUCT_NAME-$version&quot;&#10;dmgpath=&quot;$releasedir.dmg&quot;&#10;&#10;rm -rf &quot;$releasedir&quot; &quot;$dmgpath&quot;&#10;&#10;echo &quot;# Creating $releasedir&quot;&#10;mkdir -p &quot;$releasedir&quot;&#10;open -R &quot;$releasedir&quot;&#10;&#10;echo &quot;# Copying $appdir/$FULL_PRODUCT_NAME&quot;&#10;ditto &quot;$appdir/$FULL_PRODUCT_NAME&quot; &quot;$releasedir/$FULL_PRODUCT_NAME&quot;&#10;&#10;echo &quot;# Signing app as $DIST_ID&quot;&#10;codesign -f -vv -s &quot;$DIST_ID&quot; &quot;$releasedir/$FULL_PRODUCT_NAME&quot; || exit 1&#10;&#10;echo &quot;# Creating $releasedir/$PRODUCT_NAME.html&quot;&#10;kramdown &quot;$PROJECT_DIR/README.markdown&quot; | cat &quot;$PROJECT_DIR/README.css&quot; - | tidy -q -i &gt; &quot;$releasedir/$PRODUCT_NAME.html&quot; 2&gt;/dev/null&#10;&#10;echo &quot;# Creating $dmgpath&quot;&#10;hdiutil create -srcfolder &quot;$releasedir&quot; -ov &quot;$dmgpath&quot;&#10;&#10;open -R &quot;$dmgpath&quot;&#10;&#10;&#10;exit 0&#10;"
shellToInvoke = "/bin/bash">
<EnvironmentBuildable>
<BuildableReference
Expand Down
2 changes: 1 addition & 1 deletion AutoDMG/AutoDMG-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.4</string>
<string>1.5b</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
15 changes: 0 additions & 15 deletions AutoDMG/IEDMountInfo.h

This file was deleted.

38 changes: 0 additions & 38 deletions AutoDMG/IEDMountInfo.m

This file was deleted.

137 changes: 111 additions & 26 deletions AutoDMG/IEDUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
import subprocess
import tempfile
import shutil
from xml.etree import ElementTree
from IEDLog import LogDebug, LogInfo, LogNotice, LogWarning, LogError, LogMessage
try:
IEDMountInfo = objc.lookUpClass(u"IEDMountInfo")
except objc.nosuchclass_error:
# Create a dummy class to allow import from pure python for testing. Will
# crash when an attempt is made to use the class.
class IEDMountInfo(object):
pass


class IEDUtil(NSObject):
Expand Down Expand Up @@ -100,10 +94,26 @@ def findMountPoint_(cls, path):
@classmethod
def getInstalledPkgSize_(cls, pkgPath):
# For apps just return the size on disk.
name, ext = os.path.splitext(pkgPath)
ext = os.path.splitext(pkgPath)[1].lower()
if ext == u".app":
return cls.getPackageSize_(pkgPath)
# For packages try to get the size requirements with installer.
elif ext in (u".pkg", u".mpkg"):
# For packages first try to get the size requirements with
# installer.
size = cls.getInstalledPkgSizeFromInstaller_(pkgPath)
if size is None:
# If this fails, manually extract the size requirements from
# the package.
return cls.calculateInstalledPkgSize_(pkgPath)
else:
return size
else:
LogError(u"Don't know how to calculate installed size for '%s'",
pkgPath)
return None

@classmethod
def getInstalledPkgSizeFromInstaller_(cls, pkgPath):
pkgFileName = os.path.os.path.basename(pkgPath)
tempdir = tempfile.mkdtemp()
try:
Expand All @@ -123,22 +133,9 @@ def getInstalledPkgSize_(cls, pkgPath):
shutil.rmtree(tempdir)
except BaseException as e:
LogWarning(u"Unable to remove tempdir: %@", unicode(e))
# Try to handle some common scenarios when installer fails.
if p.returncode == -11:
LogWarning(u"Estimating package size since installer -pkginfo "
u"'%@' crashed", pkgPath)
return cls.getPackageSize_(pkgPath) * 2
elif p.returncode != 0:
mountPoints = IEDMountInfo.getMountPoints()
fsInfo = mountPoints[cls.findMountPoint_(pkgPath)]
if not fsInfo[u"islocal"]:
LogWarning(u"Estimating package size since installer -pkginfo "
u"failed and '%@' is on a remote (%@) filesystem",
pkgPath, fsInfo[u"fstypename"])
return cls.getPackageSize_(pkgPath) * 2
else:
LogError(u"installer -pkginfo -pkg '%@' failed with exit code %d", pkgPath, p.returncode)
return None
if p.returncode != 0:
LogDebug(u"/usr/sbin/installer failed to determine size requirements")
return None
outData = NSData.dataWithBytes_length_(out, len(out))
plist, format, error = NSPropertyListSerialization.propertyListWithData_options_format_error_(outData,
NSPropertyListImmutable,
Expand All @@ -147,5 +144,93 @@ def getInstalledPkgSize_(cls, pkgPath):
if not plist:
LogError(u"Error decoding plist: %@", error)
return None
LogDebug(u"%@ requires %@", pkgPath, cls.formatBytes_(int(plist[u"Size"]) * 1024))
LogDebug(u"Installer says %@ requires %@", pkgPath, cls.formatBytes_(int(plist[u"Size"]) * 1024))
return int(plist[u"Size"]) * 1024

@classmethod
def calculateInstalledPkgSize_(cls, pkgPath):
if os.path.isdir(pkgPath):
size = cls.getBundlePkgInfo_(pkgPath)
else:
size = cls.getFlatPkgInfo_(pkgPath)
if size is None:
# If all else fails, estimate package size requirements.
LogWarning(u"Estimating package size for '%@'", pkgPath)
size = cls.getPackageSize_(pkgPath) * 2
LogDebug(u"%@ needs %@", pkgPath, cls.formatBytes_(size))
return size

@classmethod
def getBundlePkgInfo_(cls, pkgPath):
distPath = os.path.join(pkgPath, u"Contents", u"distribution.dist")
infoPlistPath = os.path.join(pkgPath, u"Contents", u"Info.plist")
if os.path.exists(distPath):
return cls.getSizeFromDistribution_(distPath)
elif os.path.exists(infoPlistPath):
return cls.getSizeFromPkgInfoPlist_(infoPlistPath)
else:
LogError(u"No distribution.dist or Info.plist found in '%@'", pkgPath)
return None

@classmethod
def getFlatPkgInfo_(cls, pkgPath):
tempdir = tempfile.mkdtemp()
try:
# Extract to tempdir, excluding all except Distribution and
# PackageInfo.
subprocess.check_output([u"/usr/bin/xar",
u"-x",
u"--exclude", u"^[^DP]",
u"--exclude", u"Payload",
u"-C", tempdir,
u"-f", pkgPath])
distPath = os.path.join(tempdir, u"Distribution")
pkgInfoPath = os.path.join(tempdir, u"PackageInfo")
if os.path.exists(distPath):
return cls.getSizeFromDistribution_(distPath)
elif os.path.exists(pkgInfoPath):
return cls.getSizeFromPackageInfo_(pkgInfoPath)
else:
LogError(u"No Distribution or PackageInfo found in '%@'", pkgPath)
return None
except subprocess.CalledProcessError as e:
LogError(u"xar failed with return code %d", e.returncode)
return None
finally:
try:
shutil.rmtree(tempdir)
except Exception as e:
LogWarning(u"Unable to remove tempdir: %@", unicode(e))

@classmethod
def getSizeFromDistribution_(cls, distPath):
kbytes = 0
try:
tree = ElementTree.parse(distPath)
for pkgref in tree.iterfind(u"pkg-ref[@installKBytes]"):
kbytes += int(pkgref.get(u"installKBytes"))
except Exception as e:
LogError(u"Failed parsing '%@': %@", distPath, unicode(e))
return None
return kbytes * 1024

@classmethod
def getSizeFromPackageInfo_(cls, pkgInfoPath):
kbytes = 0
try:
tree = ElementTree.parse(pkgInfoPath)
for payload in tree.iterfind(u"payload[@installKBytes]"):
kbytes += int(payload.get(u"installKBytes"))
except Exception as e:
LogError(u"Failed parsing '%@': %@", pkgInfoPath, unicode(e))
return None
return kbytes * 1024

@classmethod
def getSizeFromPkgInfoPlist_(cls, infoPlistPath):
try:
infoDict = NSDictionary.dictionaryWithContentsOfFile_(infoPlistPath)
return infoDict[u"IFPkgFlagInstalledSize"] * 1024
except Exception as e:
LogError(u"Failed parsing '%@': %@", infoPlistPath, unicode(e))
return None
Binary file modified AutoDMG/Installer Placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7d9651d

Please sign in to comment.