]> Savannah Git Hosting - gnulib.git/commitdiff
config: LGPL license dict; support gl_LGPL values
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 26 Sep 2017 14:43:37 +0000 (17:43 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Tue, 26 Sep 2017 15:11:00 +0000 (18:11 +0300)
pygnulib/config.py

index 4f2bb6b0d1a9954bc4a4ef7c172f82be21ad2696..7d0e528018a3d04943b5f572a015e8f8e1515fc4 100644 (file)
@@ -46,6 +46,11 @@ class LicenseSet:
         "LGPLv3",
         "LGPLv3+",
     )
+    _LGPL_ = {
+        "2": ("LGPLv2", "LGPLv2+"),
+        "3": ("LGPLv2+", "LGPLv3", "LGPLv3+"),
+        "3orGPLv2": ("LGPLv2+", "LGPLv3+", "GPLv2"),
+    }
 
     def __init__(self, choice=None):
         if choice is None:
@@ -56,10 +61,10 @@ class LicenseSet:
         variants = tuple(map(str.casefold, LicenseSet._TABLE_))
         for variant in choice:
             _type_assert_("variant", variant, str)
-            variant = variant.casefold()
-            if variant not in variants:
+            if variant.casefold() not in variants:
                 raise _UnknownLicenseError_(variant)
-            self.__variants.add(LicenseSet._TABLE_[variants.index(variant)])
+            index = variants.index(variant.casefold())
+            self.__variants.add(LicenseSet._TABLE_[index])
         self.__variants = set(sorted(self.__variants))
 
     def __repr__(self):
@@ -82,6 +87,10 @@ class LicenseSet:
             return False
         return set(self) == set(variant)
 
+    @staticmethod
+    def LGPL():
+        return dict(LicenseSet._LGPL_)
+
 
 
 class Base:
@@ -546,7 +555,7 @@ class Cache(Base):
         "lib"               : (str, _regex_(r"gl_LIB\(\[(.*?)\]\)")),
         "modules"           : (list, _regex_(r"gl_MODULES\(\[(.*?)\]\)")),
         "avoid"             : (list, _regex_(r"gl_AVOID\(\[(.*?)\]\)")),
-        "lgpl"              : (str, _regex_(r"gl_LGPL\(\[(.*?)\]\)")),
+        "license"           : (str, _regex_(r"gl_LGPL\(\[(.*?)\]\)")),
     }
 
 
@@ -585,7 +594,10 @@ class Cache(Base):
         for (key, (typeid, pattern)) in Cache._GNULIB_CACHE_.items():
             match = pattern.findall(data)
             if match and key not in explicit:
-                if typeid is bool:
+                if key == "license":
+                    lgpl = LicenseSet.LGPL()
+                    self[key] = lgpl[match[-1]]
+                elif typeid is bool:
                     self[key] = True
                 elif typeid is str:
                     self[key] = match[-1].strip()