[firmware-free] 11/19: check_upstream.py: Split license check into multiple functions

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Sun May 22 22:54:42 UTC 2016


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch master
in repository firmware-free.

commit 88507735280e1d147e562ed5026788dc2c3bd8bb
Author: Ben Hutchings <ben at decadent.org.uk>
Date:   Fri Oct 16 19:23:19 2015 +0100

    check_upstream.py: Split license check into multiple functions
    
    [bwh: Cherry-picked from firmware-nonfree commit
     d599c6ca3fc04c6a7539b7c9e2cbade63ddea51b.  For firmware-free, check for
     DistState.free and keep copying source files.]
---
 debian/bin/check_upstream.py | 63 ++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/debian/bin/check_upstream.py b/debian/bin/check_upstream.py
index 42bc2b4..4baaf7b 100755
--- a/debian/bin/check_upstream.py
+++ b/debian/bin/check_upstream.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 
 import errno, filecmp, fnmatch, glob, os.path, re, sys
+from enum import Enum
 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)])
@@ -9,6 +10,41 @@ sys.path.append('/usr/share/linux-support-%s/lib/python' %
 from debian_linux.firmware import FirmwareWhence
 from debian_linux.config import ConfigParser, SchemaItemList
 
+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(?:v2|\+)?\b', 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 = ConfigParser({
             'base': {'packages': SchemaItemList()},
@@ -19,32 +55,13 @@ def main(source_dir):
     exclusions = config['upstream',]['exclude']
 
     for section in FirmwareWhence(open(os.path.join(source_dir, 'WHENCE'))):
-        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'
-                     r'|^GPL(?:v2|\+)?\b',
-                     section.licence):
-            # Suitable for main if source is available or binary is
-            # preferred form for modification
+        if check_section(section) == DistState.free:
             for file_info in section.files.values():
-                if any(fnmatch.fnmatch(file_info.binary, exclusion)
-                       for exclusion in exclusions):
-                    continue
-                sources = set()
-                if file_info.source or file_info.binary.endswith('.cis'):
+                if not any(fnmatch.fnmatch(file_info.binary, exclusion)
+                           for exclusion in exclusions):
                     update_file(source_dir, dest_dirs, file_info.binary)
                     for source in file_info.source:
-                        sources.add(source)
-                for source in sources:
-                    update_file(source_dir, dest_dirs, source)
+                        update_file(source_dir, dest_dirs, source)
 
 def update_file(source_dir, dest_dirs, filename):
     source_file = os.path.join(source_dir, filename)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/firmware-free.git



More information about the Kernel-svn-changes mailing list