示例#1
0
    def items(self):
        items = []
        for line in [l.strip() for l in self.split("\n")]:
            (key, value) = line.split(":", 1)

            # Sanitize key so that it can be expressed as
            # an attribute
            key = key.strip()
            key = key.replace(" ", "_")
            key = key.lower()

            # Rename processor entry to name
            if key == "processor":
                key = "name"

            # Express value as a list if it is flags
            value = value.strip()
            if key == "flags":
                value = value.split()
            else:
                value = string_to_type(value)

            items.append((key, value))

        items.append(("processor", LinkRegistry(self)))

        return items
示例#2
0
    def size(self):
        attribute = "%s_size" % self.category.lower()
        size = self._attributes.get(attribute)

        if size:
            size = string_to_type(size)

        return size
示例#3
0
文件: dmi.py 项目: nkaul/ocp-checkbox
    def size(self):
        attribute = "%s_size" % self.category.lower()
        size = self._attributes.get(attribute)

        if size:
            size = string_to_type(size)

        return size
    def exchange(self):
        # Encode form data
        form = {}
        for field, value in self._form.items():
            form[field] = str(value).encode("UTF-8")

        # Compress and add payload to form
        payload = open(self._report, "r").read()
        compressed_payload = bz2.compress(payload)
        file = StringIO(compressed_payload)
        file.name = "%s.xml.bz2" % str(gethostname())
        file.size = len(compressed_payload)
        form["field.submission_data"] = file

        if logging.getLogger().getEffectiveLevel() <= logging.DEBUG:
            logging.debug("Uncompressed payload length: %d", len(payload))

        transport = HTTPTransport(self.transport_url)

        start_time = time.time()
        response = transport.exchange(form, self._headers,
            timeout=string_to_type(self.timeout))
        end_time = time.time()

        if not response:
            self._manager.reactor.fire("exchange-error", _("""\
Failed to contact server. Please try
again or upload the following file name:
%s

directly to the system database:
https://launchpad.net/+hwdb/+submit""") % posixpath.abspath(self._report))
            return
        elif response.status != 200:
            self._manager.reactor.fire("exchange-error", _("""\
Failed to upload to server,
please try again later."""))
            return

        if logging.getLogger().getEffectiveLevel() <= logging.DEBUG:
            logging.debug("Response headers:\n%s",
                pprint.pformat(response.getheaders()))

        header = response.getheader("x-launchpad-hwdb-submission")
        if not header:
            self._manager.reactor.fire("exchange-error",
                _("Information not posted to Launchpad."))
        elif "Error" in header:
            # HACK: this should return a useful error message
            self._manager.reactor.fire("exchange-error", header)
            logging.error(header)
        else:
            text = response.read()
            logging.info("Sent %d bytes and received %d bytes in %s.",
                file.size, len(text), format_delta(end_time - start_time))
示例#5
0
    def items(self):
        keys = ["file_system", "mount_point", "type", "options", "dump", "pass"]
        items = []
        for line in [l for l in self.split("\n") if l]:
            values = [string_to_type(v) for v in line.split(" ")]
            map = dict(zip(keys, values))
            map["options"] = map["options"].split(",")
            value = MapRegistry(map)
            items.append((map["mount_point"], value))

        return items
示例#6
0
    def items(self):
        items = []
        lines = [l.strip() for l in self.split("\n") if l]
        if lines:
            keys_line = lines.pop(0)
            keys = [k.lower() for k in re.split(r"\s+", keys_line)]

            for line in lines:
                values = [string_to_type(v) for v in re.split(r"\s+", line)]
                map = dict(zip(keys, values))
                value = MapRegistry(map)
                items.append((map["pv"], value))

        return items
示例#7
0
    def items(self):
        items = []
        lines = []

        id = depth = None
        for line in self.split("\n"):
            if not line:
                continue

            match = re.match(r"(\s+(\/)?)(.+)", line)
            if not match:
                lines[-1] += line
                continue

            space = len(match.group(1).rstrip("/"))
            if depth is None:
                depth = space

            if space > depth:
                lines.append(line)
            elif match.group(2) is not None:
                if id is not None:
                    value = SourceRegistry("\n".join(lines))
                    lines = []

                    items.append((id, value))

                id = match.group(3).split("/")[-1].rstrip(":")
            else:
                (key, value) = match.group(3).split(" = ", 1)
                if value == "(no value set)":
                    value = None
                else:
                    match = re.match(r"\[([^\]]*)\]", value)
                    if match:
                        list_string = match.group(1)
                        if len(list_string):
                            value = list_string.split(",")
                        else:
                            value = []
                    else:
                        value = string_to_type(value)

                items.append((key, value))

        if lines:
            value = SourceRegistry("\n".join(lines))
            items.append((id, value))

        return items
示例#8
0
    def run(self, result):
        attributes = self.getAttributes()
        if not attributes:
            return

        # Default values
        machine = self.machine
        processor = {
            "platform": machine,
            "count": 1,
            "type": machine,
            "model": machine,
            "model_number": "",
            "model_version": "",
            "model_revision": "",
            "cache": 0,
            "bogomips": 0,
            "speed": -1,
            "other": ""}

        # Conversion table
        platform_to_conversion = {
            ("i386", "i486", "i586", "i686", "x86_64",): {
                "type": "vendor_id",
                "model": "model name",
                "model_number": "cpu family",
                "model_version": "model",
                "model_revision": "stepping",
                "cache": "cache size",
                "other": "flags",
                "speed": "cpu mhz"},
            ("alpha", "alphaev6",): {
                "count": "cpus detected",
                "type": "cpu",
                "model": "cpu model",
                "model_number": "cpu variation",
                "model_version": ("system type", "system variation",),
                "model_revision": "cpu revision",
                "other": "platform string",
                "speed": "cycle frequency [Hz]"},
            ("armv7l",): {
                "type": "hardware",
                "model": "processor",
                "model_number": "cpu variant",
                "model_version": "cpu architecture",
                "model_revision": "cpu revision",
                "other": "features"},
            ("ia64",): {
                "type": "vendor",
                "model": "family",
                "model_version": "archrev",
                "model_revision": "revision",
                "other": "features",
                "speed": "cpu mhz"},
            ("ppc64", "ppc",): {
                "type": "platform",
                "model": "cpu",
                "model_version": "revision",
                "speed": "clock"},
            ("sparc64", "sparc",): {
                "count": "ncpus probed",
                "type": "type",
                "model": "cpu",
                "model_version": "type",
                "speed": "bogomips"}}

        processor["count"] = attributes.get("count", 1)
        bogompips_string = attributes.get("bogomips", "0.0")
        processor["bogomips"] = int(round(float(bogompips_string)))
        for platform, conversion in platform_to_conversion.items():
            if machine in platform:
                for pkey, ckey in conversion.items():
                    if isinstance(ckey, (list, tuple)):
                        processor[pkey] = "/".join([attributes[k]
                            for k in ckey])
                    elif ckey in attributes:
                        processor[pkey] = attributes[ckey]

        # Adjust platform
        if machine[0] == "i" and machine[-2:] == "86":
            processor["platform"] = "i386"
        elif machine[:5] == "alpha":
            processor["platform"] = "alpha"

        # Adjust cache
        if processor["cache"]:
            processor["cache"] = string_to_type(processor["cache"])

        # Adjust speed
        try:
            if machine[:5] == "alpha":
                speed = processor["speed"].split()[0]
                processor["speed"] = int(round(float(speed))) / 1000000
            elif machine[:5] == "sparc":
                speed = processor["speed"]
                processor["speed"] = int(round(float(speed))) / 2
            else:
                if machine[:3] == "ppc":
                    # String is appended with "mhz"
                    speed = processor["speed"][:-3]
                else:
                    speed = processor["speed"]
                processor["speed"] = int(round(float(speed)) - 1)
        except ValueError:
            processor["speed"] = -1

        # Adjust count
        try:
            processor["count"] = int(processor["count"])
        except ValueError:
            processor["count"] = 1
        else:
            # There is at least one processor
            if processor["count"] == 0:
                processor["count"] = 1

        result.setProcessor(processor)