美文网首页
Python3-打包脚本操作info.plist文件

Python3-打包脚本操作info.plist文件

作者: 037e3257fa3b | 来源:发表于2019-07-31 14:10 被阅读0次

value types

Types:
    string
    array
    dict
    bool
    real
    integer
    date
    data

将下列Log.printError()修改为print()即可

1.修改key对应的value,若不存在则添加

   @staticmethod
   def replaceInfoPlist(infoPlistPath,key,value,valueType = 'string'):
        (stauts,output) = subprocess.getstatusoutput('/usr/libexec/PlistBuddy -c \"Set :{} {}\" {} 2>&1'.format(key,value,infoPlistPath))
        if stauts != 0:
            if output.find('Does Not Exist') == -1:
                Log.printError('设置Plist失败%s=%s,[%s]'%(key,value,infoPlistPath))
            (stauts,output) = subprocess.getstatusoutput('/usr/libexec/PlistBuddy -c \"Add :{} {} {}\" {}'.format(key,valueType,value,infoPlistPath))
            if stauts != 0:
                Log.printError('添加Plist失败%s=%s,[%s]'%(key,value,infoPlistPath))

2.删除对应的key

   @staticmethod
   def deleteInfoPlist(infoPlistPath,key):
        (stauts, output) = subprocess.getstatusoutput(
            '/usr/libexec/PlistBuddy -c \"Delete :{}\" {} '.format(key, infoPlistPath))
        if stauts != 0:
            if output.find('Does Not Exist') == -1:
                Log.printError('删除Plist失败 key=%s,[%s]' % (key, infoPlistPath))

3.添加一组URLType

   @staticmethod
   def addURLTypeInfoPlist(infoPlistPath,scheme,index):
        Log.printInfo(scheme)
        (status,output) = subprocess.getstatusoutput("/usr/libexec/PlistBuddy -c \"Add :CFBundleURLTypes:{}:CFBundleTypeRole string Editor\" {}".format(index,infoPlistPath))
        if status != 0:
            Log.printError("添加Plist CFBundleURLTypes/CFBundleTypeRole失败,value = %s"%(scheme))
        (status,output) = subprocess.getstatusoutput("/usr/libexec/PlistBuddy -c \"Add :CFBundleURLTypes:{}:CFBundleURLSchemes:0 string {}\" {}".format(index,scheme,infoPlistPath))
        if status != 0:
            Log.printError("添加Plist CFBundleURLTypes/CFBundleURLSchemes失败,value = %s"%(scheme))

4.修改一组URLType

    @staticmethod
    def setURLTypeInfoPlist(infoPlistPath, scheme, index):
        Log.printInfo(scheme)
        (status, output) = subprocess.getstatusoutput(
            "/usr/libexec/PlistBuddy -c \"Set :CFBundleURLTypes:{}:CFBundleTypeRole Editor\" {}".format(index,infoPlistPath))
        if status != 0:
            Log.printError("设置Plist CFBundleURLTypes/CFBundleTypeRole失败,value = %s" % (scheme))
        (status, output) = subprocess.getstatusoutput(
            "/usr/libexec/PlistBuddy -c \"Set :CFBundleURLTypes:{}:CFBundleURLSchemes:0 {}\" {}".format(index,scheme,infoPlistPath))
        if status != 0:
            Log.printError("设置Plist CFBundleURLTypes/CFBundleURLSchemes失败,value = %s" % (scheme))

5.删除一组URLType

   @staticmethod
   def deleteURLTypeInfoPlist(infoPlistPath,index):
        (status, output) = subprocess.getstatusoutput(
            "/usr/libexec/PlistBuddy -c \"Delete :CFBundleURLTypes:{} dict\" {}".format(index,infoPlistPath))
        if status != 0:
            Log.printError("删除Plist CFBundleURLTypes失败,index = %s" % (index))

6.删除所有的URLType

   @staticmethod
   def deleteURLTypeInfoPlist(infoPlistPath):
        (status, output) = subprocess.getstatusoutput(
            "/usr/libexec/PlistBuddy -c \"Delete :CFBundleURLTypes\" {}".format(index,infoPlistPath))
        if status != 0:
            Log.printError("删除Plist CFBundleURLTypes失败" )

相关文章

网友评论

      本文标题:Python3-打包脚本操作info.plist文件

      本文链接:https://www.haomeiwen.com/subject/hxazrctx.html