本文整理汇总了Python中xml.etree.ElementTree.XML.findtext方法的典型用法代码示例。如果您正苦于以下问题:Python XML.findtext方法的具体用法?Python XML.findtext怎么用?Python XML.findtext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.XML
的用法示例。
在下文中一共展示了XML.findtext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import findtext [as 别名]
def download(job, regex):
"""Grabs platform specific distribution targets from Hudson"""
url = urllib.urlopen("/".join([HUDSON_ROOT, job, HUDSON_XML_SUFFIX]))
hudson_xml = url.read()
hudson_xml = hudson_xml.replace('origin/', 'origin_')
url.close()
root = XML(hudson_xml)
building = root.findtext("./building")
if building == 'true':
print '%s build in progress, exiting...' % job
sys.exit(1)
revision = root.findtext("./changeSet/revision/revision")
artifacts = root.findall("./artifact")
print "Retrieving %s job artifacts from revision: %s" % (job, revision)
base_url = "/".join([HUDSON_ROOT, job, 'lastSuccessfulBuild/artifact'])
new_artifacts = list()
for artifact in artifacts:
filename = artifact.findtext("fileName")
if not regex.match(filename):
continue
artifact_url = "/".join([base_url, artifact.findtext("relativePath")])
print "Downloading %s from URL %s" % (filename, artifact_url)
urllib.urlretrieve(artifact_url , filename)
new_artifacts.append(filename)
return [revision, new_artifacts]
示例2: post
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import findtext [as 别名]
def post(self, request, *args, **kwargs):
notify_xml = XML(request.raw_post_data)
self.notify_type = self._extract_notify_type(notify_xml)
self.notify_type_const = \
GoogleOrder.trans_notify_type_const(self.notify_type)
ts_utc = dt_parse(notify_xml.findtext(xpq_timestamp))
self.timestamp = self._trans_utc_to_local(ts_utc)
self.serial_number = notify_xml.get('serial-number')
self.order_number = long(notify_xml.findtext(xpq_order_number))
backend_class = get_backend_class(ngc_settings.BACKEND)
self.backend = backend_class(request, notify_xml=notify_xml)
self.cart = self.backend.get_cart()
# if we don't find a cart, we do actually go ahead and continue
# processing. The idea is the data npo_google_checkout holds should
# match all of what google checkout holds
msg_target = "cart '{0}'".format(self.cart) \
if self.cart else 'unknown cart'
msg = "GC {0} #{1} received for {2}.".format(
self.notify_type, self.serial_number, msg_target),
logger.info(msg, extra={'request': request})
# notification type-specific handling
if self.notify_type_const == GoogleOrder.NEW_ORDER_NOTIFY_TYPE:
self._post_new_order(notify_xml)
else:
try:
order = GoogleOrder.objects.get(number=self.order_number)
except GoogleOrder.DoesNotExist:
order = None
else:
order.last_notify_type = self.notify_type_const
order.last_notify_dt = self.timestamp
if not order:
# silently ignore notifications for orders we didn't see the
# new-order-notification for
pass
elif self.notify_type_const == GoogleOrder.ORDER_STATE_CHANGE_NOTIFY_TYPE:
self._post_order_state_change(order, notify_xml)
elif self.notify_type_const == GoogleOrder.RISK_INFORMATION_NOTIFY_TYPE:
self._post_risk_informaiton(order, notify_xml)
elif self.notify_type_const == GoogleOrder.AUTHORIZATION_AMOUNT_NOTIFY_TYPE:
self._post_authorization_amount(order, notify_xml)
elif self.notify_type_const == GoogleOrder.CHARGE_AMOUNT_NOTIFY_TYPE:
self._post_charge_amount(order, notify_xml)
else:
msg = "Unrecognized notification '{0}' recieved". \
format(self.notify_type)
raise RuntimeError(msg)
return super(NotificationListenerView, self).get(
request, *args, **kwargs)
示例3: getAllArtifactVersions
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import findtext [as 别名]
def getAllArtifactVersions(self, strGroupID, strArtifactID):
atVersions = []
strPath = self.strUrlLuceneSearchGA % (strGroupID, strArtifactID)
aucContent = self.tRestDriver.get(self.tServerBaseUrl, strPath)
tSearchResult = XML(aucContent)
# The search result must be complete.
if tSearchResult.findtext('tooManyResults')!='false':
raise Exception("Received a truncated search result!")
# Loop over all results.
for tNode in tSearchResult.findall('data/artifact'):
strVersion = tNode.findtext('version')
if isinstance(strVersion, basestring)==True:
strVersion = strVersion.strip()
if strVersion=='SNAPSHOT':
tVersion = deploy_version.version(0, 0, 0)
else:
tVersion = deploy_version.version(strVersion)
atVersions.append(tVersion)
# Sort the versions.
atVersions.sort()
return atVersions
示例4: findSha1Artifacts
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import findtext [as 别名]
def findSha1Artifacts(self, strFileName, strGroupID, strArtifactID):
atVersions = []
# Generate the SHA1 sum for the file.
strFileSha1 = self.generate_sha1_from_file(strFileName)
strPath = self.strUrlLuceneSearchSha1 % strFileSha1
aucContent = self.tRestDriver.get(self.tServerBaseUrl, strPath)
tSearchResult = XML(aucContent)
# The search result must be complete.
if tSearchResult.findtext('tooManyResults')!='false':
raise Exception("Received a truncated search result!")
# Loop over all results.
for tNode in tSearchResult.findall('data/artifact'):
strG = tNode.findtext('groupId')
strA = tNode.findtext('artifactId')
strVersion = tNode.findtext('version')
if isinstance(strG, basestring)==True and isinstance(strA, basestring)==True and isinstance(strVersion, basestring)==True:
strG = strG.strip()
strA = strA.strip()
strVersion = strVersion.strip()
if strGroupID==strG and strArtifactID==strA:
if strVersion=='SNAPSHOT':
tVersion = deploy_version.version(0, 0, 0)
else:
tVersion = deploy_version.version(strVersion)
atVersions.append(tVersion)
atVersions.sort()
return atVersions
示例5: svn_log
# 需要导入模块: from xml.etree.ElementTree import XML [as 别名]
# 或者: from xml.etree.ElementTree.XML import findtext [as 别名]
def svn_log(pkgbase, repo):
'''Retrieve the most recent SVN log entry for the given pkgbase and
repository. The configured setting SVN_BASE_URL is used along with the
svn_root for each repository to form the correct URL.'''
path = '%s%s/%s/trunk/' % (settings.SVN_BASE_URL, repo.svn_root, pkgbase)
cmd = ['svn', 'log', '--limit=1', '--xml', path]
log_data = subprocess.check_output(cmd)
# the XML format is very very simple, especially with only one revision
xml = XML(log_data)
revision = int(xml.find('logentry').get('revision'))
date = datetime.strptime(xml.findtext('logentry/date'),
'%Y-%m-%dT%H:%M:%S.%fZ')
return {
'revision': revision,
'date': date,
'author': xml.findtext('logentry/author'),
'message': xml.findtext('logentry/msg'),
}