def parse_str(self, file): try: # Nonesense: we don't know if file is a path or content ??!! wtf if os.path.exists(file): try: data = json.loads(open(file).read()) except IOError: pass except: pass else: data = json.loads(file) # parsing routines self.logger = logging.getLogger() try: pid = data['id'] if 'appstream_family' in data: appstream_family = data['appstream_family'] else: appstream_family = '' name = data['name'].strip() v_txt = data['version'] or '0' desc = data['description'] cmds = data['commands'] reboot = data['reboot'] or 0 try: sub_packages = data['sub_packages'] except KeyError: sub_packages = [] # Inventory section licenses = data['inventory']['licenses'] associateinventory = data['inventory']['associateinventory'] queries = data['inventory']['queries'] except KeyError: raise Exception('CANTPARSE') p = Package() p.init(pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot, appstream_family, queries['Qvendor'], queries['Qsoftware'], queries['Qversion'], queries['boolcnd'], licenses, sub_packages, associateinventory) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): xml = None try: if os.path.exists(file): xml = minidom.parse(file) else: xml = minidom.parseString(file) # parsing routines self.logger = logging.getLogger() root = xml.getElementsByTagName('package') if len(root) != 1: raise Exception('CANTPARSE') root = root[0] pid = root.getAttribute('id') appstream_family = '' if root.hasAttribute('appstream_family'): appstream_family = root.getAttribute('appstream_family') tmp = root.getElementsByTagName('name')[0] name = tmp.firstChild.wholeText.strip() version = root.getElementsByTagName('version')[0] tmp = version.getElementsByTagName('numeric')[0] tmp = version.getElementsByTagName('label')[0] if tmp.firstChild is not None: v_txt = tmp.firstChild.wholeText.strip() else: v_txt = "0" tmp = root.getElementsByTagName('description') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] desc = tmp.firstChild.wholeText.strip() else: desc = "" licenses = '' tmp = root.getElementsByTagName('licenses') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] licenses = tmp.firstChild.wholeText.strip() cmd = root.getElementsByTagName('commands')[0] reboot = 0 if cmd.hasAttribute('reboot'): reboot = cmd.getAttribute('reboot') cmds = {} for c in ['installInit', 'preCommand', 'command', 'postCommandSuccess', 'postCommandFailure']: tmp = cmd.getElementsByTagName(c) if len(tmp) == 1 and tmp[0].firstChild is not None: command = tmp[0].firstChild.wholeText.strip() if tmp[0].hasAttribute('name'): ncmd = tmp[0].getAttribute('name') else: ncmd = '' cmds[c] = {'command': command, 'name': ncmd} else: cmds[c] = '' associateinventory = 0 tmp = root.getElementsByTagName('associateinventory') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] associateinventory = tmp.firstChild.wholeText.strip() query = root.getElementsByTagName('query') queries = {'Qvendor': '', 'Qsoftware': '', 'Qversion': '', 'boolcnd': ''} if query.length >= 1 and query[0].firstChild: for k in queries: tmp = query[0].getElementsByTagName(k) if tmp.length >= 1 and tmp[0].firstChild: queries[k] = tmp[0].firstChild.wholeText.strip() p = Package() p.init( pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot, appstream_family, queries['Qvendor'], queries['Qsoftware'], queries['Qversion'], queries['boolcnd'], licenses, associateinventory ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): try: # Nonesense: we don't know if file is a path or content ??!! wtf if os.path.exists(file): try: data = json.loads(open(file).read()) except IOError: pass except: pass else: data = json.loads(file) # parsing routines self.logger = logging.getLogger() try: pid = data['id'] if 'appstream_family' in data: appstream_family = data['appstream_family'] else: appstream_family = '' name = data['name'].strip() v_txt = data['version'] or '0' desc = data['description'] cmds = data['commands'] reboot = data['reboot'] or 0 try: sub_packages = data['sub_packages'] except KeyError: sub_packages = [] # Inventory section licenses = data['inventory']['licenses'] associateinventory = data['inventory']['associateinventory'] queries = data['inventory']['queries'] except KeyError: raise Exception('CANTPARSE') p = Package() p.init( pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot, appstream_family, queries['Qvendor'], queries['Qsoftware'], queries['Qversion'], queries['boolcnd'], licenses, sub_packages, associateinventory ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): xml = None try: if os.path.exists(file): xml = minidom.parse(file) else: xml = minidom.parseString(file) # parsing routines self.logger = logging.getLogger() root = xml.getElementsByTagName("package") if len(root) != 1: raise Exception("CANTPARSE") root = root[0] pid = root.getAttribute("id") tmp = root.getElementsByTagName("name")[0] name = tmp.firstChild.wholeText.strip() version = root.getElementsByTagName("version")[0] tmp = version.getElementsByTagName("numeric")[0] tmp = version.getElementsByTagName("label")[0] if tmp.firstChild != None: v_txt = tmp.firstChild.wholeText.strip() else: v_txt = "0" tmp = root.getElementsByTagName("description") if len(tmp) == 1 and tmp[0].firstChild != None: tmp = tmp[0] desc = tmp.firstChild.wholeText.strip() else: desc = "" cmd = root.getElementsByTagName("commands")[0] reboot = 0 if cmd.hasAttribute("reboot"): reboot = cmd.getAttribute("reboot") cmds = {} for c in ["installInit", "preCommand", "command", "postCommandSuccess", "postCommandFailure"]: tmp = cmd.getElementsByTagName(c) if len(tmp) == 1 and tmp[0].firstChild != None: command = tmp[0].firstChild.wholeText.strip() if tmp[0].hasAttribute("name"): ncmd = tmp[0].getAttribute("name") else: ncmd = "" cmds[c] = {"command": command, "name": ncmd} else: cmds[c] = "" p = Package() p.init( pid, name, v_txt, 0, desc, cmds["command"], cmds["installInit"], cmds["preCommand"], cmds["postCommandSuccess"], cmds["postCommandFailure"], reboot, ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): xml = None try: if os.path.exists(file): xml = minidom.parse(file) else: xml = minidom.parseString(file) # parsing routines self.logger = logging.getLogger() root = xml.getElementsByTagName('package') if len(root) != 1: raise Exception('CANTPARSE') root = root[0] pid = root.getAttribute('id') tmp = root.getElementsByTagName('name')[0] name = tmp.firstChild.wholeText.strip() version = root.getElementsByTagName('version')[0] tmp = version.getElementsByTagName('numeric')[0] tmp = version.getElementsByTagName('label')[0] if tmp.firstChild is not None: v_txt = tmp.firstChild.wholeText.strip() else: v_txt = "0" tmp = root.getElementsByTagName('description') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] desc = tmp.firstChild.wholeText.strip() else: desc = "" licenses = '' tmp = root.getElementsByTagName('licenses') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] licenses = tmp.firstChild.wholeText.strip() cmd = root.getElementsByTagName('commands')[0] reboot = 0 if cmd.hasAttribute('reboot'): reboot = cmd.getAttribute('reboot') cmds = {} for c in ['installInit', 'preCommand', 'command', 'postCommandSuccess', 'postCommandFailure']: tmp = cmd.getElementsByTagName(c) if len(tmp) == 1 and tmp[0].firstChild is not None: command = tmp[0].firstChild.wholeText.strip() if tmp[0].hasAttribute('name'): ncmd = tmp[0].getAttribute('name') else: ncmd = '' cmds[c] = {'command': command, 'name': ncmd} else: cmds[c] = '' associateinventory = 0 tmp = root.getElementsByTagName('associateinventory') if len(tmp) == 1 and tmp[0].firstChild is not None: tmp = tmp[0] associateinventory = tmp.firstChild.wholeText.strip() query = root.getElementsByTagName('query') queries = {'Qvendor': '', 'Qsoftware': '', 'Qversion': '', 'boolcnd': ''} if query.length >= 1 and query[0].firstChild: for k in queries: tmp = query[0].getElementsByTagName(k) if tmp.length >= 1 and tmp[0].firstChild: queries[k] = tmp[0].firstChild.wholeText.strip() p = Package() p.init( pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot, 0, queries['Qvendor'], queries['Qsoftware'], queries['Qversion'], queries['boolcnd'], licenses, [], associateinventory ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): xml = None try: if os.path.exists(file): xml = minidom.parse(file) else: xml = minidom.parseString(file) # parsing routines self.logger = logging.getLogger() root = xml.getElementsByTagName('package') if len(root) != 1: raise Exception('CANTPARSE') root = root[0] pid = root.getAttribute('id') tmp = root.getElementsByTagName('name')[0] name = tmp.firstChild.wholeText.strip() version = root.getElementsByTagName('version')[0] tmp = version.getElementsByTagName('numeric')[0] tmp = version.getElementsByTagName('label')[0] if tmp.firstChild != None: v_txt = tmp.firstChild.wholeText.strip() else: v_txt = "0" tmp = root.getElementsByTagName('description') if len(tmp) == 1 and tmp[0].firstChild != None: tmp = tmp[0] desc = tmp.firstChild.wholeText.strip() else: desc = "" cmd = root.getElementsByTagName('commands')[0] reboot = 0 if cmd.hasAttribute('reboot'): reboot = cmd.getAttribute('reboot') cmds = {} for c in ['installInit', 'preCommand', 'command', 'postCommandSuccess', 'postCommandFailure']: tmp = cmd.getElementsByTagName(c) if len(tmp) == 1 and tmp[0].firstChild != None: command = tmp[0].firstChild.wholeText.strip() if tmp[0].hasAttribute('name'): ncmd = tmp[0].getAttribute('name') else: ncmd = '' cmds[c] = {'command':command, 'name':ncmd} else: cmds[c] = '' p = Package() p.init( pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None
def parse_str(self, file): xml = None try: if os.path.exists(file): xml = minidom.parse(file) else: xml = minidom.parseString(file) # parsing routines self.logger = logging.getLogger() root = xml.getElementsByTagName('package') if len(root) != 1: raise Exception('CANTPARSE') root = root[0] pid = root.getAttribute('id') tmp = root.getElementsByTagName('name')[0] name = tmp.firstChild.wholeText.strip() version = root.getElementsByTagName('version')[0] tmp = version.getElementsByTagName('numeric')[0] if tmp.firstChild != None: v_num = tmp.firstChild.wholeText else: v_num = 0 tmp = version.getElementsByTagName('label')[0] if tmp.firstChild != None: v_txt = tmp.firstChild.wholeText.strip() else: v_txt = "0" tmp = root.getElementsByTagName('description') if len(tmp) == 1 and tmp[0].firstChild != None: tmp = tmp[0] desc = tmp.firstChild.wholeText.strip() else: desc = "" cmd = root.getElementsByTagName('commands')[0] reboot = 0 if cmd.hasAttribute('reboot'): reboot = cmd.getAttribute('reboot') cmds = {} for c in ['installInit', 'preCommand', 'command', 'postCommandSuccess', 'postCommandFailure']: tmp = cmd.getElementsByTagName(c) if len(tmp) == 1 and tmp[0].firstChild != None: command = tmp[0].firstChild.wholeText.strip() if tmp[0].hasAttribute('name'): ncmd = tmp[0].getAttribute('name') else: ncmd = '' cmds[c] = {'command':command, 'name':ncmd} else: cmds[c] = '' p = Package() p.init( pid, name, v_txt, 0, desc, cmds['command'], cmds['installInit'], cmds['preCommand'], cmds['postCommandSuccess'], cmds['postCommandFailure'], reboot ) except Exception, e: logging.getLogger().error("parse_str failed") logging.getLogger().error(e) p = None