Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.30 KB | None | 0 0
  1. #!/usr/bin/pyhton
  2.  
  3. #created by: hamdullahshah@gmail.com
  4. #modified by: mozgoid@gmail.com
  5.  
  6. import os, getopt, sys
  7. import subprocess
  8. import plistlib as PlistParser
  9.  
  10. options = {
  11. "appPath" : "/Users/user/Desktop/MyApp.app",
  12. "entitlements" : "/Users/user/Desktop/entitlements.plist",
  13. "signingProfileName" : "3rd Party Mac Developer Application: MyCompany (QWERTYU)",
  14. "signingInstallerProfileName" : "",
  15. "AppPackageName" : "myApp.pkg",
  16. "bundleStringinfoValue" : "Kids Learning Program 1.1.0. (c) 2014 MyCompany Inc. All rights reserved.",
  17. "bundleVersionStringValue" : "1.1.0",
  18. "bundleVersionNumberValue" : "1.1.0",
  19. "bundleIdentifierValue" : "com.company.MyApp",
  20. "bundleNameValue" : "MyApp",
  21. "ApplicationCategoryValue" : "public.app-category.strategy-games",
  22. "ReadableCopyRightValue" : "MyCompany  v1.0.0 (c) MyCompany, Inc.",
  23. }
  24.  
  25.  
  26. def removeMetaFilesFromDirectiory(dirPath):
  27.     fileslist = []
  28.     for root, dirs, files in os.walk(dirPath):
  29.         for file in files:
  30.             if file.endswith('.meta'):
  31.                 metaFilePath = root + '/' + file
  32.                 fileslist.append(metaFilePath)
  33.  
  34.     for filePath in fileslist:
  35.         print 'deleting file: ', filePath
  36.         os.remove(filePath)
  37.  
  38. def signPlugins():
  39.     pluginsPath = options['appPath'] + '/Contents/Plugins'
  40.     if os.path.exists(pluginsPath):
  41.         for plugin in os.listdir(pluginsPath):
  42.             p = pluginsPath + '/' + plugin
  43.             removeMetaFilesFromDirectiory(p)
  44.             executeCodeSign(p)
  45.  
  46.  
  47.  
  48. def UpdateInfoPlist():
  49.     plistPath = options['appPath'] + "/Contents/Info.plist"
  50.     allData = PlistParser.readPlist(plistPath)
  51.  
  52.     allData["CFBundleGetInfoString"] = options['bundleStringinfoValue']
  53.     allData["CFBundleShortVersionString"] = options['bundleVersionStringValue']
  54.     allData["CFBundleVersion"] = options['bundleVersionNumberValue']
  55.     allData["CFBundleIdentifier"] = options['bundleIdentifierValue']
  56.     allData["CFBundleName"] = options['bundleNameValue']
  57.     allData["LSApplicationCategoryType"] = options['ApplicationCategoryValue']
  58.     allData["NSHumanReadableCopyright"] = options['ReadableCopyRightValue']
  59.  
  60.     PlistParser.writePlist(allData, plistPath)
  61.  
  62.  
  63. def executeCodeSign(pathToTargetSign):
  64.     codesignPlugin = subprocess.call(["codesign", "--deep", "-f", "-v", "-s"
  65.         , options['signingProfileName']
  66.         , "--entitlements"
  67.         , options['entitlements']
  68.         , pathToTargetSign])
  69.  
  70.     if codesignPlugin == 0:
  71.         print '\nSigning Completed of ', pathToTargetSign
  72.         return True
  73.     else:
  74.         print subprocess.CalledProcessError
  75.         return False
  76.  
  77.  
  78. def AppSigning():
  79.     print "\n\n**********Signing App for Mac AppStore with \"", options['signingProfileName'], "\" ************"
  80.  
  81.     codesignOutput = subprocess.call(["codesign", "--deep", "-f", "-v", "-s",
  82.             options['signingProfileName'],
  83.             "--entitlements",
  84.             options['entitlements'],
  85.             options['appPath']])
  86.  
  87.     if codesignOutput == 0:
  88.         print '\n\nSigning Completed'
  89.         return True
  90.     else:
  91.         print subprocess.CalledProcessError
  92.         return False
  93.  
  94. def PackageCreation():
  95.     if len(options['AppPackageName']) == 0:
  96.         print "won't create package"
  97.         return
  98.     if len(options['signingInstallerProfileName']) == 0:
  99.         print '\n\nCreating Package without installer signing.'
  100.         installerOutPut = subprocess.call(["productbuild", "--component",
  101.                 options['appPath'], "/Applications",
  102.                 options['AppPackageName']])
  103.  
  104.         if installerOutPut == 0:
  105.             print '\n\nPackage Created'
  106.         else:
  107.             print subprocess.CalledProcessError
  108.     else:
  109.         print '\n\nCreating Package with ',options['signingInstallerProfileName'], ' installer signing.'
  110.  
  111.         installerOutPut = subprocess.call(["productbuild", "--component",
  112.                 options['appPath'],
  113.                 "/Applications",
  114.                 "--sign",
  115.                 options['signingInstallerProfileName'],
  116.                 options['AppPackageName']])
  117.  
  118.         if installerOutPut == 0:
  119.             print '\n\nPackage Created'
  120.         else:
  121.             print subprocess.CalledProcessError
  122.  
  123. def  main():
  124.     if os.path.exists(options['appPath']) == False:
  125.         print 'File Does Not Exist: ', options['appPath']
  126.         return
  127.  
  128.     if os.path.exists(options['entitlements']) == False:
  129.         print 'File Does Not Exist: ', options['entitlements']
  130.         return
  131.  
  132.     UpdateInfoPlist()
  133.  
  134.     signPlugins()
  135.  
  136.     isSigned = AppSigning()
  137.  
  138.     if isSigned:
  139.         PackageCreation()
  140.  
  141.     print '\n\n**********End************'
  142.  
  143.  
  144. helpString = '''
  145. argument examples:
  146.     --appPath "/Users/user/Desktop/MyApp.app"
  147.     --entitlements  "/Users/user/Desktop/entitlements.plist"
  148.     --signingProfileName  "3rd Party Mac Developer Application: Company, INC."
  149.     --signingInstallerProfileName  "ololo"
  150.     --AppPackageName "myApp.pkg"
  151.     --bundleStringinfoValue "Kids Learning Program 1.1.0. (c) 2014 MyCompany Inc. All rights reserved."
  152.     --bundleVersionStringValue "1.1.0"
  153.     --bundleVersionNumberValue "1.1.0"
  154.     --bundleIdentifierValue "com.company.MyApp"
  155.     --bundleNameValue "MyApp"
  156.     --ApplicationCategoryValue "public.app-category.arcade-games"
  157.     --ReadableCopyRightValue "MyCompany  v1.0.0 (c) MyCompany, Inc."
  158. '''
  159.  
  160.  
  161. def readArgs():
  162.    try:
  163.       opts, args = getopt.getopt(sys.argv[1:],"h", [ k + "=" for k in options.keys()])
  164.    except getopt.GetoptError as ex:
  165.       print 'wrong command line args'
  166.       print ex
  167.       sys.exit(2)
  168.  
  169.    for opt, arg in opts:
  170.       if opt == '-h':
  171.          print helpString
  172.          sys.exit()
  173.       else:
  174.          options[opt.replace('--', '')] = arg
  175.  
  176.    print 'options are: '
  177.    print options
  178.  
  179. if __name__ == "__main__":
  180.    readArgs()
  181.    main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement