Python xml.etree.cElementTree.ParseError() Examples
The following are 30
code examples of xml.etree.cElementTree.ParseError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
xml.etree.cElementTree
, or try the search function
.
Example #1
Source File: tv_grab_es_movistartv.py From tv_grab_es_movistartv with GNU General Public License v3.0 | 6 votes |
def __get_packages(xml): root = ElTr.fromstring(xml.replace('\n', ' ')) packages = root[0].findall("{urn:dvb:ipisdns:2006}Package") package_list = {} for package in packages: package_name = 'unknown' try: package_name = package[0].text package_list[package_name] = { 'id': package.attrib['Id'], 'name': package_name, 'services': {}} for service in package: if not service.tag == '{urn:dvb:ipisdns:2006}PackageName': service_id = service[0].attrib['ServiceName'] package_list[package_name]['services'][service_id] = service[1].text except (KeyError, ElTr.ParseError) as ex: logger.error('El paquete %s no tiene la estructura correcta: %s' % (package_name, str(ex.args))) logger.info('Paquetes: %i' % len(package_list)) return package_list
Example #2
Source File: tzconvert.py From ccs-pycalendar with Apache License 2.0 | 6 votes |
def parseWindowsAliases(self, aliases): try: with open(aliases) as xmlfile: xmlroot = XML.ElementTree(file=xmlfile).getroot() except (IOError, XMLParseError): raise ValueError("Unable to open or read windows alias file: {}".format(aliases)) # Extract the mappings try: for elem in xmlroot.findall("./windowsZones/mapTimezones/mapZone"): if elem.get("territory", "") == "001": if elem.get("other") not in self.links: self.links[elem.get("other")] = elem.get("type") else: print("Ignoring duplicate Windows alias: {}".format(elem.get("other"))) except (ValueError, KeyError): raise ValueError("Unable to parse windows alias file: {}".format(aliases))
Example #3
Source File: arya.py From arya with Apache License 2.0 | 6 votes |
def isxmlorjson(s): try: json.loads(s) isjson = True except ValueError: isjson = False try: ETree.ElementTree(ETree.fromstring(s)) isxml = True except ETree.ParseError: isxml = False if isjson and isxml: raise ValueError('This file appears to be both XML and JSON. I am ' + 'confused. Goodbye') if isjson: return 'json' elif isxml: return 'xml' else: return None
Example #4
Source File: rssbot.py From abusehelper with MIT License | 5 votes |
def _poll(self, url): request = urllib2.Request(url) for key, value in self.http_headers: request.add_header(key, value) try: self.log.info('Downloading feed from: "%s"', url) _, fileobj = yield utils.fetch_url(request) except utils.FetchUrlFailed as e: self.log.error('Failed to download feed "%s": %r', url, e) idiokit.stop(False) self.log.info("Finished downloading the feed.") byte = fileobj.read(1) while byte and byte != "<": byte = fileobj.read(1) if byte == "<": fileobj.seek(-1, 1) try: for _, elem in etree.iterparse(fileobj): for event in self._parse(elem, url): if event: yield idiokit.send(event) except ParseError as e: self.log.error('Invalid format on feed: "%s", "%r"', url, e)
Example #5
Source File: tunein.py From AlexaPi with MIT License | 5 votes |
def parse_new_asx(data): # Copied from mopidy.audio.playlists try: for _, element in elementtree.iterparse(data): element.tag = element.tag.lower() # normalize for ref in element.findall('entry/ref[@href]'): yield fix_asf_uri(ref.get('href', '').strip()) for entry in element.findall('entry[@href]'): yield fix_asf_uri(entry.get('href', '').strip()) except elementtree.ParseError: return
Example #6
Source File: pascal_voc.py From PL-ZSD_Release with MIT License | 5 votes |
def load_annotations(self, image_index): filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #7
Source File: __init__.py From uniconvertor with GNU Affero General Public License v3.0 | 5 votes |
def check_svg(path): tag = None fileptr = get_fileptr(path) try: for event, el in cElementTree.iterparse(fileptr, ('start',)): tag = el.tag break except cElementTree.ParseError: pass finally: fileptr.close() return tag == '{http://www.w3.org/2000/svg}svg' or tag == 'svg'
Example #8
Source File: pascal_voc.py From keras-m2det with Apache License 2.0 | 5 votes |
def load_annotations(self, image_index): """ Load annotations for an image_index. """ filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #9
Source File: utils.py From dvhb-hybrid with MIT License | 5 votes |
def validate_svg_file(f): tag = None f.seek(0) try: for event, el in xml_et.iterparse(f, ('start',)): tag = el.tag break except xml_et.ParseError: pass if tag != '{http://www.w3.org/2000/svg}svg': raise ValidationError('Uploaded file is not an image or SVG file') f.seek(0) return f
Example #10
Source File: pascal_voc.py From keras-retinanet with Apache License 2.0 | 5 votes |
def load_annotations(self, image_index): """ Load annotations for an image_index. """ filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #11
Source File: convert.py From pubrunner with MIT License | 5 votes |
def pmcxml2bioc(pmcxmlFilename, biocFilename): try: with bioc.BioCXMLDocumentWriter(biocFilename) as writer: for pmcDoc in processPMCFile(pmcxmlFilename): biocDoc = bioc.BioCDocument() biocDoc.id = pmcDoc["pmid"] biocDoc.infons['title'] = " ".join(pmcDoc["textSources"]["title"]) biocDoc.infons['pmid'] = pmcDoc["pmid"] biocDoc.infons['pmcid'] = pmcDoc["pmcid"] biocDoc.infons['doi'] = pmcDoc["doi"] biocDoc.infons['year'] = pmcDoc["pubYear"] biocDoc.infons['month'] = pmcDoc["pubMonth"] biocDoc.infons['day'] = pmcDoc["pubDay"] biocDoc.infons['journal'] = pmcDoc["journal"] biocDoc.infons['journalISO'] = pmcDoc["journalISO"] offset = 0 for groupName,textSourceGroup in pmcDoc["textSources"].items(): subsection = None for textSource in textSourceGroup: textSource = trimSentenceLengths(textSource) passage = bioc.BioCPassage() subsectionCheck = textSource.lower().strip('01234567890. ') if subsectionCheck in allowedSubsections: subsection = subsectionCheck passage.infons['section'] = groupName passage.infons['subsection'] = subsection passage.text = textSource passage.offset = offset offset += len(textSource) biocDoc.add_passage(passage) writer.write_document(biocDoc) except etree.ParseError: raise RuntimeError("Parsing error in PMC xml file: %s" % pmcxmlFilename)
Example #12
Source File: nmap.py From Saker with GNU General Public License v3.0 | 5 votes |
def parse(self): try: tree = ET.parse(self.output) except ET.ParseError as e: return except Exception as e: raise e ''' if self.output.startswith('.tmp-nmap'): os.remove(self.output) ''' root = tree.getroot() result = {} filter_flag = True for host in root.findall('host'): ip = host.find('address').get('addr') result[ip] = {} for port in host.find('ports').findall('port'): if port.find('state').get('state') not in ('filtered', 'closed'): filter_flag = False if port.find('state').get('state') == 'open': service = port.find('service') if service is None: continue service = service.attrib if service['name'] == 'tcpwrapped': continue service.pop('conf') service.pop('method') result[ip][port.get('portid')] = service if result[ip] == {}: del result[ip] if not result: if filter_flag: print('All open ports detected by nmap are actually filtered or closed!') else: print('Failed to parse nmap xml!') return None self.result = result return result
Example #13
Source File: xml_util.py From pyxcli with Apache License 2.0 | 5 votes |
def _translateExceptions(original): try: yield None except ExpatError as e: raise XMLSyntaxError(original, e.args[0], e.lineno) except (cet.ParseError, et.ParseError) as e: raise XMLSyntaxError(original, e.args[0], e.lineno)
Example #14
Source File: pascal_voc.py From kaggle-rsna18 with MIT License | 5 votes |
def load_annotations(self, image_index): """ Load annotations for an image_index. """ filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #15
Source File: pascal_voc.py From DeepForest with MIT License | 5 votes |
def load_annotations(self, image_index): """ Load annotations for an image_index. """ filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #16
Source File: pascal_voc.py From ImageAI with MIT License | 5 votes |
def load_annotations(self, image_index): filename = self.image_names[image_index] + '.xml' try: tree = ET.parse(os.path.join(self.data_dir, 'Annotations', filename)) return self.__parse_annotations(tree.getroot()) except ET.ParseError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None) except ValueError as e: raise_from(ValueError('invalid annotations file: {}: {}'.format(filename, e)), None)
Example #17
Source File: heal_libs.py From glusto-tests with GNU General Public License v3.0 | 5 votes |
def is_heal_disabled(mnode, volname): """Check if heal is disabled for a volume. Args: mnode : Node on which commands are executed volname : Name of the volume Returns: bool : True if heal is disabled on volume. False otherwise. NoneType: None if unable to get the volume status shd or parse error. """ cmd = "gluster volume status %s shd --xml" % volname ret, out, _ = g.run(mnode, cmd, log_level='DEBUG') if ret != 0: g.log.error("Failed to get the self-heal-daemon status for the " "volume" % volname) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the volume status shd xml output.") return None operr = root.find("opErrstr") if operr: if "Self-heal Daemon is disabled for volume" in operr.text: return True return False
Example #18
Source File: tiering_ops.py From glusto-tests with GNU General Public License v3.0 | 5 votes |
def tier_detach_start_and_get_taskid(mnode, volname): """Parse the output of 'gluster volume tier detach start' command. Args: mnode (str): Node on which command has to be executed. volname (str): volume name Returns: NoneType: None if command execution fails, parse errors. dict: dict on success. Examples: >>> tier_detach_start_and_get_taskid('abc.lab.eng.xyz.com', "testvol") {'task-id': '8020835c-ff0d-4ea1-9f07-62dd067e92d4'} """ cmd = "gluster volume tier %s detach start --xml" % volname ret, out, _ = g.run(mnode, cmd) if ret != 0: g.log.error("Failed to execute 'detach tier start' on node %s. " "Hence failed to parse the detach tier start.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster detach tier " "start xml output.") return None tier_status = {} for info in root.findall("volDetachTier"): for element in info.getchildren(): tier_status[element.tag] = element.text return tier_status
Example #19
Source File: snap_ops.py From glusto-tests with GNU General Public License v3.0 | 5 votes |
def get_snap_list(mnode, volname=""): """Parse the output of 'gluster snapshot list' command. If a volname is provided then the output will be specific to that volume. Args: mnode (str): Node on which command has to be executed. Kwargs: volname (str): volume name Returns: NoneType: None if command execution fails, parse errors. list: list of snapshots on success. Examples: >>> get_snap_list('abc.lab.eng.xyz.com') ['snap1', 'snap2'] """ cmd = "gluster snapshot list %s --xml" % volname ret, out, _ = g.run(mnode, cmd) if ret != 0: g.log.error("Failed to execute 'snapshot list' on node %s. " "Hence failed to get the snapshot list.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster snapshot " "list xml output.") return None snap_list = [] for snap in root.findall("snapList/snapshot"): snap_list.append(snap.text) return snap_list
Example #20
Source File: heal_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_heal_info_split_brain(mnode, volname): """From the xml output of heal info split-brain command get the heal info split-brain data. Args: mnode : Node on which commands are executed volname : Name of the volume Returns: NoneType: None if parse errors. list: list of dictionaries. Each element in the list is the heal_info_split_brain data per brick. """ cmd = "gluster volume heal %s info split-brain --xml" % volname ret, out, _ = g.run(mnode, cmd, log_level='DEBUG') if ret != 0: g.log.error("Failed to get the heal info xml output for the volume %s." "Hence failed to get the heal info summary." % volname) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster heal info xml output.") return None heal_info_split_brain_data = [] for brick in root.findall("healInfo/bricks/brick"): brick_heal_info_split_brain = {} brick_files_in_split_brain = [] is_file_in_split_brain = False for element in brick.getchildren(): if element.tag == "file": is_file_in_split_brain = True file_info = {} file_info[element.attrib['gfid']] = element.text brick_files_in_split_brain.append(file_info) else: brick_heal_info_split_brain[element.tag] = element.text if is_file_in_split_brain: brick_heal_info_split_brain['file'] = brick_files_in_split_brain heal_info_split_brain_data.append(brick_heal_info_split_brain) return heal_info_split_brain_data
Example #21
Source File: ShimCacheParser_ACP.py From appcompatprocessor with Apache License 2.0 | 4 votes |
def read_zip(zip_name): zip_contents = [] tmp_list = [] final_list = [] out_list = [] hostname = "" try: # Open the zip archive. archive = zipfile.ZipFile(zip_name) for zip_file in archive.infolist(): zip_contents.append(zip_file.filename) print "[+] Processing %d registry acquisitions..." % len(zip_contents) for item in zip_contents: try: if '_w32registry.xml' not in item: continue filename = item.split('/') if len(filename) > 0: filename = filename.pop() else: continue # Get the hostname from the MIR xml filename. hostname = '-'.join(filename.split('-')[:-3]) xml_file = archive.open(item) # Catch possibly corrupt MIR XML data. try: out_list = read_mir(xml_file, quiet=True) except(struct.error, et.ParseError), err: print "[-] Error reading XML data from host: %s, data looks corrupt. Continuing..." % hostname continue # Add the hostname to the entry list. if not out_list or len(out_list) == 0: continue else: for li in out_list: if "Last Modified" not in li[0]: li.insert(0, hostname) final_list.append(li) except IOError, err: print "[-] Error opening file: %s in MIR archive: %s" % (item, err) continue # Add the final header.
Example #22
Source File: rebalance_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_remove_brick_status(mnode, volname, bricks_list): """Parse the output of 'gluster vol remove-brick status' command for the given volume Args: mnode (str): Node on which command has to be executed. volname (str): volume name bricks_list (list): List of bricks participating in remove-brick operation Returns: NoneType: None if command execution fails, parse errors. dict: dict on success. rebalance status will be in dict format Examples: >>> get_remove_brick_status('abc.lab.eng.xyz.com', testvol, bricklist) {'node': [{'files': '0', 'status': '3', 'lookups': '0', 'skipped': '0' , 'nodeName': 'localhost', 'failures': '0', 'runtime': '0.00','id' : '6662bdcd-4602-4f2b-ac1a-75e6c85e780c', 'statusStr': 'completed', 'size': '0'}], 'task-id': '6a135147-b202-4e69- b48c-b1c6408b9d24', 'aggregate': {'files': '0', 'status': '3', 'lookups': '0', 'skipped': '0', 'failures': '0', 'runtime': '0.00', 'statusStr': 'completed', 'size': '0'}, 'nodeCount' : '3'} """ cmd = ("gluster volume remove-brick %s %s status --xml" % (volname, ' '.join(bricks_list))) ret, out, _ = g.run(mnode, cmd) if ret != 0: g.log.error("Failed to execute 'remove-brick status' on node %s", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the remove-brick status" "xml output on volume %s", volname) return None remove_brick_status = {} remove_brick_status["node"] = [] for info in root.findall("volRemoveBrick"): for element in info.getchildren(): if element.tag == "node": status_info = {} for elmt in element.getchildren(): status_info[elmt.tag] = elmt.text remove_brick_status[element.tag].append(status_info) elif element.tag == "aggregate": status_info = {} for elmt in element.getchildren(): status_info[elmt.tag] = elmt.text remove_brick_status[element.tag] = status_info else: remove_brick_status[element.tag] = element.text return remove_brick_status
Example #23
Source File: snap_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_snap_status(mnode): """Parse the output of 'gluster snapshot status' command. Args: mnode (str): Node on which command has to be executed. Returns: NoneType: None if command execution fails, parse errors. list: list of dict on success. Each snap status will be in dict format Examples: >>> get_snap_status('abc.lab.eng.xyz.com') [{'volCount': '1', 'volume': {'brick': [{'path': '10.70.47.11: testvol_brick0', 'pid': '26747', 'lvUsage': '3.52', 'volumeGroup': 'RHS_vg0', 'lvSize': '9.95g'}, {'path': '10.70.47.16:/testvol_brick1', 'pid': '25497', 'lvUsage': '3.52', 'volumeGroup': 'RHS_vg0', 'lvSize': '9.95g'}], 'brickCount': '2'}, 'name': 'snap2', 'uuid': '56a39a92-c339-47cc-a8b2-9e54bb2a6324'}, {'volCount': '1', 'volume': {'brick': [{'path': '10.70.47.11:testvol_next_brick0', 'pid': '26719', 'lvUsage': '4.93', 'volumeGroup': 'RHS_vg1', 'lvSize': '9.95g'}], 'brickCount': '1'}, 'name': 'next_snap1', 'uuid': 'dcf0cd31-c0db-47ad-92ec-f72af2d7b385'}] """ ret, out, _ = g.run(mnode, "gluster snapshot status --xml") if ret != 0: g.log.error("Failed to execute 'snapshot status' on node %s. " "Hence failed to get the snapshot status.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster snapshot " "status xml output.") return None snap_status_list = [] for snap in root.findall("snapStatus/snapshots/snapshot"): snap_status = {} for element in snap.getchildren(): if element.tag == "volume": status = {} status["brick"] = [] for elmt in element.getchildren(): if elmt.tag == "brick": brick_info = {} for el in elmt.getchildren(): brick_info[el.tag] = el.text status["brick"].append(brick_info) else: status[elmt.tag] = elmt.text snap_status[element.tag] = status else: snap_status[element.tag] = element.text snap_status_list.append(snap_status) return snap_status_list
Example #24
Source File: snap_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_snap_info(mnode): """Parse the output of 'gluster snapshot info' command. Args: mnode (str): Node on which command has to be executed. Returns: NoneType: None if command execution fails, parse errors. list: list of dicts on success. Examples: >>> get_snap_info('abc.lab.eng.xyz.com') [{'description': 'This is snap2', 'uuid': '56a39a92-c339-47cc-a8b2-9e54bb2a6324', 'volCount': '1', 'snapVolume': {'status': 'Stopped', 'name': 'df1882d3f86d48738e69f298096f3810'}, 'createTime': '2016-04-07 12:01:21', 'name': 'snap2'}, {'description': None, 'uuid': 'a322d93a-2732-447d-ab88-b943fa402fd2', 'volCount': '1', 'snapVolume': {'status': 'Stopped', 'name': '2c790e6132e447e79168d9708d4abfe7'}, 'createTime': '2016-04-07 13:59:43', 'name': 'snap1'}] """ ret, out, _ = g.run(mnode, "gluster snapshot info --xml") if ret != 0: g.log.error("Failed to execute 'snapshot info' on node %s. " "Hence failed to get the snapshot info.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster snapshot " "info xml output.") return None snap_info_list = [] for snap in root.findall("snapInfo/snapshots/snapshot"): snap_info = {} for element in snap.getchildren(): if element.tag == "snapVolume": info = {} for elmt in element.getchildren(): if elmt.tag == "originVolume": info["originVolume"] = {} for el in elmt.getchildren(): info[elmt.tag][el.tag] = el.text else: info[elmt.tag] = elmt.text snap_info[element.tag] = info else: snap_info[element.tag] = element.text snap_info_list.append(snap_info) return snap_info_list
Example #25
Source File: dependencies.py From cobra with MIT License | 4 votes |
def find_java_mvn(self, file_path): pom_ns = "{http://maven.apache.org/POM/4.0.0}" properties = {} for pom in file_path: if 'pom.xml' in pom: try: tree = self.parse_xml(pom) root = tree.getroot() childs = root.findall('.//%sdependency' % pom_ns) for child in childs: group_id = child.getchildren()[0].text artifact_id = child.getchildren()[1].text if len(child.getchildren()) > 2: version = child.getchildren()[2].text version_match = re.match(r'\${(.*)}', version) if version_match: version_var = version_match.group(1) ver_num = root.findall('.//{pom}{ver}'.format(pom=pom_ns, ver=version_var)) if ver_num: version = ver_num[0].text properties.update({ version_var: version }) elif version_var in properties: version = properties.get(version_var) else: version = '0.0.0' else: # 不确定版本,需要自查 version = '0.0.0' module_ = artifact_id self._framework.append(group_id) self._framework.append(artifact_id) self._result.update( { module_: { 'version': str(version), 'format': 'java', } } ) except ParseError: logger.warning('[DEP] The {} have invalid token'.format(pom)) elif 'package.json' in pom: self.find_nodejs_npm([pom])
Example #26
Source File: snap_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_snap_config(mnode, volname=None): """Parse the output of 'gluster snapshot config' command. Args: mnode (str): Node on which command has to be executed. Kwargs: volname (str): volume name Returns: NoneType: None if command execution fails, parse errors. dict: on success. Examples: >>> get_snap_config('abc.com') {'volumeConfig': [{'softLimit': '230', 'effectiveHardLimit': '256', 'name': 'testvol', 'hardLimit': '256'}, {'softLimit': '230', 'effectiveHardLimit': '256', 'name': 'testvol_next', 'hardLimit': '256'}], 'systemConfig': {'softLimit': '90%', 'activateOnCreate': 'disable', 'hardLimit': '256', 'autoDelete': 'disable'}} """ ret, out, _ = g.run(mnode, "gluster snapshot config --xml") if ret != 0: g.log.error("Failed to execute 'snapshot config' on node %s. " "Hence failed to get the snapshot config.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster snapshot " "config xml output.") return None snap_config = {} for config in root.findall("snapConfig/systemConfig"): sys_config = {} for element in config.getchildren(): sys_config[element.tag] = element.text snap_config["systemConfig"] = sys_config volume_config = [] for config in root.findall("snapConfig/volumeConfig/volume"): vol_config = {} for element in config.getchildren(): vol_config[element.tag] = element.text if volname is not None: if volname == vol_config["name"]: volume_config.append(vol_config) else: volume_config.append(vol_config) snap_config["volumeConfig"] = volume_config return snap_config
Example #27
Source File: peer_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_pool_list(mnode): """Parse the output of 'gluster pool list' command. Args: mnode (str): Node on which command has to be executed. Returns: NoneType: None if command execution fails, parse errors. list: list of dicts on success. Examples: >>> get_pool_list(mnode = 'abc.lab.eng.xyz.com') [{'uuid': 'a2b88b10-eba2-4f97-add2-8dc37df08b27', 'hostname': 'abc.lab.eng.xyz.com', 'state': '3', 'connected': '1', 'stateStr': 'Peer in Cluster'}, {'uuid': 'b15b8337-9f8e-4ec3-8bdb-200d6a67ae12', 'hostname': 'def.lab.eng.xyz.com', 'state': '3', 'hostnames': ['def.lab.eng.xyz.com'], 'connected': '1', 'stateStr': 'Peer in Cluster'} ] """ ret, out, _ = g.run(mnode, "gluster pool list --xml", log_level='DEBUG') if ret != 0: g.log.error("Failed to execute 'pool list' on node %s. " "Hence failed to parse the pool list.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster pool list xml output.") return None pool_list_list = [] for peer in root.findall("peerStatus/peer"): peer_dict = {} for element in peer.getchildren(): if element.tag == "hostname" and element.text == 'localhost': element.text = mnode if element.tag == "hostnames": hostnames_list = [] for hostname in element.getchildren(): hostnames_list.append(hostname.text) element.text = hostnames_list peer_dict[element.tag] = element.text pool_list_list.append(peer_dict) return pool_list_list
Example #28
Source File: heal_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def get_heal_info(mnode, volname): """From the xml output of heal info command get the heal info data. Args: mnode : Node on which commands are executed volname : Name of the volume Returns: NoneType: None if parse errors. list: list of dictionaries. Each element in the list is the heal_info data per brick. """ cmd = "gluster volume heal %s info --xml" % volname ret, out, _ = g.run(mnode, cmd, log_level='DEBUG') if ret != 0: g.log.error("Failed to get the heal info xml output for the volume %s." "Hence failed to get the heal info summary." % volname) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster heal info xml output.") return None heal_info_data = [] for brick in root.findall("healInfo/bricks/brick"): brick_heal_info = {} brick_files_to_heal = [] file_to_heal_exist = False for element in brick.getchildren(): if element.tag == "file": file_to_heal_exist = True file_info = {} file_info[element.attrib['gfid']] = element.text brick_files_to_heal.append(file_info) else: brick_heal_info[element.tag] = element.text if file_to_heal_exist: brick_heal_info['file'] = brick_files_to_heal heal_info_data.append(brick_heal_info) return heal_info_data
Example #29
Source File: workbenches.py From Tenable.io-SDK-for-Python with MIT License | 4 votes |
def parse(path, tag=REPORT_HOST): """Parse Nessus XML export from Workbench API into dicts. :param path: The file path. :param tag: The XML tag to iterate on. It should be WorkbenchParser.REPORT_HOST or WorkbenchParser.REPORT_ITEM. """ assert tag in [WorkbenchParser.REPORT_HOST, WorkbenchParser.REPORT_ITEM], u'Valid tag for parsing.' report_host = None host_properties = None report_items = [] if tag == WorkbenchParser.REPORT_HOST else None try: for event, elem in ET.iterparse(path, events=('start', 'end')): if event == 'start': if elem.tag == 'ReportHost': report_host = WorkbenchParser._from_report_host(elem) if event == 'end': if elem.tag == WorkbenchParser.REPORT_HOST: elem.clear() if tag == elem.tag: yield { 'report_host': report_host, 'host_properties': host_properties, 'report_items': report_items, } report_items = [] if elem.tag == WorkbenchParser.HOST_PROPERTIES: host_properties = WorkbenchParser._from_host_properties(elem) elem.clear() if elem.tag == WorkbenchParser.REPORT_ITEM: report_item = WorkbenchParser._from_report_item(elem) elem.clear() if tag == elem.tag: yield report_item elif tag == WorkbenchParser.REPORT_HOST: report_items.append(report_item) except ET.ParseError as e: logging.warn(u'Failed to parse Nessus XML: ' + e.msg) # TODO The service return malformed XML for empty set, for now we won't raise an exception for what should # TODO be a normal state. However, this might masked out real error from bubble up (unlikely). # raise TenableIOException(u'Failed to parse Nessus XML: ' + e.message)
Example #30
Source File: quota_ops.py From glusto-tests with GNU General Public License v3.0 | 4 votes |
def quota_fetch_list(mnode, volname, path=None): """Parse the output of 'gluster quota list' command. Args: mnode (str): Node on which command has to be executed. volname (str): volume name Kwargs: path (str): Quota path Returns: NoneType: None if command execution fails, parse errors. dict: dict on success. Examples: >>> quota_fetch_list('abc.lab.eng.xyz.com', "testvol") {'/': {'used_space': '0', 'hl_exceeded': 'No', 'soft_limit_percent': '60%', 'avail_space': '2147483648', 'soft_limit_value': '1288490188', 'sl_exceeded': 'No', 'hard_limit': '2147483648'}} """ if not path: path = '' cmd = "gluster volume quota %s list %s --xml" % (volname, path) ret, out, _ = g.run(mnode, cmd) if ret != 0: g.log.error("Failed to execute 'quota list' on node %s. " "Hence failed to get the quota list.", mnode) return None try: root = etree.XML(out) except etree.ParseError: g.log.error("Failed to parse the gluster quota list xml output.") return None quotalist = {} for path in root.findall("volQuota/limit"): for elem in path.getchildren(): if elem.tag == "path": path = elem.text quotalist[path] = {} elif elem.text == 'N/A': quotalist[path][elem.tag] = elem.text elif elem.tag in ("hard_limit", "soft_limit_value", "used_space", "avail_space"): quotalist[path][elem.tag] = int(elem.text) elif elem.tag == "soft_limit_percent": quotalist[path][elem.tag] = int(elem.text[:-1]) elif elem.tag in ("sl_exceeded", "hl_exceeded"): quotalist[path][elem.tag] = bool(elem.text == 'Yes') else: g.log.error("Failed to parse the gluster quota" "list xml output.") return None return quotalist