本文整理汇总了Python中rapuma.core.tools.Tools.buildConfSection方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.buildConfSection方法的具体用法?Python Tools.buildConfSection怎么用?Python Tools.buildConfSection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.buildConfSection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserConfig
# 需要导入模块: from rapuma.core.tools import Tools [as 别名]
# 或者: from rapuma.core.tools.Tools import buildConfSection [as 别名]
class UserConfig(object):
def __init__(self):
"""Intitate the whole class and create the object."""
self.rapumaHome = os.environ.get("RAPUMA_BASE")
self.defaultUserHome = os.environ.get("RAPUMA_USER")
self.userConfFileName = "rapuma.conf"
self.tools = Tools()
# Point to the right user config
# Look for a web installation first, if not go to default
# Note that a slash is put before var as it is off of root
# That kind of stops this from being cross-platform
rapumaWebConfig = os.path.join("/var", "lib", "rapuma", "config", self.userConfFileName)
defaultConfig = os.path.join(self.defaultUserHome, self.userConfFileName)
if os.path.exists(rapumaWebConfig):
self.userConfFile = rapumaWebConfig
else:
self.userConfFile = defaultConfig
# Check to see if the file is there, then read it in and break it into
# sections. If it fails, scream really loud!
rapumaXMLDefaults = os.path.join(self.rapumaHome, "config", "rapuma.xml")
if os.path.exists(rapumaXMLDefaults):
self.tools.sysXmlConfig = self.tools.xml_to_section(rapumaXMLDefaults)
else:
raise IOError, "Can't open " + rapumaXMLDefaults
# import pdb; pdb.set_trace()
# Now make the users local rapuma.conf file if it isn't there
if not os.path.exists(self.userConfFile):
self.initUserHome()
# Load the Rapuma conf file into an object
self.userConfig = ConfigObj(self.userConfFile, encoding="utf-8")
# Initialize the user's home folders, like resources, etc
self.makeHomeFolders()
# Log messages for this module
self.errorCodes = {"0000": ["MSG", "Placeholder message"]}
###############################################################################
############################ User Config Functions ############################
###############################################################################
def initUserHome(self):
"""Initialize a user config file on a new install or system re-init."""
# Create home folders
if not os.path.isdir(self.defaultUserHome):
os.mkdir(self.defaultUserHome)
# Make the default global rapuma.conf for custom environment settings
if not os.path.isfile(self.userConfFile):
self.userConfig = ConfigObj(self.tools.sysXmlConfig.dict(), encoding="utf-8")
self.userConfig.filename = self.userConfFile
self.userConfig["System"]["initDate"] = self.tools.tStamp()
self.userConfig.write()
def setSystemSettings(self, section, key, value):
"""Function to make system settings."""
oldValue = self.userConfig[section][key]
if oldValue != value:
self.userConfig[section][key] = value
# Write out the results
self.userConfig.write()
self.tools.terminal("\nRapuma user name setting changed from [" + oldValue + "] to [" + value + "].\n\n")
else:
self.tools.terminal("\nSame value given, nothing to changed.\n\n")
def makeHomeFolders(self):
"""Setup the default Rapuma resource folders."""
# import pdb; pdb.set_trace()
# We do not write out unless this flag is set
confWriteFlag = False
# Setup Resources section if needed
if not self.userConfig.has_key("Resources"):
self.tools.buildConfSection(self.userConfig, "Resources")
# Get the user config project folder location (or set a default)
if not self.userConfig["Resources"].has_key("projects") or not self.userConfig["Resources"]["projects"]:
projects = os.path.join(os.environ.get("HOME"), "Publishing")
if not os.path.exists(projects):
os.makedirs(projects)
self.userConfig["Resources"]["projects"] = projects
confWriteFlag = True
elif not os.path.exists(self.tools.resolvePath(self.userConfig["Resources"]["projects"])):
sys.exit(
"\nERROR: Invalid projects folder path: "
+ self.userConfig["Resources"]["projects"]
+ "\n\nProcess halted.\n"
)
else:
projects = self.tools.resolvePath(self.userConfig["Resources"]["projects"])
#.........这里部分代码省略.........
示例2: Usfm
# 需要导入模块: from rapuma.core.tools import Tools [as 别名]
# 或者: from rapuma.core.tools.Tools import buildConfSection [as 别名]
#.........这里部分代码省略.........
#cStrPgNo = 1
#self.projectConfig['Groups'][self.gid]['startPageNumber'] = 1
#try :
#pGrpPgs = int(self.projectConfig['Groups'][pGrp]['totalPages'])
#pGrpStrPgNo = int(self.projectConfig['Groups'][pGrp]['startPageNumber'])
#except :
## FIXME: Maybe this could go out and find out exactly how many pages were in the preceeding group
#pGrpPgs = 1
#pGrpStrPgNo = 1
#self.projectConfig['Groups'][pGrp]['totalPages'] = 1
#self.projectConfig['Groups'][pGrp]['startPageNumber'] = 1
## Whether this is right or wrong set it the way it is
#self.projectConfig['Groups'][self.gid]['startPageNumber'] = (pGrpStrPgNo + pGrpPgs)
#self.tools.writeConfFile(self.projectConfig)
#return self.projectConfig['Groups'][pGrp]['startPageNumber']
def createCompAdjustmentFile (self, cid) :
'''Create an adjustment file for this cid. If entries exsist in
the adjustment.conf file.'''
description = 'Auto-generated text adjustments file for: ' + cid + '\n'
# import pdb; pdb.set_trace()
# Check for a master adj conf file
if os.path.exists(self.local.adjustmentConfFile) :
adjFile = self.getCidAdjPath(cid)
# Clean up old file if there is one so we can start fresh
if os.path.exists(adjFile) :
os.remove(adjFile)
# Nothing to do if no gid section is found
if not self.adjustmentConfig.has_key(self.gid) :
self.tools.buildConfSection(self.adjustmentConfig, self.gid)
if not self.adjustmentConfig[self.gid].has_key(cid) :
self.tools.buildConfSection(self.adjustmentConfig[self.gid], cid)
self.adjustmentConfig[self.gid][cid]['%1.1'] = '1'
self.tools.writeConfFile(self.adjustmentConfig)
self.log.writeToLog(self.errorCodes['0240'], [cid])
return False
# Sort through commented adjustment lines ()
if self.adjustmentConfig[self.gid].has_key(cid) :
c = False
for k in self.adjustmentConfig[self.gid][cid].keys() :
if not re.search(r'%|#', k) :
c = True
if not c :
self.log.writeToLog(self.errorCodes['0245'], [cid])
return False
# If we make it this far, create the new adjustment file
with codecs.open(adjFile, "w", encoding='utf_8') as writeObject :
writeObject.write(self.tools.makeFileHeader(adjFile, description, True))
# Output like this: JAS 1.13 +1
for k, v in self.adjustmentConfig[self.gid][cid].iteritems() :
if re.search(r'%|#', k) :
continue
adj = v
if int(v) > 0 :
adj = '+' + str(v)
writeObject.write(cid.upper() + ' ' + k + ' ' + adj + '\n')
self.log.writeToLog(self.errorCodes['0230'], [self.tools.fName(adjFile)])
return True
示例3: Project
# 需要导入模块: from rapuma.core.tools import Tools [as 别名]
# 或者: from rapuma.core.tools.Tools import buildConfSection [as 别名]
#.........这里部分代码省略.........
###############################################################################
def createManager (self, mType) :
'''Check to see if a manager is listed in the config and load it if
it is not already.'''
fullName = self.cType + '_' + mType.capitalize()
if fullName not in self.managers :
self.addManager(mType)
self.loadManager(mType)
self.log.writeToLog(self.errorCodes['0205'], [fullName])
def loadManager (self, mType) :
'''Do basic load on a manager.'''
fullName = self.cType + '_' + mType.capitalize()
cfg = self.projectConfig['Managers'][fullName]
module = import_module('rapuma.manager.' + mType)
ManagerClass = getattr(module, mType.capitalize())
manobj = ManagerClass(self, cfg, self.cType)
self.managers[fullName] = manobj
def addManager (self, mType) :
'''Create a manager reference in the project config that components
will point to.'''
# import pdb; pdb.set_trace()
fullName = self.cType + '_' + mType.capitalize()
managerDefaults = None
# Insert the Manager section if it is not already there
self.tools.buildConfSection(self.projectConfig, 'Managers')
if not self.projectConfig['Managers'].has_key(fullName) :
self.tools.buildConfSection(self.projectConfig['Managers'], fullName)
# Update settings if needed
update = False
managerDefaults = self.tools.getXMLSettings(os.path.join(self.local.rapumaConfigFolder, mType + '.xml'))
for k, v, in managerDefaults.iteritems() :
# Do not overwrite if a value is already there
if not self.projectConfig['Managers'][fullName].has_key(k) :
self.projectConfig['Managers'][fullName][k] = v
# If we are dealing with an empty string, don't bother writing out
# Trying to avoid needless conf updating here. Just in case we are
# working with a list, we'll use len()
if len(v) > 0 :
update = True
# Update the conf if one or more settings were changed
if update :
if self.tools.writeConfFile(self.projectConfig) :
self.log.writeToLog(self.errorCodes['0210'],[fullName])
else :
self.log.writeToLog(self.errorCodes['0211'],[fullName])
###############################################################################
############################ Group Level Functions ############################
###############################################################################
####################### Error Code Block Series = 0600 ########################
###############################################################################
def renderGroup (self, cidList = '', pages = '', override = '', save = False) :
'''Render a group of subcomponents or any number of components
示例4: ProjFont
# 需要导入模块: from rapuma.core.tools import Tools [as 别名]
# 或者: from rapuma.core.tools.Tools import buildConfSection [as 别名]
class ProjFont (object) :
def __init__(self, pid) :
'''Do the primary initialization for this class.'''
self.pid = pid
self.tools = Tools()
self.user = UserConfig()
self.log = ProjLog(pid)
self.userConfig = self.user.userConfig
self.proj_config = Config(pid)
self.proj_config.getProjectConfig()
self.projectConfig = self.proj_config.projectConfig
self.proj_config.getFontConfig()
self.fontConfig = self.proj_config.fontConfig
self.local = ProjLocal(pid, self.projectConfig)
# Load all font settings for use in this module
if self.fontConfig :
for k, v in self.fontConfig['GeneralSettings'].iteritems() :
setattr(self, k, v)
# Log messages for this module
self.errorCodes = {
'FONT-000' : ['MSG', 'Font module messages'],
'FONT-005' : ['MSG', 'FONT-005 - Unassigned error message ID.'],
'FONT-015' : ['MSG', 'FONT-015 - Unassigned error message ID.'],
'FONT-020' : ['ERR', 'Failed to find font setting in ParaTExt project (.ssf file). A primary font must be set before this component can be successfully rendered.'],
'FONT-025' : ['ERR', 'No source editor was found for this project. Please enter this setting before continuing.'],
'FONT-042' : ['MSG', 'The [<<1>>] font setup information was added to project config'],
'FONT-050' : ['ERR', 'Halt! [<<1>>] not found. - font.copyInFont()'],
'FONT-070' : ['LOG', 'Copied the [<<1>>] font file into the project. - proj_font.copyInFont()'],
'FONT-100' : ['ERR', 'This function has not been implemented yet!. - proj_font.setGlyphMap()'],
'0010' : ['LOG', 'Wrote out new font configuration (font.__init__())'],
'1220' : ['ERR', 'The Font bundle file [<<1>>] could not be found. Process halted.'],
'1235' : ['MSG', 'Font [<<1>>] has been installed into the project.'],
'1237' : ['MSG', 'Font [<<1>>] has been updated.'],
'1240' : ['ERR', 'Font bundle file [<<1>>] not found.'],
'1241' : ['ERR', 'Font bundle [<<1>>] not found.'],
'1245' : ['LOG', '<<1>> font setup information added to project config'],
'1250' : ['ERR', 'The [<<1>>] font is apparently part of this project. Please remove before trying to re-add this font.'],
'1260' : ['MSG', 'The <<1>> font bundle has been copied into the project font folder.'],
'1262' : ['LOG', 'The <<1>> font bundle already exsits in the font folder.'],
'1265' : ['ERR', 'Failed to extract the [<<1>>] font bundle into the project. Font install process failed.'],
'1267' : ['LOG', 'The <<1>> font bundle has been copied into the project font folder.'],
'1280' : ['MSG', 'Failed to install the font: [<<1>>] into the project.'],
'1370' : ['LOG', 'Removed [<<1>>] font name from project component type: [<<2>>].'],
'1380' : ['MSG', 'Removed the [<<1>>] font from the project.'],
'1382' : ['MSG', 'Force switch was set (-f). This process has completely removed the [<<1>>] font and settings from the project. - proj_font.removeFont()'],
'1390' : ['LOG', 'Removed the [<<1>>] font package.'],
'1395' : ['MSG', 'Could not remove the [<<1>>] font package. It may be used by another group. Use force (-f) to remove the package from the font folder.']
}
###############################################################################
############################ Project Level Functions ##########################
###############################################################################
######################## Error Code Block Series = 1000 #######################
###############################################################################
def setGlyphMap (self, cType, font) :
'''If needed, set the glyph map used for this component type font.'''
self.log.writeToLog('FONT-100')
def getFontIdFromFileName (self, fileName) :
'''Return the font ID based on the file name'''
# File name less ext is the font ID
parts = len(fileName.split('.'))
return '.'.join(fileName.split('.')[:parts-1])
def getFontIdFromSource (self, source) :
'''Return the font ID based on the complete path and file name.'''
# Get the file name from the path
fileName = self.tools.fName(source)
# Return the font ID
return self.getFontIdFromFileName(fileName)
def recordFont (self, fontId, cType=None) :
'''Check for the exsitance of the specified font in the font folder.
Then extract the meta data into the appropreate configurations.'''
# import pdb; pdb.set_trace()
# Set vars do initial checks
metaDataSource = os.path.join(self.local.projFontFolder, fontId, fontId + '.xml')
if not os.path.isfile(metaDataSource) :
self.log.writeToLog(self.errorCodes['1240'], [fontId + '.xml', 'proj_font.recordFont():1240'])
# Build the Fonts section in the config (if needed)
self.tools.buildConfSection(self.fontConfig, 'Fonts')
#.........这里部分代码省略.........