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失败" )
网友评论