本文整理匯總了Python中rapuma.core.tools.Tools.xml_to_section方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.xml_to_section方法的具體用法?Python Tools.xml_to_section怎麽用?Python Tools.xml_to_section使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.xml_to_section方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: UserConfig
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import xml_to_section [as 別名]
class UserConfig (object) :
def __init__(self) :
'''Intitate the whole class and create the object.'''
# import pdb; pdb.set_trace()
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 either server or desktop
# The RAPUMA_USER setting should have the right path from
# the mother script (rapuma)
self.userConfFile = os.path.join(self.defaultUserHome, self.userConfFileName)
# 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
# Now make the users local rapuma.conf file if it isn't there
if not os.path.isfile(self.userConfFile) :
self.initUserHome()
# Load the system.conf file into an object
self.userConfig = ConfigObj(self.userConfFile, encoding='utf-8')
# 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')
示例2: UserConfig
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import xml_to_section [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"])
#.........這裏部分代碼省略.........