changeset 38779:e135f194be44

further FileModule simpifications; minor cleanup in Config
author Dmitry Selyutin <ghostmansd@gmail.com>
date Sat, 02 Sep 2017 13:05:18 +0300
parents db1f261e1da2
children 4c74fcde64e0
files pygnulib/config.py pygnulib/module.py
diffstat 2 files changed, 24 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pygnulib/config.py	Sun Aug 27 14:30:26 2017 +0300
+++ b/pygnulib/config.py	Sat Sep 02 13:05:18 2017 +0300
@@ -7,10 +7,10 @@
 import re
 
 
+
 class Config:
     """gnulib generic configuration"""
     _TABLE_ = {
-        "gnulib"            : "",
         "root"              : "",
         "local_dir"         : "",
         "source_base"       : "lib",
@@ -38,10 +38,6 @@
     }
 
 
-    def __repr__(self):
-        return repr(self.__dict__["_table_"])
-
-
     def __init__(self, **kwargs):
         self.__dict__["_table_"] = dict()
         for key in Config._TABLE_:
@@ -50,6 +46,10 @@
             self[key] = value
 
 
+    def __repr__(self):
+        return repr(self.__dict__["_table_"])
+
+
     def __setattr__(self, key, value):
         self[key] = value
         self.__dict__[key] = value
@@ -80,7 +80,7 @@
                 raise TypeError("lgpl option must be either None or integral version (2 or 3)")
         elif key == "autoconf":
             if value < 2.59:
-                raise NotImplementedError("pygnulib ")
+                raise AutoconfVersionError(2.59)
         elif not isinstance(value, typeid):
             raise TypeError("%r option must be of %r type" % (key, typeid))
 
@@ -142,7 +142,7 @@
     def __init__(self, root, autoconf=None, **kwargs):
         if not isinstance(root, str):
             raise TypeError("root must be of 'str' type")
-        super(CachedConfig, self).__init__(**kwargs)
+        super().__init__(**kwargs)
         self._autoconf_(root, autoconf)
         self._gnulib_cache_(root)
         self._gnulib_comp_(root)
--- a/pygnulib/module.py	Sun Aug 27 14:30:26 2017 +0300
+++ b/pygnulib/module.py	Sat Sep 02 13:05:18 2017 +0300
@@ -346,6 +346,22 @@
 
 class FileModule(Module):
     """gnulib module text file"""
+    _TABLE_ = {
+        "Description"        : (str, "description"),
+        "Comment"            : (str, "comment"),
+        "Status"             : (str, "status"),
+        "Notice"             : (str, "notice"),
+        "Applicability"      : (str, "applicability"),
+        "Files"              : (list, "files"),
+        "Depends-on"         : (list, "dependencies"),
+        "configure.ac-early" : (str, "configure_early"),
+        "configure.ac"       : (str, "configure"),
+        "Makefile.am"        : (str, "makefile"),
+        "Include"            : (list, "include"),
+        "Link"               : (list, "link"),
+        "License"            : (str, "license"),
+        "Maintainer"         : (list, "maintainers"),
+    }
     _FIELDS_ = [field for (_, _, field) in Module._TABLE_.values()]
     _PATTERN_ = re.compile("(%s):" % "|".join(_FIELDS_))
 
@@ -366,11 +382,7 @@
                     data += (line + "\n")
             match = FileModule._PATTERN_.split(data)[1:]
             for (group, value) in zip(match[::2], match[1::2]):
-                key = None
-                typeid = type(None)
-                for key, (_, typeid, field) in Module._TABLE_.items():
-                    if group == field:
-                        break
+                (typeid, key) = FileModule._TABLE_[group]
                 if typeid is list:
                     self._table_[key] = [_ for _ in "".join(value).split("\n") if _.strip()]
                 else: