本文整理匯總了Python中rapuma.core.tools.Tools.xmlFileToDict方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.xmlFileToDict方法的具體用法?Python Tools.xmlFileToDict怎麽用?Python Tools.xmlFileToDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.xmlFileToDict方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Xetex
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import xmlFileToDict [as 別名]
#.........這裏部分代碼省略.........
def makeSettingsTexFile (self) :
'''Create the primary TeX settings file.'''
# import pdb; pdb.set_trace()
description = 'This is the primary TeX settings file for the ' + self.gid + ' group. \
It is auto-generated so editing can be a rather futile exercise. This is unless you \
set freezeTexSettings to True in the XeTeX manager configuration of the project.conf \
file. Doing that will prevent the file from being remade. However, no configuration \
changes will be reflected in the static settings file. Use this with care.'
# Setting for internal testing
outputTest = False
# Check for freezeTexSettings in project.conf
if self.projectConfig['Managers'][self.cType + '_Xetex'].has_key('freezeTexSettings') and \
self.tools.str2bool(self.projectConfig['Managers'][self.cType + '_Xetex']['freezeTexSettings']) :
self.log.writeToLog(self.errorCodes['0420'])
return False
def appendLine(line, realVal) :
'''Use this to shorten the code and look for listy things.'''
if type(line) == list :
for s in line :
linesOut.append(self.proj_config.processNestedPlaceholders(s, realVal))
else :
linesOut.append(self.proj_config.processNestedPlaceholders(line, realVal))
# Open a fresh settings file
with codecs.open(self.local.macSettingsFile, "w", encoding='utf_8') as writeObject :
writeObject.write(self.tools.makeFileHeader(self.local.macSettingsFileName, description))
# Build a dictionary from the default XML settings file
# Create a dict that contains only the data we need here
macPackDict = self.tools.xmlFileToDict(self.local.macPackConfXmlFile)
for sections in macPackDict['root']['section'] :
for section in sections :
secItem = sections[section]
linesOut = []
if type(secItem) is list :
if outputTest :
print sections['sectionID']
linesOut.append('% ' + sections['sectionID'].upper())
for setting in secItem :
for k in setting.keys() :
if k == 'texCode' :
if outputTest :
print '\t', setting['key']
realVal = self.macroConfig['Macros'][self.macPackId][sections['sectionID']][setting['key']]
# Test any boolDepends that this setting might have
if setting.has_key('boolDepend') :
result = []
if type(setting['boolDepend']) == list :
for i in setting['boolDepend'] :
result.append(self.affirm(i))
else :
result.append(self.affirm(setting['boolDepend']))
# If 'None' didn't end up in the list, that means
# every bool tested good so we can output the line
if None not in result :
if outputTest :
print '\t', setting.get(k)
appendLine(setting['texCode'], realVal)
# Normal setting output
elif setting.get(k) :
if setting.get(k) != None :
示例2: ProjLocal
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import xmlFileToDict [as 別名]
class ProjLocal (object) :
# def __init__(self, pid, gid = None, cType = 'usfm', mType = 'book', macPack = 'usfmTex') :
# FIXME: Media type can be found in the general settings of an existing project, change to None
# cType is found in a group and not needed to start a project, remove from init
def __init__(self, pid, gid=None, cType=None, mType='book') :
'''Intitate a class object which contains all the project file folder locations.
The files and folders are processed by state. If the system is in a state where
certain parent files or folders do not exist, the child file or folder will be
set to None. This should only cause problems when certain proecess are attempted
that should not be given a particular state. For example, a render process should
fail if a group/component was never added.'''
# import pdb; pdb.set_trace()
self.tools = Tools()
self.pid = pid
self.gid = gid
self.rapumaHome = os.environ.get('RAPUMA_BASE')
self.userHome = os.environ.get('RAPUMA_USER')
self.osPlatform = platform.architecture()[0][:2]
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.userResource = os.path.join(site.USER_BASE, 'share', 'rapuma')
self.projHome = os.path.join(os.path.expanduser(os.environ['RAPUMA_PROJECTS']), self.pid)
self.projFolders = []
self.localDict = None
self.macPackId = None
self.mType = mType
self.cType = cType
# FIXME: The if statement to follow is a sad and desperate attempt to
# set the macPackId so that file paths will turn out in processes
# that rely on this module. This is really bad but right now I cannot
# think of another way to make this happen. I appologize for the future
# grief this is going to cause me or anyone else who tries to figure
# this situation out.
if self.cType :
pcf = os.path.join(self.projHome, 'Config', 'project.conf')
pcfx = os.path.join(self.rapumaHome, 'config', mType + '.xml')
projectConfig = self.tools.loadConfig(pcf, pcfx)
# Having come this far, it is still possible that we cannot
# set the macPackId because the component type doesn't even
# need a macro package, PDF, for example. For that reason
# we will use "try" to check passively.
try :
self.macPackId = projectConfig['CompTypes'][self.cType.capitalize()]['macroPackage']
except :
pass
debug = self.userConfig['System']['debugging']
debugOutput = os.path.join(self.userResource, 'debug', 'local_path.log')
if debug and not os.path.exists(os.path.join(self.userResource, 'debug')) :
os.makedirs(os.path.join(self.userResource, 'debug'))
# Bring in all the Rapuma default project location settings
rapumaXMLDefaults = os.path.join(self.rapumaHome, 'config', 'proj_local.xml')
if os.path.exists(rapumaXMLDefaults) :
self.localDict = self.tools.xmlFileToDict(rapumaXMLDefaults)
else :
raise IOError, "Can't open " + rapumaXMLDefaults
# Create the user resources dir under .local/share
if not os.path.isdir(self.userResource) :
os.makedirs(self.userResource)
# Troll through the localDict and create the file and folder defs we need
if debug :
debugObj = codecs.open(debugOutput, "w", encoding='utf_8')
for sections in self.localDict['root']['section'] :
for section in sections :
secItems = sections[section]
if type(secItems) is list :
for item in secItems :
if item.has_key('folderID') :
# First make a folder name placeholder and set
# to None if it doesn't exist already
try :
getattr(self, str(item['folderID']))
except :
setattr(self, item['folderID'], None)
# Next, if the 'relies' exists, set the value
val = self.processNestedPlaceholders(item['folderPath'])
# Check for relative path and fix it if needed
if len(val) > 0 :
if val[0] == '~' :
val = os.path.expanduser(val)
if item['relies'] :
if getattr(self, item['relies']) :
setattr(self, item['folderID'], val)
self.projFolders.append(val)
if debug :
debugObj.write(item['folderID'] + ' = ' + val + '\n')
else :
setattr(self, item['folderID'], val)
if debug :
debugObj.write(item['folderID'] + ' = ' + val + '\n')
elif item.has_key('fileID') :
#.........這裏部分代碼省略.........