pull: Use sets of licenses in TAGS
authorW. Trevor King <wking@tremily.us>
Fri, 20 Oct 2017 17:46:26 +0000 (10:46 -0700)
committerW. Trevor King <wking@tremily.us>
Fri, 20 Oct 2017 17:46:26 +0000 (10:46 -0700)
Because the FSF considers GPL- and FDL-compatible licenses
free-as-in-libre as well.

pull.py

diff --git a/pull.py b/pull.py
index 4173591aabe26deba54acc024b4ae1f0de7803bb..880dca17b1f9c9381edac60b0bc8a14f48b7bb52 100755 (executable)
--- a/pull.py
+++ b/pull.py
@@ -18,11 +18,11 @@ except ImportError:
 URI = 'https://www.gnu.org/licenses/license-list.html'
 
 TAGS = {
-    'blue': 'viewpoint',
-    'green': 'glp-compatible',
-    'orange': 'libre',
-    'purple': 'fdl-compatible',
-    'red': 'non-free',
+    'blue': {'viewpoint'},
+    'green': {'glp-compatible', 'libre'},
+    'orange': {'libre'},
+    'purple': {'fdl-compatible', 'libre'},
+    'red': {'non-free'},
 }
 
 SPLITS = {
@@ -119,7 +119,7 @@ def extract(root, base_uri=None):
     licenses = {}
     for dl in root.iter(tag='{http://www.w3.org/1999/xhtml}dl'):
         try:
-            tag = TAGS[dl.attrib.get('class')]
+            tags = TAGS[dl.attrib.get('class')]
         except KeyError:
             raise ValueError(
                 'unrecognized class {!r}'.format(dl.attrib.get('class')))
@@ -129,7 +129,7 @@ def extract(root, base_uri=None):
             oid = a.attrib['id']
             for id in SPLITS.get(oid, [oid]):
                 license = {
-                    'tags': [tag],
+                    'tags': tags.copy(),
                 }
                 if a.text and a.text.strip():
                     license['name'] = a.text.strip()
@@ -146,8 +146,7 @@ def extract(root, base_uri=None):
                 if id not in licenses:
                     licenses[id] = license
                 else:
-                    licenses[id]['tags'].append(tag)
-                    licenses[id]['tags'].sort()
+                    licenses[id]['tags'].update(tags)
     return licenses
 
 
@@ -164,6 +163,9 @@ def save(licenses, dir=os.curdir):
         json.dump(obj=index, fp=f, indent=2, sort_keys=True)
         f.write('\n')
     for id, license in licenses.items():
+        license = license.copy()
+        if 'tags' in license:
+            license['tags'] = sorted(license['tags'])
         with open(os.path.join(dir, '{}.json'.format(id)), 'w') as f:
             json.dump(obj=license, fp=f, indent=2, sort_keys=True)
             f.write('\n')