Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/pyhton
- #created by: hamdullahshah@gmail.com
- #modified by: mozgoid@gmail.com
- import os, getopt, sys
- import subprocess
- import plistlib as PlistParser
- options = {
- "appPath" : "/Users/user/Desktop/MyApp.app",
- "entitlements" : "/Users/user/Desktop/entitlements.plist",
- "signingProfileName" : "3rd Party Mac Developer Application: MyCompany (QWERTYU)",
- "signingInstallerProfileName" : "",
- "AppPackageName" : "myApp.pkg",
- "bundleStringinfoValue" : "Kids Learning Program 1.1.0. (c) 2014 MyCompany Inc. All rights reserved.",
- "bundleVersionStringValue" : "1.1.0",
- "bundleVersionNumberValue" : "1.1.0",
- "bundleIdentifierValue" : "com.company.MyApp",
- "bundleNameValue" : "MyApp",
- "ApplicationCategoryValue" : "public.app-category.strategy-games",
- "ReadableCopyRightValue" : "MyCompany v1.0.0 (c) MyCompany, Inc.",
- }
- def removeMetaFilesFromDirectiory(dirPath):
- fileslist = []
- for root, dirs, files in os.walk(dirPath):
- for file in files:
- if file.endswith('.meta'):
- metaFilePath = root + '/' + file
- fileslist.append(metaFilePath)
- for filePath in fileslist:
- print 'deleting file: ', filePath
- os.remove(filePath)
- def signPlugins():
- pluginsPath = options['appPath'] + '/Contents/Plugins'
- if os.path.exists(pluginsPath):
- for plugin in os.listdir(pluginsPath):
- p = pluginsPath + '/' + plugin
- removeMetaFilesFromDirectiory(p)
- executeCodeSign(p)
- def UpdateInfoPlist():
- plistPath = options['appPath'] + "/Contents/Info.plist"
- allData = PlistParser.readPlist(plistPath)
- allData["CFBundleGetInfoString"] = options['bundleStringinfoValue']
- allData["CFBundleShortVersionString"] = options['bundleVersionStringValue']
- allData["CFBundleVersion"] = options['bundleVersionNumberValue']
- allData["CFBundleIdentifier"] = options['bundleIdentifierValue']
- allData["CFBundleName"] = options['bundleNameValue']
- allData["LSApplicationCategoryType"] = options['ApplicationCategoryValue']
- allData["NSHumanReadableCopyright"] = options['ReadableCopyRightValue']
- PlistParser.writePlist(allData, plistPath)
- def executeCodeSign(pathToTargetSign):
- codesignPlugin = subprocess.call(["codesign", "--deep", "-f", "-v", "-s"
- , options['signingProfileName']
- , "--entitlements"
- , options['entitlements']
- , pathToTargetSign])
- if codesignPlugin == 0:
- print '\nSigning Completed of ', pathToTargetSign
- return True
- else:
- print subprocess.CalledProcessError
- return False
- def AppSigning():
- print "\n\n**********Signing App for Mac AppStore with \"", options['signingProfileName'], "\" ************"
- codesignOutput = subprocess.call(["codesign", "--deep", "-f", "-v", "-s",
- options['signingProfileName'],
- "--entitlements",
- options['entitlements'],
- options['appPath']])
- if codesignOutput == 0:
- print '\n\nSigning Completed'
- return True
- else:
- print subprocess.CalledProcessError
- return False
- def PackageCreation():
- if len(options['AppPackageName']) == 0:
- print "won't create package"
- return
- if len(options['signingInstallerProfileName']) == 0:
- print '\n\nCreating Package without installer signing.'
- installerOutPut = subprocess.call(["productbuild", "--component",
- options['appPath'], "/Applications",
- options['AppPackageName']])
- if installerOutPut == 0:
- print '\n\nPackage Created'
- else:
- print subprocess.CalledProcessError
- else:
- print '\n\nCreating Package with ',options['signingInstallerProfileName'], ' installer signing.'
- installerOutPut = subprocess.call(["productbuild", "--component",
- options['appPath'],
- "/Applications",
- "--sign",
- options['signingInstallerProfileName'],
- options['AppPackageName']])
- if installerOutPut == 0:
- print '\n\nPackage Created'
- else:
- print subprocess.CalledProcessError
- def main():
- if os.path.exists(options['appPath']) == False:
- print 'File Does Not Exist: ', options['appPath']
- return
- if os.path.exists(options['entitlements']) == False:
- print 'File Does Not Exist: ', options['entitlements']
- return
- UpdateInfoPlist()
- signPlugins()
- isSigned = AppSigning()
- if isSigned:
- PackageCreation()
- print '\n\n**********End************'
- helpString = '''
- argument examples:
- --appPath "/Users/user/Desktop/MyApp.app"
- --entitlements "/Users/user/Desktop/entitlements.plist"
- --signingProfileName "3rd Party Mac Developer Application: Company, INC."
- --signingInstallerProfileName "ololo"
- --AppPackageName "myApp.pkg"
- --bundleStringinfoValue "Kids Learning Program 1.1.0. (c) 2014 MyCompany Inc. All rights reserved."
- --bundleVersionStringValue "1.1.0"
- --bundleVersionNumberValue "1.1.0"
- --bundleIdentifierValue "com.company.MyApp"
- --bundleNameValue "MyApp"
- --ApplicationCategoryValue "public.app-category.arcade-games"
- --ReadableCopyRightValue "MyCompany v1.0.0 (c) MyCompany, Inc."
- '''
- def readArgs():
- try:
- opts, args = getopt.getopt(sys.argv[1:],"h", [ k + "=" for k in options.keys()])
- except getopt.GetoptError as ex:
- print 'wrong command line args'
- print ex
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- print helpString
- sys.exit()
- else:
- options[opt.replace('--', '')] = arg
- print 'options are: '
- print options
- if __name__ == "__main__":
- readArgs()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement