#!/usr/bin/env pythonimport sys, os, plist, shutil, tempfile, subprocessdef _decode(value, encoding="utf-8", errors="ignore"):# Helper method to only decode if bytes typeif sys.version_info >= (3,0) and isinstance(value, bytes):return value.decode(encoding,errors)return valuedef main():# Let's check for an existing app - remove it if it exists,# then create and format a new bundletemp = Noneprint("Getting python 2 path...")p = subprocess.Popen(["which","python"], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)c = p.communicate()pypath = _decode(c[0]).split("\n")[0]if not len(pypath):print(" - Python not found in PATH! Aborting...")exit(1)print(" - {} ".format(pypath))print("Checking for existing ProperTree.app...")os.chdir(os.path.dirname(os.path.realpath(__file__)))os.chdir("../")if os.path.exists("ProperTree.app"):print(" - Found, removing...")if os.path.exists("ProperTree.app/Contents/MacOS/Scripts/settings.json"):print(" --> Found settings.json - preserving...")temp = tempfile.mkdtemp()shutil.copy("ProperTree.app/Contents/MacOS/Scripts/settings.json", os.path.join(temp, "settings.json"))shutil.rmtree("ProperTree.app")# Make the directory structureprint("Creating bundle structure...")os.makedirs("ProperTree.app/Contents/MacOS/Scripts")os.makedirs("ProperTree.app/Contents/Resources")print("Copying scripts...")print(" - ProperTree.command")with open("ProperTree.command","r") as f:ptcom = f.read().split("\n")if ptcom[0].startswith("#!"):# Got a shebang - remove itptcom.pop(0)# Set the new shebangptcom.insert(0,"#!{}".format(pypath))with open("ProperTree.app/Contents/MacOS/ProperTree.command","w") as f:f.write("\n".join(ptcom))# chmod +xp = subprocess.Popen(["chmod","+x","ProperTree.app/Contents/MacOS/ProperTree.command"], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)c = p.communicate()# Copy everything elsefor x in os.listdir("Scripts"):if x.startswith(".") or not x.lower().endswith((".py",".plist",".icns")):continueprint(" - "+x)target = "ProperTree.app/Contents/Resources" if x.lower().endswith(".icns") else "ProperTree.app/Contents/MacOS/Scripts"shutil.copy(os.path.join("Scripts",x),target)print("Building Info.plist...")info = {"CFBundleShortVersionString": "0.0","CFBundleSignature": "????","CFBundleInfoDictionaryVersion": "0.0","CFBundleIconFile": "icon","NSHumanReadableCopyright": "Copyright 2019 CorpNewt","CFBundleIconFile": "shortcut.icns","CFBundleIdentifier": "com.corpnewt.ProperTree","CFBundleDocumentTypes": [{"CFBundleTypeName": "Property List","CFBundleTypeRole": "Viewer","CFBundleTypeIconFile": "plist","CFBundleTypeExtensions": ["plist"]}],"CFBundleDevelopmentRegion": "English","CFBundleExecutable": "ProperTree.command","CFBundleName": "ProperTree","LSMinimumSystemVersion": "10.4","LSMultipleInstancesProhibited": True,"CFBundlePackageType": "APPL","CFBundleVersion": "0.0"}with open("ProperTree.app/Contents/Info.plist","wb") as f:plist.dump(info,f)if temp:print("Restoring settings.json...")shutil.copy(os.path.join(temp, "settings.json"),"ProperTree.app/Contents/MacOS/Scripts/settings.json")shutil.rmtree(temp,ignore_errors=True)if __name__ == '__main__':if not str(sys.platform) == "darwin":print("Can only be run on macOS")exit(1)try:main()except Exception as e:print("An error occurred!")print(str(e))exit(1)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。