本文整理匯總了Python中foundations.parsers.SectionsFileParser.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Python SectionsFileParser.getValue方法的具體用法?Python SectionsFileParser.getValue怎麽用?Python SectionsFileParser.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類foundations.parsers.SectionsFileParser
的用法示例。
在下文中一共展示了SectionsFileParser.getValue方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __templatesOutliner_view_selectionModel__selectionChanged
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def __templatesOutliner_view_selectionModel__selectionChanged(self, selectedItems, deselectedItems):
"""
This method is triggered when **templatesOutliner.view** Model selection has changed.
:param selectedItems: Selected items. ( QItemSelection )
:param deselectedItems: Deselected items. ( QItemSelection )
"""
selectedTemplates = self.__templatesOutliner.getSelectedTemplates()
template = foundations.common.getFirstItem(selectedTemplates)
if not (template and foundations.common.pathExists(template.path)):
return
LOGGER.debug("> Parsing '{0}' Template for '{1}' section.".format(template.name,
self.__templateRemoteConnectionSection))
templateSectionsFileParser = SectionsFileParser(template.path)
templateSectionsFileParser.read() and templateSectionsFileParser.parse(
rawSections=(self.__templateScriptSection))
if not self.__templateRemoteConnectionSection in templateSectionsFileParser.sections:
return
LOGGER.debug("> {0}' section found.".format(self.__templateRemoteConnectionSection))
connectionType = foundations.parsers.getAttributeCompound("ConnectionType",
templateSectionsFileParser.getValue("ConnectionType", self.__templateRemoteConnectionSection))
if connectionType.value == "Socket":
LOGGER.debug("> Remote connection type: 'Socket'.")
self.__tcpClientUi.address = foundations.parsers.getAttributeCompound("DefaultAddress",
templateSectionsFileParser.getValue("DefaultAddress",
self.__templateRemoteConnectionSection)).value
self.__tcpClientUi.port = int(foundations.parsers.getAttributeCompound("DefaultPort",
templateSectionsFileParser.getValue("DefaultPort",
self.__templateRemoteConnectionSection)).value)
elif connectionType.value == "Win32":
LOGGER.debug("> Remote connection: 'Win32'.")
示例2: sendLoaderScriptToSoftware
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def sendLoaderScriptToSoftware(self, template, loaderScriptPath):
"""
This method sends the Loader Script to associated 3d package.
:param template: Template. ( Template )
:param loaderScriptPath: Loader Script path. ( String )
:return: Method success. ( Boolean )
"""
LOGGER.info("{0} | Starting remote connection!".format(self.__class__.__name__))
templateSectionsFileParser = SectionsFileParser(template.path)
templateSectionsFileParser.read() and templateSectionsFileParser.parse(
rawSections=(self.__templateScriptSection))
connectionType = foundations.parsers.getAttributeCompound("ConnectionType",
templateSectionsFileParser.getValue("ConnectionType", self.__templateRemoteConnectionSection))
if connectionType.value == "Socket":
try:
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.settimeout(2.5)
connection.connect((foundations.strings.toString(self.__tcpClientUi.address), self.__tcpClientUi.port))
socketCommand = foundations.parsers.getAttributeCompound("ExecutionCommand",
templateSectionsFileParser.getValue("ExecutionCommand",
self.__templateRemoteConnectionSection)).value.replace("$loaderScriptPath",
loaderScriptPath)
LOGGER.debug("> Current socket command: '%s'.", socketCommand)
connection.send(socketCommand)
self.__engine.notificationsManager.notify(
"{0} | Socket connection command dispatched!".format(self.__class__.__name__))
dataBack = connection.recv(4096)
LOGGER.debug("> Received from connection: '{0}'.".format(dataBack))
connection.close()
LOGGER.info("{0} | Closing remote connection!".format(self.__class__.__name__))
except socket.timeout as error:
LOGGER.info("{0} | Closing remote connection on timeout!".format(self.__class__.__name__))
except Exception as error:
raise sibl_gui.exceptions.SocketConnectionError(
"{0} | Socket connection error: '{1}'!".format(self.__class__.__name__, error))
elif connectionType.value == "Win32":
if platform.system() == "Windows" or platform.system() == "Microsoft":
try:
import win32com.client
connection = win32com.client.Dispatch(foundations.parsers.getAttributeCompound("TargetApplication",
templateSectionsFileParser.getValue("TargetApplication",
self.__templateRemoteConnectionSection)).value)
connection._FlagAsMethod(self.__win32ExecutionMethod)
connectionCommand = foundations.parsers.getAttributeCompound("ExecutionCommand",
templateSectionsFileParser.getValue("ExecutionCommand",
self.__templateRemoteConnectionSection)).value.replace("$loaderScriptPath",
loaderScriptPath)
LOGGER.debug("> Current connection command: '%s'.", connectionCommand)
getattr(connection, self.__win32ExecutionMethod)(connectionCommand)
self.__engine.notificationsManager.notify(
"{0} | Win32 connection command dispatched!".format(self.__class__.__name__))
except Exception as error:
raise sibl_gui.exceptions.Win32OLEServerConnectionError(
"{0} | Win32 OLE server connection error: '{1}'!".format(self.__class__.__name__, error))
return True
示例3: initializeProfile
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def initializeProfile(self):
"""
Initializes the Component Profile.
:return: Method success.
:rtype: bool
"""
LOGGER.debug("> Building '{0}' profile.".format(self.__file))
sectionsFileParser = SectionsFileParser(self.__file)
sectionsFileParser.parse()
if sectionsFileParser.sections:
fileStructureParsingError = lambda attribute: foundations.exceptions.FileStructureParsingError(
"{0} | No '{1}' attribute found, '{2}' file structure seems invalid!".format(
self.__class__.__name__, attribute, self.__file))
self.__directory = os.path.dirname(self.__file)
self.__name = sectionsFileParser.getValue("Name", "Component", default=None)
if self.__name is None:
raise fileStructureParsingError("Name")
self.__title = sectionsFileParser.getValue("Title", "Component", default=None)
if self.__title is None:
self.__title = self.__name
self.__package = sectionsFileParser.getValue("Module", "Component", default=None)
if self.__package is None:
raise fileStructureParsingError("Module")
self.__attribute = sectionsFileParser.getValue("Object", "Component", default=None)
if self.__attribute is None:
raise fileStructureParsingError("Object")
self.__require = sectionsFileParser.getValue("Require", "Component", default=None)
self.__require = list() if self.__require is None else self.__require.split("|")
self.__version = sectionsFileParser.getValue("Version", "Component", default=None)
if self.__version is None:
raise fileStructureParsingError("Version")
self.__author = sectionsFileParser.getValue("Author", "Informations", default=None)
self.__email = sectionsFileParser.getValue("Email", "Informations", default=None)
self.__url = sectionsFileParser.getValue("Url", "Informations", default=None)
self.__description = sectionsFileParser.getValue("Description", "Informations", default=None)
return True
else:
raise foundations.exceptions.FileStructureParsingError(
"{0} | No sections found, '{1}' file structure seems invalid!".format(self.__class__.__name__, self.__file))
示例4: testGetValue
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def testGetValue(self):
"""
This method tests :meth:`foundations.parsers.SectionsFileParser.getValue` method.
"""
for type, file in STANDARD_FILES.iteritems():
sectionsFileParser = SectionsFileParser(file)
sectionsFileParser.read() and sectionsFileParser.parse(False, rawSections=STANDARD_FILES_RAW_SECTIONS[type])
for attribute, value in RANDOM_ATTRIBUTES[type].iteritems():
self.assertIsInstance(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
rootOnly=True)), str)
self.assertIsInstance(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
rootOnly=True),
encode=True), unicode)
self.assertEqual(sectionsFileParser.getValue(attribute, namespace.getNamespace(attribute,
rootOnly=True)), value)
示例5: getIblSetImagesPaths
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def getIblSetImagesPaths(self, iblSet, imageType):
"""
This method gets Ibl Set images paths.
:param iblSet: Ibl Set. ( IblSet )
:param imageType: Image type. ( String )
:return: Images paths. ( List )
"""
imagePaths = []
if imageType == "Background":
path = iblSet.backgroundImage
path and imagePaths.append(path)
elif imageType == "Lighting":
path = iblSet.lightingImage
path and imagePaths.append(path)
elif imageType == "Reflection":
path = iblSet.reflectionImage
path and imagePaths.append(path)
elif imageType == "Plate":
if foundations.common.pathExists(iblSet.path):
LOGGER.debug("> Parsing Inspector Ibl Set file: '{0}'.".format(iblSet))
sectionsFileParser = SectionsFileParser(iblSet.path)
sectionsFileParser.read() and sectionsFileParser.parse()
for section in sectionsFileParser.sections:
if re.search(r"Plate\d+", section):
imagePaths.append(os.path.normpath(os.path.join(os.path.dirname(iblSet.path),
sectionsFileParser.getValue("PLATEfile", section))))
for path in imagePaths[:]:
if not foundations.common.pathExists(path):
imagePaths.remove(path) and LOGGER.warning(
"!> {0} | '{1}' image file doesn't exists and will be skipped!".format(self.__class__.__name__, path))
return imagePaths
示例6: testGetValue
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def testGetValue(self):
"""
Tests :meth:`foundations.parsers.SectionsFileParser.getValue` method.
"""
for type, file in STANDARD_FILES.iteritems():
sectionsFileParser = SectionsFileParser(file, preserveOrder=False)
sectionsFileParser.parse(rawSections=STANDARD_FILES_RAW_SECTIONS[type])
for attribute, value in RANDOM_ATTRIBUTES[type].iteritems():
self.assertEqual(
sectionsFileParser.getValue(
attribute, foundations.namespace.getNamespace(attribute, rootOnly=True)
),
value,
)
self.assertEqual(sectionsFileParser.getValue("attribute", "section", default=None), None)
self.assertEqual(sectionsFileParser.getValue("attribute", "section", default=list()), list())
示例7: listTemplatesReleases
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def listTemplatesReleases():
"""
This definition lists Templates releases.
"""
for template in sorted(list(foundations.walkers.filesWalker(os.path.normpath(TEMPLATES_PATH), (TEMPLATES_EXTENSION,), ("\._",)))):
sectionsFileParser = SectionsFileParser(template)
sectionsFileParser.read() and sectionsFileParser.parse(rawSections=("Script",))
LOGGER.info("{0} | '{1}': '{2}'.".format(listTemplatesReleases.__name__,
foundations.strings.getSplitextBasename(template),
foundations.parsers.getAttributeCompound("Release",
sectionsFileParser.getValue("Release", "Template")).value))
示例8: testParseInternational
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def testParseInternational(self):
"""
Tests :meth:`foundations.parsers.SectionsFileParser.parse` in international specific context.
"""
sectionsFileParser = SectionsFileParser(CHINESE_IBL_SET_FILE)
sectionsFileParser.parse()
for attribute, value in CHINESE_IBL_SET_FILE_RANDOM_ATTRIBUTES.iteritems():
self.assertEqual(
value,
sectionsFileParser.getValue(
foundations.namespace.getLeaf(attribute), foundations.namespace.getRoot(attribute)
),
)
示例9: setContent
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def setContent(self):
"""
Initializes the class attributes.
:return: Method success.
:rtype: bool
"""
sectionsFileParser = SectionsFileParser(self.path)
sectionsFileParser.parse(rawSections=("Script"))
if sectionsFileParser.sections:
self.helpFile = foundations.parsers.getAttributeCompound("HelpFile",
sectionsFileParser.getValue("HelpFile", "Template")).value and \
os.path.join(os.path.dirname(self.path),
foundations.parsers.getAttributeCompound("HelpFile",
sectionsFileParser.getValue("HelpFile", "Template")).value) or None
self.title = foundations.parsers.getAttributeCompound("Name",
sectionsFileParser.getValue("Name", "Template")).value
self.author = foundations.parsers.getAttributeCompound("Author",
sectionsFileParser.getValue("Author", "Template")).value
self.email = foundations.parsers.getAttributeCompound("Email",
sectionsFileParser.getValue("Email", "Template")).value
self.url = foundations.parsers.getAttributeCompound("Url",
sectionsFileParser.getValue("Url", "Template")).value
self.release = foundations.parsers.getAttributeCompound("Release",
sectionsFileParser.getValue("Release", "Template")).value
self.date = foundations.parsers.getAttributeCompound("Date",
sectionsFileParser.getValue("Date", "Template")).value
self.software = foundations.parsers.getAttributeCompound("Software",
sectionsFileParser.getValue("Software", "Template")).value
self.version = foundations.parsers.getAttributeCompound("Version",
sectionsFileParser.getValue("Version", "Template")).value
self.renderer = foundations.parsers.getAttributeCompound("Renderer",
sectionsFileParser.getValue("Renderer", "Template")).value
self.outputScript = foundations.parsers.getAttributeCompound("OutputScript",
sectionsFileParser.getValue("OutputScript", "Template")).value
self.comment = foundations.parsers.getAttributeCompound("Comment",
sectionsFileParser.getValue("Comment", "Template")).value
return True
else:
raise foundations.exceptions.FileStructureParsingError(
"{0} | '{1}' no sections found, file structure seems invalid!".format(self.__class__.__name__, self.path))
示例10: __releasesFileReply__finished
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def __releasesFileReply__finished(self):
"""
Defines the slot triggered by the releases file reply when finished.
"""
self.__engine.stopProcessing()
if not self.__releasesFileReply.error():
content = []
while not self.__releasesFileReply.atEnd ():
content.append(foundations.strings.toString(self.__releasesFileReply.readLine()))
LOGGER.debug("> Parsing releases file content.")
sectionsFileParser = SectionsFileParser()
sectionsFileParser.content = content
sectionsFileParser.parse()
releases = {}
for remoteObject in sectionsFileParser.sections:
if remoteObject != Constants.applicationName:
databaseTemplates = \
sibl_gui.components.core.database.operations.filterTemplates("^{0}$".format(remoteObject), "name")
databaseTemplate = foundations.common.getFirstItem([foundations.common.getFirstItem(databaseTemplate)
for databaseTemplate in sorted(((databaseTemplate, databaseTemplate.release)
for databaseTemplate in databaseTemplates),
reverse=True,
key=lambda x:(foundations.strings.getVersionRank(x[1])))])
if not self.__engine.parameters.databaseReadOnly:
if databaseTemplate:
if databaseTemplate.release != sectionsFileParser.getValue("Release", remoteObject):
releases[remoteObject] = ReleaseObject(name=remoteObject,
repositoryVersion=sectionsFileParser.getValue(
"Release", remoteObject),
localVersion=databaseTemplate.release,
type=sectionsFileParser.getValue("Type",
remoteObject),
url=sectionsFileParser.getValue("Url",
remoteObject),
comment=sectionsFileParser.getValue("Comment",
remoteObject))
else:
if not self.Ignore_Non_Existing_Templates_checkBox.isChecked():
releases[remoteObject] = ReleaseObject(name=remoteObject,
repositoryVersion=sectionsFileParser.getValue(
"Release", remoteObject),
localVersion=None,
type=sectionsFileParser.getValue("Type",
remoteObject),
url=sectionsFileParser.getValue("Url",
remoteObject),
comment=sectionsFileParser.getValue("Comment",
remoteObject))
else:
LOGGER.info("{0} | '{1}' repository remote object skipped by '{2}' command line parameter value!".format(
self.__class__.__name__, remoteObject, "databaseReadOnly"))
else:
if Constants.version != sectionsFileParser.getValue("Release", remoteObject):
releases[remoteObject] = ReleaseObject(name=remoteObject,
repositoryVersion=sectionsFileParser.getValue("Release",
remoteObject),
localVersion=Constants.version,
url=sectionsFileParser.getValue("Url", remoteObject),
type=sectionsFileParser.getValue("Type", remoteObject),
comment=None)
if releases:
LOGGER.debug("> Initializing Remote Updater.")
self.__remoteUpdater = RemoteUpdater(self, releases, Qt.Window)
self.__remoteUpdater.show()
else:
self.__reportUpdateStatus and self.__engine.notificationsManager.notify(
"{0} | '{1}' is up to date!".format(self.__class__.__name__, Constants.applicationName))
else:
raise sibl_gui.exceptions.NetworkError("{0} | QNetworkAccessManager error code: '{1}'.".format(
self.__class__.__name__, self.__releasesFileReply.error()))
示例11: getLoaderScript
# 需要導入模塊: from foundations.parsers import SectionsFileParser [as 別名]
# 或者: from foundations.parsers.SectionsFileParser import getValue [as 別名]
def getLoaderScript(self, template, iblSet, overrideKeys):
"""
This method builds a Loader Script.
:param template: Template path. ( String )
:param iblSet: Ibl Set path. ( String )
:param overrideKeys: Override keys. ( Dictionary )
:return: Loader Script. ( List )
"""
LOGGER.debug("> Parsing Template file: '{0}'.".format(template))
templateSectionsFileParser = SectionsFileParser(template)
templateSectionsFileParser.read() and templateSectionsFileParser.parse(
rawSections=(self.__templateScriptSection))
templateSections = dict.copy(templateSectionsFileParser.sections)
for attribute, value in dict.copy(templateSections[self.__templateIblSetAttributesSection]).iteritems():
templateSections[self.__templateIblSetAttributesSection][foundations.namespace.removeNamespace(attribute,
rootOnly=True)] = value
del templateSections[self.__templateIblSetAttributesSection][attribute]
LOGGER.debug("> Binding Templates file attributes.")
bindedAttributes = dict(((attribute, foundations.parsers.getAttributeCompound(attribute, value))
for section in templateSections if section not in (self.__templateScriptSection)
for attribute, value in templateSections[section].iteritems()))
LOGGER.debug("> Parsing Ibl Set file: '{0}'.".format(iblSet))
iblSetSectionsFileParser = SectionsFileParser(iblSet)
iblSetSectionsFileParser.read() and iblSetSectionsFileParser.parse()
iblSetSections = dict.copy(iblSetSectionsFileParser.sections)
LOGGER.debug("> Flattening Ibl Set file attributes.")
flattenedIblAttributes = dict(((attribute, foundations.parsers.getAttributeCompound(attribute, value))
for section in iblSetSections
for attribute, value in iblSetSections[section].iteritems()))
for attribute in flattenedIblAttributes:
if attribute in bindedAttributes:
bindedAttributes[attribute].value = flattenedIblAttributes[attribute].value
if "Lights|DynamicLights" in bindedAttributes:
LOGGER.debug("> Building '{0}' custom attribute.".format("Lights|DynamicLights"))
dynamicLights = []
for section in iblSetSections:
if re.search(r"Light\d+", section):
dynamicLights.append(section)
lightName = iblSetSectionsFileParser.getValue("LIGHTname", section)
dynamicLights.append(lightName and lightName or self.__unnamedLightName)
lightColorTokens = iblSetSectionsFileParser.getValue("LIGHTcolor", section).split(",")
for color in lightColorTokens:
dynamicLights.append(color)
dynamicLights.append(iblSetSectionsFileParser.getValue("LIGHTmulti", section))
dynamicLights.append(iblSetSectionsFileParser.getValue("LIGHTu", section))
dynamicLights.append(iblSetSectionsFileParser.getValue("LIGHTv", section))
LOGGER.debug("> Adding '{0}' custom attribute with value: '{1}'.".format("Lights|DynamicLights",
", ".join(dynamicLights)))
bindedAttributes["Lights|DynamicLights"].value = self.__defaultStringSeparator.join(dynamicLights)
LOGGER.debug("> Updating attributes with override keys.")
for attribute in overrideKeys:
if attribute in bindedAttributes:
bindedAttributes[attribute].value = overrideKeys[attribute] and overrideKeys[attribute].value or None
LOGGER.debug("> Updating Loader Script content.")
loaderScript = templateSectionsFileParser.sections[
self.__templateScriptSection][templateSectionsFileParser.rawSectionContentIdentifier]
boundLoaderScript = []
for line in loaderScript:
bindingParameters = re.findall(r"{0}".format(self.__bindingIdentifierPattern), line)
if bindingParameters:
for parameter in bindingParameters:
for attribute in bindedAttributes.itervalues():
if not parameter == attribute.link:
continue
LOGGER.debug("> Updating Loader Script parameter '{0}' with value: '{1}'.".format(parameter,
attribute.value))
line = line.replace(parameter, attribute.value if attribute.value else "-1")
boundLoaderScript.append(line)
return boundLoaderScript