Revision: 12242
http://sourceforge.net/p/skim-app/code/12242
Author: hofman
Date: 2021-04-04 21:37:03 +0000 (Sun, 04 Apr 2021)
Log Message:
-----------
Combine functions to create dmg
Modified Paths:
--------------
trunk/build_skim.py
Modified: trunk/build_skim.py
===================================================================
--- trunk/build_skim.py 2021-04-04 15:36:59 UTC (rev 12241)
+++ trunk/build_skim.py 2021-04-04 21:37:03 UTC (rev 12242)
@@ -181,7 +181,7 @@
break
-def create_dmg_of_application(new_version_number):
+def create_dmg_of_application(new_version_number, create_new):
# Create a name for the dmg based on version number, instead
# of date, since I sometimes want to upload multiple betas per day.
@@ -188,108 +188,89 @@
final_dmg_name = os.path.join(BUILD_DIR,
os.path.splitext(os.path.basename(BUILT_APP))[0] + "-" + new_version_number +
".dmg")
temp_dmg_path = os.path.join(BUILD_DIR, "Skim.dmg")
+ # remove temp image from a previous run
if os.path.exists(temp_dmg_path):
os.unlink(temp_dmg_path)
nullDevice = open("/dev/null", "w")
- cmd = ["/usr/bin/hdiutil", "create", "-fs", "HFS+", "-srcfolder",
BUILT_APP, temp_dmg_path]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "hdiutil create failed"
- cmd = ["/usr/bin/hdiutil", "convert", temp_dmg_path, "-format", "UDZO",
"-imagekey", "zlib-level=9", "-o", final_dmg_name]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "hdiutil convert failed"
-
- nullDevice.close()
- os.unlink(temp_dmg_path)
-
- return final_dmg_name
-
-def create_prepared_dmg_of_application(new_version_number):
-
- # Create a name for the dmg based on version number, instead
- # of date, since I sometimes want to upload multiple betas per day.
- final_dmg_name = os.path.join(BUILD_DIR,
os.path.splitext(os.path.basename(BUILT_APP))[0] + "-" + new_version_number +
".dmg")
-
- # template image in source folder
- zip_dmg_name = os.path.join(SOURCE_DIR, "Skim.dmg.zip")
-
- # temporary image
- temp_dmg_path = os.path.join(BUILD_DIR, "Skim.dmg")
-
- # temporary volume
- dst_volume_name = "/Volumes/Skim"
-
- # see if this file already exists and bail
- assert not os.path.exists(final_dmg_name), "%s exists" % (final_dmg_name)
-
- # see if a volume is already mounted or a
- # previous cp operation was botched
- assert not os.path.exists(dst_volume_name), "%s exists" % (dst_volume_name)
-
- # remove temp image from a previous run
- if os.path.exists(temp_dmg_path):
- unlink(temp_dmg_path)
-
- # stored zipped in svn, so unzip if needed
- # pass o to overwrite, or unzip waits for stdin
- # when trying to unpack the resource fork/EA
-
- nullDevice = open("/dev/null", "w")
- cmd = ["/usr/bin/unzip", "-uo", zip_dmg_name, "-d", "/tmp"]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "failed to unzip %s" % (zip_dmg_name)
-
- # mount image
- cmd = ["/usr/bin/hdiutil", "attach", "-nobrowse", "-noautoopen",
temp_dmg_path]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "failed to mount %s" % (temp_dmg_path)
-
- # use cp to copy all files
- cmd = ["/bin/cp", "-R", BUILT_APP, dst_volume_name]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "failed to copy %s" % (BUILT_APP)
-
- # tell finder to set the icon position
- cmd = ["/usr/bin/osascript", "-e", """tell application "Finder" to set the
position of application file "Skim.app" of disk named "Skim" to {90, 206}"""]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- assert rc == 0, "Finder failed to set position"
-
- # data is copied, so unmount the volume, we may need to wait when the
volume is in use
- n_tries = 0
- cmd = ["/usr/sbin/diskutil", "eject", dst_volume_name]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- rc = x.wait()
- while rc != 0:
- assert n_tries < 12, "failed to eject %s" % (dst_volume_name)
- n_tries += 1
- sleep(5)
+ if create_new:
+ cmd = ["/usr/bin/hdiutil", "create", "-fs", "HFS+", "-srcfolder",
BUILT_APP, temp_dmg_path]
x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
rc = x.wait()
+ assert rc == 0, "hdiutil create failed"
+ else:
+ # template image in source folder
+ zip_dmg_name = os.path.join(SOURCE_DIR, "Skim.dmg.zip")
+
+ # temporary volume
+ dst_volume_name = "/Volumes/Skim"
+
+ # see if this file already exists and bail
+ assert not os.path.exists(final_dmg_name), "%s exists" %
(final_dmg_name)
+
+ # see if a volume is already mounted or a
+ # previous cp operation was botched
+ assert not os.path.exists(dst_volume_name), "%s exists" %
(dst_volume_name)
+
+ # stored zipped in svn, so unzip if needed
+ # pass o to overwrite, or unzip waits for stdin
+ # when trying to unpack the resource fork/EA
+
+ nullDevice = open("/dev/null", "w")
+ cmd = ["/usr/bin/unzip", "-uo", zip_dmg_name, "-d", "/tmp"]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+ assert rc == 0, "failed to unzip %s" % (zip_dmg_name)
+
+ # mount image
+ cmd = ["/usr/bin/hdiutil", "attach", "-nobrowse", "-noautoopen",
temp_dmg_path]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+ assert rc == 0, "failed to mount %s" % (temp_dmg_path)
+
+ # use cp to copy all files
+ cmd = ["/bin/cp", "-R", BUILT_APP, dst_volume_name]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+ assert rc == 0, "failed to copy %s" % (BUILT_APP)
+
+ # tell finder to set the icon position
+ cmd = ["/usr/bin/osascript", "-e", """tell application "Finder" to set
the position of application file "Skim.app" of disk named "Skim" to {90,
206}"""]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+ assert rc == 0, "Finder failed to set position"
+
+ # data is copied, so unmount the volume, we may need to wait when the
volume is in use
+ n_tries = 0
+ cmd = ["/usr/sbin/diskutil", "eject", dst_volume_name]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+ while rc != 0:
+ assert n_tries < 12, "failed to eject %s" % (dst_volume_name)
+ n_tries += 1
+ sleep(5)
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ rc = x.wait()
+
+ # resize image to fit
+ cmd = ["/usr/bin/hdiutil", "resize", temp_dmg_path]
+ x = Popen(cmd, stdout=PIPE, stderr=nullDevice)
+ size = x.communicate()[0].split(None, 1)[0]
+ cmd = ["/usr/bin/hdiutil", "resize", "-size", size + "b",
temp_dmg_path]
+ x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+ assert rc == 0, "failed to resize %s" % (temp_dmg_path)
- # resize image to fit
- cmd = ["/usr/bin/hdiutil", "resize", temp_dmg_path]
- x = Popen(cmd, stdout=PIPE, stderr=nullDevice)
- size = x.communicate()[0].split(None, 1)[0]
- cmd = ["/usr/bin/hdiutil", "resize", "-size", size + "b", temp_dmg_path]
- x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
- assert rc == 0, "failed to resize %s" % (temp_dmg_path)
-
# convert image to read only and compress
cmd = ["/usr/bin/hdiutil", "convert", temp_dmg_path, "-format", "UDZO",
"-imagekey", "zlib-level=9", "-o", final_dmg_name]
x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
rc = x.wait()
- assert rc == 0, "failed to convert %s" % (temp_dmg_path)
+ assert rc == 0, "hdiutil convert failed"
- # remove temp image
nullDevice.close()
os.unlink(temp_dmg_path)
+
+ return final_dmg_name
def create_zip_of_application(new_version_number):
@@ -327,7 +308,7 @@
return key
-def signature_and_size(dmg_or_zip_path):
+def signature_and_size(archive_path):
# write to a temporary file that's readably only by owner; minor security
issue here since
# we have to use a named temp file, but it's better than storing
unencrypted key
@@ -336,22 +317,22 @@
keyFile.flush()
# now run the signature for Sparkle...
- sha_task = Popen(["/usr/bin/openssl", "dgst", "-sha1", "-binary"],
stdin=open(dmg_or_zip_path, "rb"), stdout=PIPE)
+ sha_task = Popen(["/usr/bin/openssl", "dgst", "-sha1", "-binary"],
stdin=open(archive_path, "rb"), stdout=PIPE)
dss_task = Popen(["/usr/bin/openssl", "dgst", "-dss1", "-sign",
keyFile.name], stdin=sha_task.stdout, stdout=PIPE)
b64_task = Popen(["/usr/bin/openssl", "enc", "-base64"],
stdin=dss_task.stdout, stdout=PIPE)
# now compute the variables we need for writing the new appcast
appcastSignature = b64_task.communicate()[0].strip()
- fileSize = str(os.stat(dmg_or_zip_path)[ST_SIZE])
+ fileSize = str(os.stat(archive_path)[ST_SIZE])
return appcastSignature, fileSize
-def write_appcast(newVersion, newVersionString, minimumSystemVersion,
dmg_or_zip_path, outputPath):
+def write_appcast(newVersion, newVersionString, minimumSystemVersion,
archive_path, outputPath):
- appcastSignature, fileSize = signature_and_size(dmg_or_zip_path)
- download_url = "https://sourceforge.net/projects/skim/files/Skim/Skim-" +
newVersionString + "/" + os.path.basename(dmg_or_zip_path) + "/download"
+ appcastSignature, fileSize = signature_and_size(archive_path)
+ download_url = "https://sourceforge.net/projects/skim/files/Skim/Skim-" +
newVersionString + "/" + os.path.basename(archive_path) + "/download"
appcastDate = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
- if dmg_or_zip_path.endswith("dmg"):
+ if archive_path.endswith("dmg"):
type = "application/x-apple-diskimage"
else:
type = "application/zip"
@@ -467,15 +448,15 @@
new_version, new_version_string, minimum_system_version = read_versions()
- dmg_or_zip_path = create_zip_of_application(new_version_string)
+ archive_path = create_zip_of_application(new_version_string)
# will bail if any part fails
if username != "":
- notarize_dmg_or_zip(dmg_or_zip_path, username, password)
+ notarize_dmg_or_zip(archive_path, username, password)
- if dmg_or_zip_path.endswith("dmg"):
+ if archive_path.endswith("dmg"):
# xcrun stapler staple Skim.app-1.4.dmg
- x = Popen(["xcrun", "stapler", "staple", dmg_or_zip_path])
+ x = Popen(["xcrun", "stapler", "staple", archive_path])
rc = x.wait()
assert rc == 0, "stapler failed"
else:
@@ -485,8 +466,8 @@
x = Popen(["xcrun", "stapler", "staple", BUILT_APP])
rc = x.wait()
assert rc == 0, "stapler failed"
- os.unlink(dmg_or_zip_path)
- dmg_or_zip_path = create_zip_of_application(new_version_string)
+ os.unlink(archive_path)
+ archive_path = create_zip_of_application(new_version_string)
try:
# probably already exists
@@ -494,9 +475,9 @@
except Exception as e:
assert os.path.isdir(out), "%s does not exist" % (out)
- write_appcast(new_version, new_version_string, minimum_system_version,
dmg_or_zip_path, out)
+ write_appcast(new_version, new_version_string, minimum_system_version,
archive_path, out)
- target_path = os.path.join(out, os.path.basename(dmg_or_zip_path))
+ target_path = os.path.join(out, os.path.basename(archive_path))
if (os.path.exists(target_path)):
os.unlink(target_path)
- os.rename(dmg_or_zip_path, target_path)
+ os.rename(archive_path, target_path)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit