Revision: 28433
          http://sourceforge.net/p/bibdesk/svn/28433
Author:   hofman
Date:     2023-11-11 18:42:20 +0000 (Sat, 11 Nov 2023)
Log Message:
-----------
use python3 procedures for plistlib, file open, and null device

Modified Paths:
--------------
    trunk/bibdesk/build_release.py

Modified: trunk/bibdesk/build_release.py
===================================================================
--- trunk/bibdesk/build_release.py      2023-11-11 15:28:46 UTC (rev 28432)
+++ trunk/bibdesk/build_release.py      2023-11-11 18:42:20 UTC (rev 28433)
@@ -62,8 +62,7 @@
 #
 
 import os, sys, io, getopt
-import codecs
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, DEVNULL
 from stat import ST_SIZE
 import tarfile
 from time import gmtime, strftime, localtime, sleep
@@ -112,7 +111,8 @@
     assert rc == 0, "agvtool bump failed"
     
     # change CFBundleVersion and rewrite the Info.plist
-    infoPlist = plistlib.readPlist(SOURCE_PLIST_PATH)
+    with open(SOURCE_PLIST_PATH, "rb") as plistFile:
+        infoPlist = plistlib.load(plistFile)
     assert infoPlist is not None, "unable to read Info.plist"
     if newVersion == "+":
         oldVersion = infoPlist["CFBundleShortVersionString"].split(".")
@@ -137,16 +137,17 @@
         oldVersion = [str(int(oldVersion[0]) + 1), "0"]
         newVersion = ".".join(oldVersion)
     infoPlist["CFBundleShortVersionString"] = newVersion
-    plistlib.writePlist(infoPlist, SOURCE_PLIST_PATH)
-    helpVersionFile = codecs.open(HELP_VERSION_PATH, "w", "utf-8")
-    helpVersionFile.write("@set VERSION " + newVersion)
-    helpVersionFile.close()
+    with open(SOURCE_PLIST_PATH, "wb") as plistFile:
+        plistlib.dump(infoPlist, plistFille)
+    with open(HELP_VERSION_PATH, "w", "utf-8") as helpVersionFile:
+        helpVersionFile.write("@set VERSION " + newVersion)
     print("version string updated to %s" % (newVersion))
 
 def read_versions():
     
     # read CFBundleVersion, CFBundleShortVersionString, LSMinimumSystemVersion 
and from Info.plist
-    infoPlist = plistlib.readPlist(PLIST_PATH)
+    with open(PLIST_PATH, "rb") as plistFile:
+        infoPlist = plistlib.readPlist(plistFile)
     assert infoPlist is not None, "unable to read Info.plist"
     newVersion = infoPlist["CFBundleVersion"]
     newVersionString = infoPlist["CFBundleShortVersionString"]
@@ -160,7 +161,6 @@
     
     # clean and rebuild the Xcode project
     buildCmd = ["/usr/bin/xcodebuild", "clean", "-configuration", "Release", 
"-target", "BibDesk", "-scheme", "BibDesk", "-destination", 
"generic/platform=macOS", "-derivedDataPath", DERIVED_DATA_DIR, "SYMROOT=" + 
SYMROOT]
-    nullDevice = open("/dev/null", "w")
     x = Popen(buildCmd, cwd=SOURCE_DIR)
     print(" ".join(buildCmd))
     rc = x.wait()
@@ -168,11 +168,9 @@
 
     buildCmd = ["/usr/bin/xcodebuild", "-configuration", "Release", "-target", 
"BibDesk", "-scheme", "BibDesk", "-destination", "generic/platform=macOS", 
"-derivedDataPath", DERIVED_DATA_DIR, "SYMROOT=" + SYMROOT, 
"CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO"]
     print(" ".join(buildCmd))
-    nullDevice = open("/dev/null", "w")
-    x = Popen(buildCmd, cwd=SOURCE_DIR)#, stdout=nullDevice, stderr=nullDevice)
+    x = Popen(buildCmd, cwd=SOURCE_DIR)#, stdout=DEVNULL, stderr=DEVNULL)
     rc = x.wait()
     assert rc == 0, "xcodebuild failed"
-    nullDevice.close()
 
 def codesign(identity):
     
@@ -205,12 +203,10 @@
     if os.path.exists(temp_dmg_path):
         os.unlink(temp_dmg_path)
 
-    nullDevice = open("/dev/null", "w")
-    
     if create_new:
         cmd = ["/usr/bin/hdiutil", "create", "-fs", "HFS+", "-srcfolder", 
BUILT_APP, temp_dmg_path]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         rc = x.wait()
         assert rc == 0, "hdiutil create failed"
     else:
@@ -231,11 +227,9 @@
         # 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", BUILD_ROOT]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         rc = x.wait()
         assert rc == 0, "failed to unzip %s" % (zip_dmg_name)
         
@@ -242,7 +236,7 @@
         # mount image
         cmd = ["/usr/bin/hdiutil", "attach", "-nobrowse", "-noautoopen", 
temp_dmg_path]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         rc = x.wait()
         assert rc == 0, "failed to mount %s" % (temp_dmg_path)
         
@@ -249,7 +243,7 @@
         # use cp to copy all files
         cmd = ["/bin/cp", "-R", BUILT_APP, dst_volume_name]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         rc = x.wait()
         assert rc == 0, "failed to copy %s" % (BUILT_APP)
         
@@ -256,7 +250,7 @@
         # tell finder to set the icon position
         cmd = ["/usr/bin/osascript", "-e", """tell application "Finder" to set 
the position of application file "BibDesk.app" of disk named "BibDesk" to {204, 
148}"""]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         rc = x.wait()
         assert rc == 0, "Finder failed to set position"
         
@@ -264,32 +258,31 @@
         n_tries = 0
         cmd = ["/usr/sbin/diskutil", "eject", dst_volume_name]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         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)
+            x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
             rc = x.wait()
         
         # resize image to fit
         cmd = ["/usr/bin/hdiutil", "resize", temp_dmg_path]
         print(" ".join(cmd))
-        x = Popen(cmd, stdout=PIPE, stderr=nullDevice)
-        size = x.communicate()[0].split(None, 1)[0]
+        x = Popen(cmd, stdout=PIPE, stderr=DEVNULL)
+        size = x.communicate()[0].decode("ascii").split(None, 1)[0]
         cmd = ["/usr/bin/hdiutil", "resize", "-size", size + "b", 
temp_dmg_path]
-        x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+        x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
         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]
     print(" ".join(cmd))
-    x = Popen(cmd, stdout=nullDevice, stderr=nullDevice)
+    x = Popen(cmd, stdout=DEVNULL, stderr=DEVNULL)
     rc = x.wait()
     assert rc == 0, "hdiutil convert failed"
 
-    nullDevice.close()
     os.unlink(temp_dmg_path)
     
     return final_dmg_name
@@ -300,7 +293,6 @@
     # of date, since I sometimes want to upload multiple betas per day.
     final_zip_name = os.path.join(BUILD_DIR, 
os.path.splitext(os.path.basename(BUILT_APP))[0] + "-" + new_version_number + 
".zip")
     
-    nullDevice = open("/dev/null", "w")
     cmd = ["/usr/bin/ditto", "-c", "-k", "--keepParent", BUILT_APP, 
final_zip_name]
     print(" ".join(cmd))
     x = Popen(cmd)
@@ -311,9 +303,8 @@
 
 def release_notes():
     
-    f = codecs.open(RELNOTES_PATH, "r", encoding="utf-8")
-    relNotes = f.read()
-    f.close()
+    with open(RELNOTES_PATH, "r", encoding="utf-8") as f:
+        relNotes = f.read()
     
     changeString = "Changes since "
     endLineString = "\\\n"
@@ -380,8 +371,8 @@
     
     # see 
http://www.entropy.ch/blog/Developer/2008/09/22/Sparkle-Appcast-Automation-in-Xcode.html
     pwtask = Popen(["/usr/bin/security", "find-generic-password", "-g", "-s", 
KEY_NAME], stdout=PIPE, stderr=PIPE)
-    [output, error] = pwtask.communicate()
-    pwoutput = output + error
+    # security returns the password in stderr for some reason
+    pwoutput = pwtask.communicate()[1].decode("utf-8")
     
     # notes are evidently stored as archived RTF data, so find start/end 
markers
     start = pwoutput.find("-----BEGIN DSA PRIVATE KEY-----")
@@ -412,7 +403,7 @@
     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()
+    appcastSignature = b64_task.communicate()[0],decode("ascii").strip()
     fileSize = str(os.stat(archive_path)[ST_SIZE])
     
     return appcastSignature, fileSize
@@ -479,9 +470,8 @@
         appcastName = "bibdesk-" + newVersionString + ".xml"
     
     appcastPath = os.path.join(outputPath , appcastName)
-    appcastFile = codecs.open(appcastPath, "w", "utf-8")
-    appcastFile.write(appcastString)
-    appcastFile.close()
+    with open(appcastPath, "w", "utf-8") as appcastFile:
+        appcastFile.write(appcastString)
     
     # construct the ReadMe file
     readMe = "Release notes for BibDesk version " + newVersionString + "\n"
@@ -498,32 +488,9 @@
     
     # write the ReadMe file
     readMePath = os.path.join(outputPath , "ReadMe-" + newVersionString + 
".txt")
-    readMeFile = codecs.open(readMePath, "w", "utf-8")
-    readMeFile.write(readMe)
-    readMeFile.close()
+    with open(readMePath, "w", "utf-8") as readMeFile:
+        readMeFile.write(readMe)
 
-def user_and_pass_for_upload():
-    
-    pwtask = Popen(["/usr/bin/security", "find-internet-password", "-g", "-s", 
UPLOAD_KEYCHAIN_ITEM, "-t", "dflt"], stdout=PIPE, stderr=PIPE)
-    [output, error] = pwtask.communicate()
-    pwoutput = (output + error).decode("utf-8")
-        
-    username = None
-    password = None
-    for line in pwoutput.split("\n"):
-        line = line.strip()
-        acct_prefix = "\"acct\"<blob>="
-        pw_prefix = "password: "
-        if line.startswith(acct_prefix):
-            assert username == None, "already found username"
-            username = line[len(acct_prefix):].strip("\"")
-        elif line.startswith(pw_prefix):
-            assert password == None, "already found password"
-            password = line[len(pw_prefix):].strip("\"")
-    
-    assert username and password, "unable to find username and password for 
%s" % (UPLOAD_KEYCHAIN_ITEM)
-    return username, password
-
 def get_options():
     
     sign = ""

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to