本文整理匯總了Python中rapuma.core.tools.Tools.loadConfig方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.loadConfig方法的具體用法?Python Tools.loadConfig怎麽用?Python Tools.loadConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.loadConfig方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Config
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import loadConfig [as 別名]
class Config (object) :
def __init__(self, pid, gid=None) :
'''Do the primary initialization for this class.'''
self.pid = pid
self.gid = gid
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.projHome = os.path.join(os.path.expanduser(self.userConfig['Resources']['projects']), self.pid)
self.local = ProjLocal(pid, gid)
self.tools = Tools()
self.log = ProjLog(pid)
# Create config placeholders
self.projectConfig = None
self.adjustmentConfig = None
self.layoutConfig = None
self.illustrationConfig = None
self.fontConfig = None
self.macroConfig = None
# Log messages for this module
self.errorCodes = {
'3100' : ['ERR', 'Macro package: [<<1>>] already exists in the project. Use force (-f) to reinstall.'],
'3200' : ['ERR', 'Failed to install macro package: [<<1>>]'],
'3300' : ['MSG', 'Install macro package: [<<1>>], Reinitialized [<<2>>]'],
'3310' : ['ERR', 'Failed to copy [<<1>>] to folder [<<2>>].'],
'3400' : ['MSG', 'Force set to True. Removed macro package configuration file: [<<1>>]'],
'3500' : ['MSG', 'Removed macro package [<<1>>] folder and all files contained.'],
'3600' : ['MSG', 'Updated macro package [<<1>>]'],
'3650' : ['ERR', 'Failed to updated macro package [<<1>>]']
}
# Test for gid before trying to finish the init
# import pdb; pdb.set_trace()
if gid :
if not self.projectConfig :
self.getProjectConfig()
# We need to skip over this if the group doesn't exist
try :
# Reinitialize local
self.cType = self.projectConfig['Groups'][gid]['cType']
self.Ctype = self.cType.capitalize()
self.local = ProjLocal(pid, gid, self.cType)
except :
self.cType = None
self.Ctype = None
else :
self.cType = None
self.Ctype = None
###############################################################################
############################# Get Config Functions ############################
###############################################################################
####################### Error Code Block Series = 0500 ########################
###############################################################################
def getProjectConfig (self) :
'''Load/return the project configuation object.'''
# import pdb; pdb.set_trace()
self.projectConfig = self.tools.loadConfig(self.local.projectConfFile, self.local.projectConfXmlFile)
def getAdjustmentConfig (self) :
'''Load/return the adjustment configuation object.'''
self.adjustmentConfig = self.tools.loadConfig(self.local.adjustmentConfFile, self.local.adjustmentConfXmlFile)
def getLayoutConfig (self) :
'''Load/return the layout configuation object.'''
self.layoutConfig = self.tools.loadConfig(self.local.layoutConfFile, self.local.layoutConfXmlFile)
def getIllustrationConfig (self) :
'''Load/return the illustration configuation object.'''
self.illustrationConfig = self.tools.loadConfig(self.local.illustrationConfFile, self.local.illustrationConfXmlFile)
def getFontConfig (self) :
'''Load/return the font configuation object.'''
self.fontConfig = self.tools.loadConfig(self.local.fontConfFile, self.local.fontConfXmlFile)
def getMacroConfig (self) :
'''Load/return the macro configuration object.'''
self.macroConfig = self.tools.loadConfig(self.local.macroConfFile, self.local.macroConfXmlFile)
#.........這裏部分代碼省略.........
示例2: Macro
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import loadConfig [as 別名]
class Macro(object):
def __init__(self, pid, cType, gid=None):
"""Do the primary initialization for this class."""
self.pid = pid
self.gid = gid
self.cType = cType
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.projHome = os.path.join(os.path.expanduser(self.userConfig["Resources"]["projects"]), self.pid)
self.local = ProjLocal(pid, gid, cType)
# import pdb; pdb.set_trace()
self.proj_config = Config(pid)
self.proj_config.getProjectConfig()
self.projectConfig = self.proj_config.projectConfig
self.layoutConfig = self.proj_config.layoutConfig
self.tools = Tools()
self.log = ProjLog(pid)
# Create config placeholders
self.layoutConfig = None
self.illustrationConfig = None
self.macroConfig = self.tools.loadConfig(self.local.macroConfFile, self.local.macroConfXmlFile)
# Log messages for this module
self.errorCodes = {
"3010": ["ERR", "No macro package is registered for the [<<1>>] component type."],
"3020": ["ERR", "Cannot update! No macro package is registered for the [<<1>>] component type."],
"3050": ["ERR", "Macro package file not found: [<<1>>]"],
"3100": [
"ERR",
"Macro package: [<<1>>] already exists in the project. I am not allowed to copy over an existing package.",
],
"3200": ["ERR", "Failed to install macro package: [<<1>>]"],
"3300": ["MSG", "Installed macro package: [<<1>>], Reinitialized [<<2>>]"],
"3310": ["ERR", "Failed to copy [<<1>>] to folder [<<2>>]."],
"3400": ["MSG", "Removed macro package configuration settings for: [<<1>>] from the macro.conf file."],
"3500": ["MSG", "Removed macro package [<<1>>] folder and all files contained."],
"3600": ["MSG", "Updated component type [<<1>>] with macro package [<<2>>]"],
"3650": ["ERR", "Failed to updated macro package [<<1>>]"],
}
###############################################################################
###################### Macro Package Handling Functions #######################
###############################################################################
######################## Error Code Block Series = 3000 #######################
###############################################################################
def createMacroFiles(self, macPackId):
"""Create all the necessary macro file names with their assigned paths."""
self.projMacPackFolder = os.path.join(self.local.projMacPackFolder, macPackId)
texFileIds = {
"preStyTexExtFile": "preSty-ext.tex",
"macSettingsFile": "settings.tex",
"extTexFile": "extension.tex",
"grpExtTexFile": self.gid + "-extension.tex",
"": "",
"": "",
"": "",
"": "",
"": "",
}
styFileIds = {
"glbExtStyFile": "extension.sty",
"grpExtStyFile": self.gid + "-extension.sty",
"": "",
"": "",
"": "",
"": "",
"": "",
}
# <file>
# <name>TeX lccode Definition File</name>
# <description>The TeX file that contains lccode definitions and is linked with the hypenation exclusions file.</description>
# <fileID>lccodeTexFile</fileID>
# <fileName>[self:gid]-lccode.tex</fileName>
# <filePath>[self:projGidFolder]</filePath>
# <depends></depends>
# <relies></relies>
# <note>This file is located in the component group folder to allow more segregated processing.</note>
# </file>
# <file>
# <name>TeX Group Hyphenation Exclusions File</name>
# <description>The file that contains the hypenation words exclusions list for the current group that TeX will use to render the text.</description>
# <fileID>grpHyphExcTexFile</fileID>
# <fileName>[self:gid]-hyphenation.tex</fileName>
# <filePath>[self:projGidFolder]</filePath>
# <depends></depends>
# <relies></relies>
# <note>This file is located in the component group folder to allow more segregated processing.</note>
# </file>
def getMacPackIdFromFileName(self, fileName):
"""Return the macPack ID based on the file name"""
# File name less ext is the ID
#.........這裏部分代碼省略.........
示例3: Macro
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import loadConfig [as 別名]
class Macro (object) :
def __init__(self, pid, cType, gid=None) :
'''Do the primary initialization for this class.'''
self.pid = pid
self.gid = gid
self.cType = cType
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.projHome = os.path.join(os.path.expanduser(os.environ['RAPUMA_PROJECTS']), self.pid)
self.local = ProjLocal(pid, gid, cType)
# import pdb; pdb.set_trace()
self.proj_config = Config(pid)
self.proj_config.getProjectConfig()
self.projectConfig = self.proj_config.projectConfig
self.layoutConfig = self.proj_config.layoutConfig
self.tools = Tools()
self.log = ProjLog(pid)
# Create config placeholders
self.layoutConfig = None
self.illustrationConfig = None
self.macroConfig = self.tools.loadConfig(self.local.macroConfFile, self.local.macroConfXmlFile)
# Log messages for this module
self.errorCodes = {
'3010' : ['ERR', 'No macro package is registered for the [<<1>>] component type.'],
'3020' : ['ERR', 'Cannot update! No macro package is registered for the [<<1>>] component type.'],
'3050' : ['ERR', 'Macro package file not found: [<<1>>]'],
'3100' : ['ERR', 'Macro package: [<<1>>] already exists in the project. I am not allowed to copy over an existing package.'],
'3200' : ['ERR', 'Failed to install macro package: [<<1>>]'],
'3300' : ['MSG', 'Installed macro package: [<<1>>], Reinitialized [<<2>>]'],
'3310' : ['ERR', 'Failed to copy [<<1>>] to folder [<<2>>].'],
'3400' : ['MSG', 'Removed macro package configuration settings for: [<<1>>] from the macro.conf file.'],
'3500' : ['MSG', 'Removed macro package [<<1>>] folder and all files contained.'],
'3600' : ['MSG', 'Updated component type [<<1>>] with macro package [<<2>>]'],
'3650' : ['ERR', 'Failed to updated macro package [<<1>>]']
}
###############################################################################
###################### Macro Package Handling Functions #######################
###############################################################################
######################## Error Code Block Series = 3000 #######################
###############################################################################
def createMacroFiles (self, macPackId) :
'''Create all the necessary macro file names with their assigned paths.'''
self.projMacPackFolder = os.path.join(self.local.projMacPackFolder, macPackId)
texFileIds = {'preStyTexExtFile':'preSty-ext.tex', 'macSettingsFile':'settings.tex',
'extTexFile':'extension.tex', 'grpExtTexFile': self.gid + '-extension.tex',
'':'', '':'', '':'', '':'', '':'', }
styFileIds = {'glbExtStyFile':'extension.sty', 'grpExtStyFile': self.gid + '-extension.sty',
'':'', '':'', '':'', '':'', '':''}
def getMacPackIdFromFileName (self, fileName) :
'''Return the macPack ID based on the file name'''
# File name less ext is the ID
parts = len(fileName.split('.'))
return '.'.join(fileName.split('.')[:parts-1])
def getMacPackIdFromSource (self, source) :
'''Return the macPack ID based on the complete path and file name.'''
# Get the file name from the path
fileName = self.tools.fName(source)
# Return the ID
return self.getMacPackIdFromFileName(fileName)
def addMacPack (self, source) :
'''Add a macro package to the project. It will not work if
the same package is already present. Remove must be used
to get rid of the existing one first.'''
# import pdb; pdb.set_trace()
macPackId = self.getMacPackIdFromSource(source)
confXml = os.path.join(self.local.projMacroFolder, macPackId, macPackId + '.xml')
if not os.path.isfile(source) :
self.log.writeToLog(self.errorCodes['3050'], [source])
# Do not add/install if there seems to be a macro package there already
if self.projectConfig['CompTypes'][self.cType.capitalize()]['macroPackage'] and os.path.exists(self.local.macroConfFile) :
self.log.writeToLog(self.errorCodes['3100'], [macPackId])
return False
# Set the projectConf to the new/same package
self.projectConfig['CompTypes'][self.cType.capitalize()]['macroPackage'] = macPackId
self.tools.writeConfFile(self.projectConfig)
# If we got this far, install the a fresh copy of the macPack
#.........這裏部分代碼省略.........
示例4: ProjLocal
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import loadConfig [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') :
#.........這裏部分代碼省略.........