예제 #1
0
    def parse_content(self, content):
        if not content:
            raise SkipException('No repolist.')

        trailing_line_prefix = [
            'repolist:',
            'Uploading Enabled',
            'Loaded plugins:',
            'Unable to upload',
        ]

        self.data = []
        self.repos = {}
        self.data = parse_fixed_table(content,
                                      heading_ignore=['repo id'],
                                      header_substitute=[
                                          ('repo id', 'id     '),
                                          ('repo name', 'name     ')
                                      ],
                                      trailing_ignore=trailing_line_prefix,
                                      empty_exception=True)

        if not self.data:
            raise SkipException('No repolist.')

        self.repos = dict(
            (d['id'].lstrip('!').lstrip('*'), d) for d in self.data)
예제 #2
0
    def parse_content(self, content):
        self.data = {}
        self.__slab_version = None
        column = []
        row = []
        if not content:
            raise SkipException("No Contents")

        if 'slabinfo - version' in content[0]:
            self.__slab_version = content[0].split()[-1]
        else:
            raise SkipException("Invalid Contents")

        if "active_objs" in content[1]:
            line = content[1].split()
            column = [
                obj.replace('<', '').replace('>', '') for obj in line
                if obj not in ['#', ':', 'tunables', 'slabdata']
            ]
        else:
            raise SkipException("Invalid Contents")

        for line in content[2:]:
            line = line.split()
            row = [
                obj for obj in line
                if obj not in ['#', ':', 'tunables', 'slabdata']
            ]
            if column and row and len(column) == len(row):
                self.data[row[0]] = dict(zip(column, row))
                row = []
            else:
                raise SkipException("Invalid Contents")
예제 #3
0
    def parse_content(self, content):
        if not content:
            raise SkipException("Input content is empty.")

        self.data = {}
        compiled_with = {}
        for line in content:
            line = line.strip()
            if ': ' in line:
                key, value = [s.strip() for s in line.split(': ', 1)]
                self.data[key] = value.lower()
            elif line.startswith('-'):
                line = line[3:]  # cut off the '-D '
                if '=' in line:
                    key, value = line.split('=', 1)
                    compiled_with[key] = value.strip('"')
                else:
                    if ' ' in line:
                        key, value = line.split(' ', 1)
                        value = value.strip('"()')
                    else:
                        key, value = line, True
                    compiled_with[key] = value

        if self.data:
            if compiled_with:
                self.data['Server compiled with'] = compiled_with
        else:
            raise SkipException(
                "Input content is not empty but there is no useful parsed data."
            )
예제 #4
0
 def parse_content(self, content):
     if len(content) <= 1:
         raise SkipException("Incorrect content.")
     self.data = {}
     self.sid = self.version = self.revision = None
     self.major = self.minor = self.patchlevel = None
     # get the "sid" from the file_name: "sudo_-iu_<sid>adm_HDB_version"
     if self.file_name and 'adm' in self.file_name:
         self.sid = [
             i for i in self.file_name.split('_') if i.endswith('adm')
         ][0][:-3]
     for line in content[1:]:
         key, val = [i.strip() for i in line.split(':', 1)]
         self.data[key] = val
         if key == 'version':
             self.version = val
             val_splits = val.split('.')
             if len(val_splits) != 5:
                 raise SkipException(
                     "Incorrect HDB version: {0}.".format(val))
             self.major = val_splits[0]
             self.minor = val_splits[1]
             self.revision = val_splits[2]
             self.patchlevel = val_splits[3]
     if not self.version:
         raise SkipException("Incorrect content.")
예제 #5
0
    def parse_content(self, content):
        self.fields = []
        self.data = []
        if not content:
            raise SkipException("Empty file")

        self.data = parse_fixed_table(content,
                                      heading_ignore=[
                                          "COMMAND", "PID", "USER", "FD",
                                          "TYPE", "DEVICE", "SIZE/OFF", "NODE",
                                          "NAME"
                                      ],
                                      header_substitute=[
                                          ("COMMAND", "command"),
                                          ("PID", "pid"), ("USER", "user"),
                                          ("FD", "fd"), ("TYPE", "type"),
                                          ("DEVICE", "device"),
                                          ("SIZE/OFF", "size_off"),
                                          ("NODE", "node"), ("NAME", "name")
                                      ])
        if not self.data:
            raise SkipException("Useless data")

        for item in self.data:
            self.fields.append(
                self.keyvalue(item["command"], item["pid"], item["user"],
                              item["fd"], item["type"], item["device"],
                              item["size_off"], item["node"], item["name"]))
예제 #6
0
    def parse_content(self, content):
        """
        Parse the ``/boot/grub2/grubenv``
        """
        if not content:
            raise SkipException("Empty content.")

        self.data = {}
        for line in content:
            if '=' in line:
                key, value = [i.strip() for i in line.split('=', 1)]
                self.data[key] = value
            elif not line.startswith('#'):
                raise ParseException('Bad line: "{0}"'.format(line))

        if not self.data:
            raise SkipException("No useful data")

        self.name = self.saved_entry = self.data.get('saved_entry', '')
        self.cmdline = self.data.get('kernelopts', '')
        self._boot_entries.append(
            BootEntry({
                'name': self.name,
                'cmdline': self.cmdline
            }))
        self.kernelopts = dict()
        for el in self.cmdline.split():
            key, value = el, True
            if "=" in el:
                key, value = [i.strip() for i in el.split('=', 1)]
            if key not in self.kernelopts:
                self.kernelopts[key] = []
            self.kernelopts[key].append(value)
예제 #7
0
    def parse_content(self, content):
        """
        Parse the lines given into a list of dictionaries for each row.  This
        is stored in the ``rows`` attribute.

        If the ``key_field`` property is set, use this to key a ``data``
        dictionary attribute.
        """
        if not (self.key_field and self.attr_name):
            raise NotImplementedError("'key_field' or 'attr_name' is not defined")

        # There is another application named docker that's a kde system tray, that
        # will output help when the spec is run due to incorrect arguments. So check
        # the content for any lines starting with Usage: so it can be skipped.
        if any(l for l in content if l.startswith("Usage: ")):
            raise SkipException('No data only help output.')

        self.rows = parse_fixed_table(content,
                                      heading_ignore=self.heading_ignore,
                                      header_substitute=self.substitutions)

        if not self.rows:
            raise SkipException('No data.')

        data = {}
        for row in self.rows:
            k = row.get(self.key_field)
            for sub in self.substitutions:
                row[sub[0]] = row.pop(sub[1]) if sub[1] in row else None
            if k is not None and k != '<none>':
                data[k] = row
        setattr(self, self.attr_name, data)
예제 #8
0
    def from_content(cls, content):
        """
        A classmethod to generated a `ModInfo` object from the given `content`
        list. Two more keys `module_name` and `module_deps` will be created as
        well per the `content`.

        Raises:
            SkipException: When nothing need to check to a dict.
        """
        if not content:
            raise SkipException("No Contents")

        data = {}
        for line in content:
            line = line.strip()
            if ':' in line:
                key, value = [l.strip() for l in line.split(':', 1)]
                if key not in data:
                    data[key] = value
                else:
                    old_val = data[key]
                    data[key] = [old_val] if isinstance(old_val,
                                                        str) else old_val
                    data[key].append(value)

        if not data:
            raise SkipException("No Parsed Contents")

        data['module_deps'] = [
            mod for mod in data.get('depends', '').split(',')
        ]
        data['module_name'] = data.get('filename',
                                       '').rsplit('/')[-1].split('.')[0]

        return cls(data)
예제 #9
0
    def parse_content(self, content):
        if (not content) or (not self.file_path):
            raise SkipException("No Contents")

        self.retpoline_y = set()
        self.retpoline_n = set()
        idx = None
        for i, line in enumerate(content):
            if line.startswith('filename:'):
                if idx is not None:
                    m = ModInfo.from_content(content[idx:i])
                    name = m.module_name
                    self[name] = m
                    self.retpoline_y.add(name) if m.get(
                        'retpoline') == 'Y' else None
                    self.retpoline_n.add(name) if m.get(
                        'retpoline') == 'N' else None
                idx = i
        if idx is not None and idx < len(content):
            m = ModInfo.from_content(content[idx:])
            name = m.module_name
            self[name] = m
            self.retpoline_y.add(name) if m.get('retpoline') == 'Y' else None
            self.retpoline_n.add(name) if m.get('retpoline') == 'N' else None

        if len(self) == 0:
            raise SkipException("No Parsed Contents")
예제 #10
0
    def parse_content(self, content):
        # No content found or file is empty
        if not content:
            raise SkipException("Empty file")

        data = {}
        self.raw = []
        key, value = "", ""
        for line in get_active_lines(content):
            self.raw.append(line.strip())
            if "=" in line:
                key, value = line.split("=", 1)
            elif key:
                if value.endswith("'") or value.endswith("\""):
                    data[key] = value[1:-1].split()
                    key, value = "", ""
                value = value + " " + line

        # No useful parsed data
        if not data:
            raise SkipException(
                "Input content is not empty but there is no useful parsed data."
            )

        self.update(data)
예제 #11
0
    def parse_content(self, content):
        # Parse Ceph Version Content and get Release, Major, Minor number
        if not content:
            raise SkipException("Empty Ceph Version Line", content)

        ceph_version_line = content[-1]
        # re search pattern
        pattern_community = r'((\d{1,2})\.(\d{1,2})\.((\d{1,2})|x))((\-(\d+)))'
        community_version_mo = re.search(pattern_community,
                                         str(ceph_version_line), 0)
        if not community_version_mo:
            raise SkipException("Wrong Format Ceph Version", content)

        community_version = community_version_mo.group(0)
        release_data = community_to_release_map.get(community_version, None)
        if not release_data:
            raise SkipException(
                "No Mapping Release Version. Ceph Release Number is Null",
                content)

        self.version = release_data['version']
        self.major = release_data['major']
        self.minor = release_data['minor']
        self.is_els = release_data.get('els', False)
        self.downstream_release = release_data['downstream_release']
        self.upstream_version = {
            "release": int(community_version_mo.group(2)),
            "major": int(community_version_mo.group(3)),
            "minor": int(community_version_mo.group(4))
        }
예제 #12
0
    def parse_content(self, content):
        if not content:
            raise SkipException('No content.')

        ipsec_type, ipsec_name = "", ""
        ipsec_sections = {}

        try:
            for line in get_active_lines(content):
                if line.startswith('include '):
                    include, path = [field.strip() for field in line.split()]
                    array = self.get('include', [])
                    array.append(path)
                    self['include'] = array
                    continue

                if line.startswith(('conn ', 'config ')):
                    ipsec_type, ipsec_name = [field.strip() for field in line.split()]
                    ipsec_sections = self.get(ipsec_type, defaultdict(dict))
                    continue

                if '=' not in line or ipsec_type == "" or ipsec_name == "":
                    # skip the options that don't within a section
                    continue

                key, value = [field.strip() for field in line.split('=')]
                ipsec_sections[ipsec_name][key] = value
                self[ipsec_type] = ipsec_sections

        except ValueError:
            raise SkipException('Syntax error')
 def parse_content(self, content):
     self.set = self.major = self.minor = None
     l = len(content)
     if l != 1:
         raise SkipException(
             "Content takes at most 1 line ({0} given).".format(l))
     line = content[0].strip()
     if line != 'Release not set':
         line_splits = line.split()
         # Release: 6.7 or Release 7Server
         if len(line_splits) == 2:
             rel = line_splits[-1]
             rel_splits = rel.split('.')
             # Release: 6.7
             if len(rel_splits) == 2:
                 if rel_splits[0].isdigit() and rel_splits[-1].isdigit():
                     self.set = rel
                     self.major = int(rel_splits[0])
                     self.minor = int(rel_splits[-1])
                     return
             # Release: 7Server
             elif rel.endswith('Server') and rel[0].isdigit():
                 self.set = rel
                 self.major = int(rel[0])
                 # leave self.minor as None
                 return
         raise SkipException("Incorrect content: {0}".format(line))
예제 #14
0
    def parse_content(self, content):
        self.global_lines = []
        self.host_lines = {}

        _content = get_active_lines(content)
        if not _content:
            raise SkipException("Empty content.")

        index_list = [i for i, l in enumerate(_content) if l.startswith('Host ')]
        index = index_list[0] if index_list else len(_content)

        for line in _content[:index]:
            line_splits = [s.strip() for s in line.split(None, 1)]
            kw, val = line_splits[0], line_splits[1] if len(line_splits) == 2 else ''
            self.global_lines.append(self.KeyValue(kw, val, line))

        hostbit = ''
        for line in _content[index:]:
            line_splits = [s.strip() for s in line.split(None, 1)]
            kw, val = line_splits[0], line_splits[1] if len(line_splits) == 2 else ''
            if kw == 'Host':
                hostbit = kw + '_' + val
                self.host_lines[hostbit] = []
            else:
                self.host_lines[hostbit].append(self.KeyValue(kw, val, line))

        if not (self.host_lines or self.global_lines):
            raise SkipException("Nothing parsed.")
예제 #15
0
 def parse_content(self, content):
     if not content:
         raise SkipException("Empty output.")
     if "no such user" in content[0].lower():
         raise SkipException("No such user.")
     if len(content) > 1 or not content[0].isdigit():
         raise ParseException("Unable to parse user ID: {0}".format(content))
     self.data = int(content[0])
예제 #16
0
    def parse_content(self, content):
        if not content:
            raise SkipException("Empty output.")

        _, fwl = content[0].split(None, 1)

        if not fwl:
            raise SkipException("Nothing to parse.")

        self.firmware_level = fwl.strip('()')
예제 #17
0
    def parse_content(self, content):
        if not content:
            raise SkipException("Empty output.")

        for line in content:
            key, value = [l.strip() for l in line.split('=', 1)]
            _, _, value = value.partition(',')
            self[key] = value.strip()

        if len(self) == 0:
            raise SkipException("Nothing to parse.")
예제 #18
0
 def parse_content(self, content):
     if not content:
         raise SkipException("No Valid Output")
     data = {}
     for line in content:
         if line.startswith("device for "):
             protocol = line.split(":")[-1].strip()
             printer = line.split(":")[0].split()[-1].strip()
             data[printer] = protocol
     if not data:
         raise SkipException("No Valid Output")
     self.update(data)
예제 #19
0
    def parse_content(self, content):
        if not content:
            raise SkipException("Empty output.")
        content = ''.join(content)
        try:
            self.data = json.loads(content)
        except Exception:
            raise ParseException("Incorrect content: '{0}'".format(content))

        if not self.data:
            raise SkipException("Empty or useless output.")

        self.is_running = all(l['status'] == 'Running' for l in self.data)
        self.is_green = all(l['dispstatus'] == 'GREEN' for l in self.data)
예제 #20
0
 def parse_content(self, content):
     if not content:
         raise SkipException("Empty.")
     keys = []
     for line in content:
         if not keys and line.startswith('#PATH'):
             keys = [i.strip('#') for i in line.split(':')]
             continue
         line_splits = [i.strip() for i in line.split(':', 4)]
         line_splits.extend(
             [i.strip(': ') for i in line_splits.pop(-1).rsplit(':', 1)])
         self.append(dict(zip(keys, line_splits)))
     if len(self) == 0:
         raise SkipException('Nothing to parse.')
예제 #21
0
    def parse_content(self, content):
        if len(content) == 0:
            raise SkipException("Empty file")

        self.data = {}
        # Extract the bridge name
        bridge_name = self.file_path.split("ovs-appctl_fdb.show_")[-1]

        header = content[0].split()
        self.data[bridge_name] = [
            dict(zip(header, entry.split(None, len(header))))
            for entry in content[1:]
        ]
        if not self.data[bridge_name]:
            raise SkipException("No data present for {0}".format(bridge_name))
예제 #22
0
    def parse_content(self, content):
        if not content:
            raise SkipException("Input content is empty")

        self.raw_lines = content
        self.reports = []

        for line in content:
            if line.startswith("SELinux is preventing "):
                self.reports.append(Report())
            if self.reports:  # skips the first report if it contains only partial data
                self.reports[-1].append_line(line)

        if not self.reports:
            raise SkipException("No sealert reports")
예제 #23
0
    def parse_content(self, content):
        """
        Parse the lines given into a list of dictionaries for each row.  This
        is stored in the ``rows`` attribute.

        If the ``key_field`` property is set, use this to key a ``data``
        dictionary attribute.
        """
        if not (self.key_field and self.attr_name):
            raise NotImplementedError(
                "'key_field' or 'attr_name' is not defined")

        self.rows = parse_fixed_table(content,
                                      heading_ignore=self.heading_ignore,
                                      header_substitute=self.substitutions)

        if not self.rows:
            raise SkipException('No data.')

        data = {}
        for row in self.rows:
            k = row.get(self.key_field)
            for sub in self.substitutions:
                row[sub[0]] = row.pop(sub[1]) if sub[1] in row else None
            if k is not None and k != '<none>':
                data[k] = row
        setattr(self, self.attr_name, data)
예제 #24
0
    def parse_content(self, content):
        if not content:
            raise SkipException("No Data from command: /usr/sbin/kpatch list")

        self._loaded = {}
        self._installed = {}
        cur_dict = {}
        for line in content:
            if not line.strip():
                continue

            if 'Loaded patch modules' in line:
                cur_dict = self._loaded
                continue

            if 'Installed patch modules' in line:
                cur_dict = self._installed
                continue

            fields = [k.strip('()[]') for k in line.split()]
            if len(fields) == 1:
                if cur_dict == self._loaded:
                    # In the early version:
                    #  # kpatch list
                    #  Loaded patch modules:
                    #  kpatch_7_0_1_el7
                    #
                    cur_dict[fields[0].strip()] = ''

            elif len(fields) == 2:
                cur_dict[fields[0]] = fields[1]
예제 #25
0
    def parse_content(self, content):
        """
        Parse output content table of command ``/bin/mysqladmin variables``.
        Set each variable as an class attribute.
        """
        bad_lines = []
        if not content:
            raise SkipException("Empty content.")
        if len(content) < 5:
            raise ParseException(
                "Wrong content in table: '{0}'.".format(content))

        data = {}
        for _l in content[3:-1]:
            l = _l.strip()
            if not (l.startswith('|') and l.endswith('|')):
                bad_lines.append(_l)
                continue
            l = l[1:-1]
            lsp = l.split('|', 1)
            if len(lsp) < 2:
                bad_lines.append(_l)
                continue
            data[lsp[0].strip().lower()] = lsp[1].strip()
        self.data = data
        self.bad_lines = bad_lines
예제 #26
0
 def parse_content(self, content):
     """Parse the command output"""
     with_header = ['advisory type package'] + content
     table = parse_delimited_table(with_header)
     if not table:
         raise SkipException('No data.')
     self._items = table
예제 #27
0
    def parse_content(self, content):
        self.data = []
        self._sctp_local_ports = set()
        self._sctp_remote_ports = set()
        self._sctp_local_ips = set()
        self._sctp_remote_ips = set()
        if (not content) or (not self.file_path):
            raise SkipException("No Contents")

        line = content[0].strip().split()
        keys_cnt = len(self.COLUMN_IDX)
        if "LPORT" not in line or len(line) != keys_cnt:
            raise ParseException("Contents are not compatible to this parser".format(line))

        laddr_idx = line.index('LADDRS')
        raddr_ridx = len(line) - line.index('RADDRS')
        for line in content[1:]:
            line_1 = line.strip().split(None, laddr_idx)
            line_end = line_1.pop()
            idx = line_end.index('<->')
            laddrs = line_end[:idx].strip().split()
            line_end = line_end[idx + 3:].strip().rsplit(None, raddr_ridx - 1)
            raddrs = line_end.pop(0).split()
            line_1.append(laddrs)
            line_1.append(raddrs)
            line_1.extend(line_end)
            self.data.append(dict(zip(self.COLUMN_IDX[:-1], line_1)))

        for line in self.data:
            self._sctp_local_ports.add(line['local_port'])
            self._sctp_remote_ports.add(line['remote_port'])
            self._sctp_local_ips.update(line['local_addr'])
            self._sctp_remote_ips.update(line['remote_addr'])
예제 #28
0
    def parse_content(self, content):
        if (not content) or (not self.file_path):
            raise SkipException("No Contents")

        line = content[0].strip().split()
        keys_cnt = len(self.COLUMN_IDX)
        if "LPORT" not in line or len(line) != keys_cnt:
            raise ParseException("Contents are not compatible to this parser".format(line))

        self.data = []
        for line in content[1:]:
            line = line.strip().split(None, keys_cnt - 1)
            line[-1] = line[-1].split()
            self.data.append(dict(zip(self.COLUMN_IDX, line)))

        self._sctp_local_ports = set()
        self._sctp_local_ips = set()
        self._sctp_eps_ips = {}
        for line in self.data:
            self._sctp_local_ports.add(line['local_port'])
            local_addr = line['local_addr']
            self._sctp_local_ips.update(local_addr)
            if line['endpoints'] not in self._sctp_eps_ips:
                self._sctp_eps_ips[line['endpoints']] = []
            self._sctp_eps_ips[line['endpoints']].extend(local_addr)
예제 #29
0
    def parse_content(self, content):
        if (not content) or (not self.file_path):
            raise SkipException("No Contents")

        self.data = {}
        self._module_deps = []
        for line in content:
            line = line.strip()
            if ':' in line:
                key, value = [l.strip() for l in line.split(':', 1)]
                if key not in self.data:
                    self.data[key] = value
                else:
                    old_val = self.data[key]
                    self.data[key] = [old_val] if isinstance(old_val,
                                                             str) else old_val
                    self.data[key].append(value)

        if not self.data:
            raise ParseException("No Parsed Contents")
        self._module_deps = [
            mod for mod in self.data.get("depends", '').split(',')
        ]
        self._module_name = self.data.get('filename',
                                          '').rsplit("/")[-1].split('.')[0]
예제 #30
0
 def parse_content(self, content):
     self.data = {}
     for line in get_active_lines(content):
         if '=' not in line:
             raise SkipException("Incorrect line: '{0}'".format(line))
         key, val = line.split('=', 1)
         self.data[key.strip()] = val.strip()