本文整理汇总了Python中lxml.etree.parse方法的典型用法代码示例。如果您正苦于以下问题:Python etree.parse方法的具体用法?Python etree.parse怎么用?Python etree.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree
的用法示例。
在下文中一共展示了etree.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def list():
""" get list of all collection entries """
cols_elem = ET.Element('collections')
for col in Col.objects.all():
path = os.path.join('data', 'collections', col.name)
if not os.path.exists(path):
logging.error('Collection has inconstancy : %s !!' % col.name)
continue
files = glob.glob(os.path.join(path, '*'))
for _file in files:
payload = ET.parse(_file)
for child in payload.getroot():
if child.tag == 'metadata':
cols_elem.append(child)
return cols_elem
示例2: project_status_requests
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def project_status_requests(self, request_type, filter_function=None):
requests = []
for status in self.project_status(None, status=False):
for request in status.findall(f'{request_type}_requests/request'):
updated_at = dateutil.parser.parse(request.get('updated'), ignoretz=True)
updated_delta = datetime.utcnow() - updated_at
if updated_delta.total_seconds() < 0 * 60:
# Allow for dashboard to update caches by not considering
# requests whose state has changed in the last 5 minutes.
continue
if filter_function and not filter_function(request, updated_delta):
continue
requests.append(str(request.get('id')))
return requests
示例3: ensure_staging_archs
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def ensure_staging_archs(self, project):
meta = ET.parse(http_GET(self.project_meta_url(project)))
repository = meta.find('repository[@name="{}"]'.format(self.cmain_repo))
changed = False
for arch in self.cstaging_archs:
if not repository.xpath('./arch[text()="{}"]'.format(arch)):
elm = ET.SubElement(repository, 'arch')
elm.text = arch
changed = True
if not changed:
return
meta = ET.tostring(meta)
http_PUT(self.project_meta_url(project), data=meta)
示例4: package_source_hash
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def package_source_hash(apiurl, project, package, revision=None):
query = {}
if revision:
query['rev'] = revision
# Will not catch packages that previous had a link, but no longer do.
if package_source_link_copy(apiurl, project, package):
query['expand'] = 1
try:
url = makeurl(apiurl, ['source', project, package], query)
root = ETL.parse(http_GET(url)).getroot()
except HTTPError as e:
if e.code == 400 or e.code == 404:
# 400: revision not found, 404: package not found.
return None
raise e
if revision and root.find('error') is not None:
# OBS returns XML error instead of HTTP 404 if revision not found.
return None
from osclib.util import sha1_short
return sha1_short(root.xpath('entry[@name!="_link"]/@md5'))
示例5: find_via_stagingapi
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def find_via_stagingapi(self, pkgs):
"""
Search for all various mutations and return list of SR#s. Use
and instance of StagingAPI to direct the search, this makes
sure that the SR# are inside a staging project.
:param pkgs: mesh of argumets to search for
This function is only called for its side effect.
"""
url = self.api.makeurl(['staging', self.api.project, 'staging_projects'], { 'requests': 1 })
status = ET.parse(self.api.retried_GET(url)).getroot()
for p in pkgs:
found = False
for staging in status.findall('staging_project'):
for request in staging.findall('staged_requests/request'):
if request.get('package') == p or request.get('id') == p:
self.srs[int(request.get('id'))] = {'staging': staging.get('name')}
found = True
break
if not found:
raise oscerr.WrongArgs('No SR# found for: {}'.format(p))
示例6: getlabel
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def getlabel(self,xmlPath):
tree = ET.parse(xmlPath)
root = tree.getroot()
print(root[6][0].text)
示例7: __init__
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def __init__(self, file_path):
tree = etree.parse(file_path)
self.__root = xpath(tree.getroot(), './tei:text/tei:body', self.ns)[0]
示例8: get_session_config
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def get_session_config(username):
session = ET.Element('session')
user = ET.Element('username')
user.text = username
session.append(user)
if username != '':
# Pass global static configuration data
_global = ET.parse(os.path.join('static', 'global-config.xml')).getroot()
session.append(_global)
return session
示例9: __init__
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def __init__(self, filename):
self.modules = {}
logging.debug('Parsing %s !!' % filename)
root = ET.parse(filename).getroot()
for child in root:
module = DYModule(child)
self.modules[module.name] = module
for name in self.modules:
module = self.modules[name]
for imp in module.imports:
i_module = self.modules.get(imp, None)
if i_module is None:
logging.warning('Dependent modules %s not found in dependency list !!' % imp)
continue
if imp not in i_module.depends:
i_module.depends.append(name)
for inc in module.includes:
i_module = self.modules.get(inc, None)
if i_module is None:
logging.warning('Included modules %s not found in dependency list !!' % inc)
continue
if inc not in i_module.depends:
i_module.depends.append(name)
示例10: __init__
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def __init__(self, filename):
self.filename = filename
self.modulename = os.path.splitext(os.path.basename(filename))[0]
if os.path.exists(filename):
logging.debug('Parsing %s' % filename)
try:
self.cxml = ET.parse(filename)
except:
self.cxml = None
logging.error('ET Failed to parse %s' % filename)
else:
self.cxml = None
logging.error('File %s does not exists' % filename)
示例11: check_arch
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def check_arch(self, project, repository, architecture):
url = makeurl(self.apiurl, [
'build', project, repository, architecture], {'view': 'status'})
root = ET.parse(http_GET(url)).getroot()
if root.get('code') == 'finished':
buildid = root.find('buildid')
if buildid is not None:
return buildid.text
示例12: gather_isos
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def gather_isos(self, name, repository):
url = self.api.makeurl(['published', name, repository, 'iso'])
f = self.api.retried_GET(url)
root = ET.parse(f).getroot()
ret = []
for entry in root.findall('entry'):
if entry.get('name').endswith('iso'):
ret.append(self.map_iso(name, entry.get('name')))
return ret
示例13: gather_buildid
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def gather_buildid(self, name, repository):
url = self.api.makeurl(['published', name, repository], {'view': 'status'})
f = self.api.retried_GET(url)
id = ET.parse(f).getroot().find('buildid')
if id is not None:
return id.text
示例14: build_summary
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def build_summary(self, project, repository):
url = makeurl(self.apiurl, ['build', project, '_result'], { 'repository': repository, 'view': 'summary' })
try:
f = http_GET(url)
except HTTPError as e:
return { 'building': -1 }
root = ET.parse(f).getroot()
failed = 0
unresolvable = 0
building = 0
succeeded = 0
for result in root.findall('.//statuscount'):
code = result.get('code')
count = int(result.get('count'))
if code == 'excluded' or code == 'disabled':
continue # ignore
if code == 'succeeded':
succeeded += count
continue
if code == "failed":
failed += count
continue
if code == "unresolvable":
unresolvable += count
continue
building += count
#print(code, file=sys.stderr)
# let's count them as building
if building > 0:
building += unresolvable
unresolvable = 0
if building + failed + succeeded == 0:
return {'building': -1}
return { 'building': 1000 - int(building * 1000 / (building + failed + succeeded)),
'failed': failed,
'unresolvable': unresolvable }
示例15: mirror
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import parse [as 别名]
def mirror(apiurl, project, repository, arch):
"""Call bs_mirrorfull script to mirror packages."""
directory = os.path.join(CACHEDIR, project, repository, arch)
if not os.path.exists(directory):
os.makedirs(directory)
meta = ETL.parse(http_GET('{}/public/source/{}/_meta'.format(apiurl, project))).getroot()
repotag = meta.xpath("/project/repository[@name='{}']".format(repository))[0]
if arch not in repotag.xpath("./arch/text()"):
# Arch not in this project, skip mirroring
return directory
download = repotag.xpath("./download[@arch='{}']".format(arch))
if download is not None and len(download) > 0:
if len(download) > 1:
raise Exception('Multiple download urls unsupported')
repotype = download[0].get('repotype')
if repotype != 'rpmmd':
raise Exception('repotype {} not supported'.format(repotype))
return mirrorRepomd(directory, download[0].get('url'))
script = os.path.join(SCRIPT_PATH, '..', 'bs_mirrorfull')
path = '/'.join((project, repository, arch))
logger.info('mirroring {}'.format(path))
url = '{}/public/build/{}'.format(apiurl, path)
p = subprocess.run(['perl', script, '--nodebug', url, directory])
if p.returncode:
raise Exception('failed to mirror {}'.format(path))
return directory