summaryrefslogtreecommitdiffstats
path: root/debian/bin/check_upstream.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 08:03:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 08:03:40 +0000
commit6a254b9c2391d68199836601525220b5c5f8c0db (patch)
treed1e96c6ffb5ba431feee7e953a5ed15e56098248 /debian/bin/check_upstream.py
parentAdding upstream version 20200122. (diff)
downloadfirmware-free-debian/20200122-4.tar.xz
firmware-free-debian/20200122-4.zip
Adding debian version 20200122-4.debian/20200122-4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/bin/check_upstream.py')
-rwxr-xr-xdebian/bin/check_upstream.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/debian/bin/check_upstream.py b/debian/bin/check_upstream.py
new file mode 100755
index 0000000..a1ad61b
--- /dev/null
+++ b/debian/bin/check_upstream.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+
+import errno, filecmp, fnmatch, glob, os.path, re, sys
+from debian import deb822
+from enum import Enum
+
+sys.path.insert(0, "debian/lib/python")
+rules_defs = dict((match.group(1), match.group(2))
+ for line in open('debian/rules.defs')
+ for match in [re.match(r'(\w+)\s*:=\s*(.*)\n', line)])
+sys.path.append('/usr/share/linux-support-%s/lib/python' %
+ rules_defs['KERNELVERSION'])
+from debian_linux.firmware import FirmwareWhence
+from config import Config
+
+class DistState(Enum):
+ undistributable = 1
+ non_free = 2
+ free = 3
+
+def is_source_available(section):
+ for file_info in section.files.values():
+ if not (file_info.source or file_info.binary.endswith('.cis')):
+ return False
+ return True
+
+def check_section(section):
+ if re.search(r'^BSD\b'
+ r'|^GPLv2 or OpenIB\.org BSD\b'
+ r'|\bPermission\s+is\s+hereby\s+granted\s+for\s+the\s+'
+ r'distribution\s+of\s+this\s+firmware\s+(?:data|image)\b'
+ r'(?!\s+as\s+part\s+of)'
+ r'|\bRedistribution\s+and\s+use\s+in(?:\s+source\s+and)?'
+ r'\s+binary\s+forms\b'
+ r'|\bPermission\s+is\s+hereby\s+granted\b[^.]+\sto'
+ r'\s+deal\s+in\s+the\s+Software\s+without'
+ r'\s+restriction\b'
+ r'|\bredistributable\s+in\s+binary\s+form\b',
+ section.licence):
+ return (DistState.free if is_source_available(section)
+ else DistState.non_free)
+ elif re.match(r'^(?:D|Red)istributable\b', section.licence):
+ return DistState.non_free
+ elif re.match(r'^GPL(?:v[23]|\+)?\b|^Dual GPL(?:v[23])?/', section.licence):
+ return (DistState.free if is_source_available(section)
+ else DistState.undistributable)
+ else:
+ # Unrecognised and probably undistributable
+ return DistState.undistributable
+
+def main(source_dir='.'):
+ config = Config()
+ over_dirs = ['debian/config/' + package for
+ package in config['base',]['packages']]
+ with open("debian/copyright") as f:
+ exclusions = deb822.Deb822(f).get("Files-Excluded", '').strip().split()
+ packaged_files = {}
+ for package in config['base',]['packages']:
+ for filename in config['base', package]['files']:
+ packaged_files[filename] = package
+
+ for section in FirmwareWhence(open(os.path.join(source_dir, 'WHENCE'))):
+ dist_state = check_section(section)
+ for file_info in section.files.values():
+ if dist_state == DistState.free:
+ if not any(fnmatch.fnmatch(file_info.binary, exclusion)
+ for exclusion in exclusions):
+ if file_info.binary in packaged_files:
+ update_file(source_dir, over_dirs, file_info.binary)
+ for source in file_info.source:
+ update_file(source_dir, over_dirs, source)
+ elif os.path.isfile(filename):
+ print('I: %s is not included in any binary package' %
+ file_info.binary)
+ else:
+ print('I: %s: could be added' % file_info.binary)
+ elif dist_state == DistState.non_free:
+ if os.path.isfile(file_info.binary):
+ print('W: %s appears to be non-free' %
+ file_info.binary)
+ elif dist_state == DistState.undistributable:
+ if os.path.isfile(file_info.binary):
+ print('W: %s appears to be undistributable' %
+ file_info.binary)
+
+def update_file(source_dir, over_dirs, filename):
+ source_file = os.path.join(source_dir, filename)
+ for over_dir in over_dirs:
+ for over_file in ([os.path.join(over_dir, filename)] +
+ glob.glob(os.path.join(over_dir, filename + '-*'))):
+ if os.path.isfile(over_file):
+ if not filecmp.cmp(source_file, over_file, True):
+ print('I: %s: changed' % filename)
+ return
+
+if __name__ == '__main__':
+ main(*sys.argv[1:])