安装bplist

pip3 install bplist 

 代码部分

包含获取系统文件路径 指定文件名

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
from biplist import *

class pliatManager(object):
	"""docstring for ClassName"""
	# def __init__(self, arg):
		# super(ClassName, self).__init__()
		# self.arg = arg

	 # plist 路径
	def filePaht(self):
		# 获取系统桌面路径
		# 系统路径
		osPath = os.path.expanduser('~')
		# 桌面路径 
		subPath = "Desktop"
		pathstr = os.path.join(osPath,subPath)
		return  pathstr

	# plist 名字
	def plistName(self):
		checkfile ='Info.plist'
		return  checkfile

	# 切换目录  目录
	def changePath(self,pathstr):
		os.chdir(pathstr)
		ls = os.getcwd()
		print ("当前目录是 : ", pathstr)
		return

	# 读取plist
	def readPlistFromName(self,name):
		try:
			plist = readPlist(name)

			return  plist
			pass
		except Exception as e:
			raise e
			return 
	# 修改的原字典 键 值
	def changeValueForKey(self,plist,key,value):

		try:
			plist[key] = value;
			writePlist(plist,plm.plistName())
			print ("修改 ",key,"=",value )
			pass
		except Exception as e:
			print ("Something bad happened:",e)
			raise e
	def valueForKay(self,plist,key):

		return plist[key]


plm =  pliatManager()

filePaht =  plm.filePaht()
plistName =  plm.plistName()

plm.changePath(filePaht)

plist = plm.readPlistFromName(plistName);

CFBundleIdentifier = plm.valueForKay(plist,'CFBundleIdentifier')
CFBundleVersion = plm.valueForKay(plist,'CFBundleVersion')
CFBundleShortVersionString = plm.valueForKay(plist,'CFBundleShortVersionString')
CFBundleDisplayName = plm.valueForKay(plist,'CFBundleDisplayName')

print ("CFBundleDisplayName =", CFBundleDisplayName)
print ("CFBundleIdentifier =", CFBundleIdentifier)
print ("CFBundleShortVersionString =", CFBundleShortVersionString)
print ("CFBundleVersion =", CFBundleVersion)

plm.changeValueForKey(plist,"CFBundleDisplayName","55555")

plist文件内容 保存桌面 info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationSupportsMultipleScenes</key>
		<false/>
		<key>UISceneConfigurations</key>
		<dict>
			<key>UIWindowSceneSessionRoleApplication</key>
			<array>
				<dict>
					<key>UISceneConfigurationName</key>
					<string>Default Configuration</string>
					<key>UISceneDelegateClassName</key>
					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
				</dict>
			</array>
		</dict>
	</dict>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐