File: lshwjson.py

package info (click to toggle)
checkbox-support 0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,620 kB
  • ctags: 1,369
  • sloc: python: 4,991; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
import json

class LshwJsonParser:

    def __init__(self, stream_or_string):
        self.stream_or_string = stream_or_string

    def _parse_lshw(self, lshw, result):
        if 'children' in lshw.keys():
            for child in lshw['children']:
                self._parse_lshw(child, result)
            del lshw['children']

        result.addHardware(lshw)

    def run(self, result):
        try:
            lshw = json.loads(self.stream_or_string)
        except:
            print('not valid json')

        self._parse_lshw(lshw, result)