On 10/7/19 6:10 PM, Jan Kiszka wrote:
> On 30.09.19 21:13, Andrej Utz wrote:
>> From: Ralf Ramsauer <[email protected]>
>>
>> Do this step by step. First of all, let's create a new routine that is able
>> to
>> parse a line from /proc/iomem or /proc/ioports. Both files share the same
>> layout, so we can use a common parser.
>>
>> Passing the destination type of the entry to the parser allows to share code.
>>
>> Signed-off-by: Ralf Ramsauer <[email protected]>
>> ---
>> pyjailhouse/sysfs_parser.py | 21 ++++++++++++---------
>> 1 file changed, 12 insertions(+), 9 deletions(-)
>>
>> diff --git a/pyjailhouse/sysfs_parser.py b/pyjailhouse/sysfs_parser.py
>> index b0a9bf44..a179461d 100644
>> --- a/pyjailhouse/sysfs_parser.py
>> +++ b/pyjailhouse/sysfs_parser.py
>> @@ -824,6 +824,17 @@ class IOAPIC:
>> return (self.iommu << 16) | self.bdf
>>
>>
>> +class IORegionTree:
>> + @staticmethod
>> + def parse_io_line(line, TargetClass):
>> + region, type = line.split(' : ', 1)
>
> (region, type)
>
>> + level = int(region.count(' ') / 2) + 1
>> + type = type.strip()
>> + region = [r.strip() for r in region.split('-', 1)]
>> +
>> + return level, TargetClass(int(region[0], 16), int(region[1], 16),
>> type)
>
> Doesn't the style checker complain about a long line here?
Should it? It's 79 characters.
Ralf
>
> However, this looks a bit nicer now.
>
>> +
>> +
>> class IOMemRegionTree:
>> def __init__(self, region, level):
>> self.region = region
>> @@ -864,14 +875,6 @@ class IOMemRegionTree:
>>
>> return [before_kernel, kernel_region, after_kernel]
>>
>> - @staticmethod
>> - def parse_iomem_line(line):
>> - a = line.split(':', 1)
>> - level = int(a[0].count(' ') / 2) + 1
>> - region = a[0].split('-', 1)
>> - a[1] = a[1].strip()
>> - return level, MemRegion(int(region[0], 16), int(region[1], 16),
>> a[1])
>> -
>> @staticmethod
>> def parse_iomem_file():
>> root = IOMemRegionTree(None, 0)
>> @@ -879,7 +882,7 @@ class IOMemRegionTree:
>> lastlevel = 0
>> lastnode = root
>> for line in f:
>> - (level, r) = IOMemRegionTree.parse_iomem_line(line)
>> + level, r = IORegionTree.parse_io_line(line, MemRegion)
>
> Style again.
>
>> t = IOMemRegionTree(r, level)
>> if (t.level > lastlevel):
>> t.parent = lastnode
>>
>
> Jan
>
--
You received this message because you are subscribed to the Google Groups
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jailhouse-dev/cd7c421a-ac43-93b6-29bb-75fdee9b9593%40oth-regensburg.de.