summaryrefslogtreecommitdiffstats
path: root/debian/lib/python/debian_linux/firmware.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:49:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:49:59 +0000
commit01997497f915e8f79871f3f2acb55ac465051d24 (patch)
tree1ce1afd7246e1014199e15cbf854bf7924458e5d /debian/lib/python/debian_linux/firmware.py
parentAdding upstream version 6.1.76. (diff)
downloadlinux-01997497f915e8f79871f3f2acb55ac465051d24.tar.xz
linux-01997497f915e8f79871f3f2acb55ac465051d24.zip
Adding debian version 6.1.76-1.debian/6.1.76-1debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/lib/python/debian_linux/firmware.py')
-rw-r--r--debian/lib/python/debian_linux/firmware.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/debian/lib/python/debian_linux/firmware.py b/debian/lib/python/debian_linux/firmware.py
new file mode 100644
index 000000000..592a66a45
--- /dev/null
+++ b/debian/lib/python/debian_linux/firmware.py
@@ -0,0 +1,90 @@
+import re
+
+
+class FirmwareFile(object):
+ def __init__(self, binary, desc=None, source=None, version=None):
+ self.binary = binary
+ self.desc = desc
+ self.source = source
+ self.version = version
+
+
+class FirmwareSection(object):
+ def __init__(self, driver, files, licence):
+ self.driver = driver
+ self.files = files
+ self.licence = licence
+
+
+class FirmwareWhence(list):
+ def __init__(self, file):
+ self.read(file)
+
+ def read(self, file):
+ in_header = True
+ driver = None
+ files = {}
+ licence = None
+ binary = []
+ desc = None
+ source = []
+ version = None
+
+ for line in file:
+ if line.startswith('----------'):
+ if in_header:
+ in_header = False
+ else:
+ # Finish old section
+ if driver:
+ self.append(FirmwareSection(driver, files, licence))
+ driver = None
+ files = {}
+ licence = None
+ continue
+
+ if in_header:
+ continue
+
+ if line == '\n':
+ # End of field; end of file fields
+ for b in binary:
+ # XXX The WHENCE file isn't yet consistent in its
+ # association of binaries and their sources and
+ # metadata. This associates all sources and
+ # metadata in a group with each binary.
+ files[b] = FirmwareFile(b, desc, source, version)
+ binary = []
+ desc = None
+ source = []
+ version = None
+ continue
+
+ match = re.match(
+ r'(Driver|File|Info|Licen[cs]e|Source|Version'
+ r'|Original licen[cs]e info(?:rmation)?):\s*(.*)\n',
+ line)
+ if match:
+ keyword, value = match.group(1, 2)
+ if keyword == 'Driver':
+ driver = value.split(' ')[0].lower()
+ elif keyword == 'File':
+ match = re.match(r'(\S+)(?:\s+--\s+(.*))?', value)
+ binary.append(match.group(1))
+ desc = match.group(2)
+ elif keyword in ['Info', 'Version']:
+ version = value
+ elif keyword == 'Source':
+ source.append(value)
+ else:
+ licence = value
+ elif licence is not None:
+ licence = (licence + '\n'
+ + re.sub(r'^(?:[/ ]\*| \*/)?\s*(.*?)\s*$', r'\1',
+ line))
+
+ # Finish last section if non-empty
+ for b in binary:
+ files[b] = FirmwareFile(b, desc, source, version)
+ if driver:
+ self.append(FirmwareSection(driver, files, licence))