diff options
author | Dmitry Selyutin <ghostmansd@gmail.com> | 2017-09-02 13:05:18 +0300 |
---|---|---|
committer | Dmitry Selyutin <ghostmansd@gmail.com> | 2017-09-02 13:05:45 +0300 |
commit | e0dc24d265569ab687b9df9984e27a394370628e (patch) | |
tree | 4254ade7b77d9120e7309c4ca5b9d89f087d542b | |
parent | 109b0eff35bbb0ef27d52df08c04fd84a72c6764 (diff) | |
download | gnulib-e0dc24d265569ab687b9df9984e27a394370628e.tar.gz |
further FileModule simpifications; minor cleanup in Config
-rw-r--r-- | pygnulib/config.py | 14 | ||||
-rw-r--r-- | pygnulib/module.py | 22 |
2 files changed, 24 insertions, 12 deletions
diff --git a/pygnulib/config.py b/pygnulib/config.py index 6058ca1006..50c6c4d766 100644 --- a/pygnulib/config.py +++ b/pygnulib/config.py @@ -7,10 +7,10 @@ import os import re + class Config: """gnulib generic configuration""" _TABLE_ = { - "gnulib" : "", "root" : "", "local_dir" : "", "source_base" : "lib", @@ -38,10 +38,6 @@ class Config: } - 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 @@ class Config: 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 @@ class Config: 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 @@ class CachedConfig(Config): 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) diff --git a/pygnulib/module.py b/pygnulib/module.py index b72847d780..c2875dcb6d 100644 --- a/pygnulib/module.py +++ b/pygnulib/module.py @@ -346,6 +346,22 @@ class Module: 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 @@ class FileModule(Module): 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: |