# encoding: UTF-8
+
import argparse
import codecs
import os
import re
import sys
-from .error import AutoconfVersionError
+from .error import AutoconfVersionError as _AutoconfVersionError_
+
-class Config:
+class Base:
"""gnulib generic configuration"""
_TABLE_ = {
"root" : "",
def __init__(self, **kwargs):
self.__table = dict()
- for key in Config._TABLE_:
- self.__table[key] = Config._TABLE_[key]
+ for key in Base._TABLE_:
+ self.__table[key] = Base._TABLE_[key]
for key, value in kwargs.items():
self[key] = value
def __iter__(self):
- for key in Config._TABLE_:
+ for key in Base._TABLE_:
value = self[key]
yield key, value
def include_guard_prefix(self):
"""include guard prefix"""
prefix = self["macro_prefix"].upper()
- default = Config._TABLE_["macro_prefix"]
+ default = Base._TABLE_["macro_prefix"]
return "GL_%s" % prefix if prefix == default else "GL"
def __getitem__(self, key):
- if key not in Config._TABLE_:
+ if key not in Base._TABLE_:
key = key.replace("-", "_")
- if key not in Config._TABLE_:
+ if key not in Base._TABLE_:
raise KeyError("unsupported option: %r" % key)
return self.__table[key]
def __setitem__(self, key, value):
- if key not in Config._TABLE_:
+ if key not in Base._TABLE_:
key = key.replace("_", "-")
- if key not in Config._TABLE_:
+ if key not in Base._TABLE_:
raise KeyError("unsupported option: %r" % key)
key = key.replace("-", "_")
- typeid = type(Config._TABLE_[key])
+ typeid = type(Base._TABLE_[key])
if key == "lgpl":
if value not in [None, 2, 3]:
raise TypeError("lgpl option must be either None or integral version (2 or 3)")
elif key == "autoconf":
if value < 2.59:
- raise AutoconfVersionError(2.59)
+ raise _AutoconfVersionError_(2.59)
elif not isinstance(value, typeid):
raise TypeError("%r option must be of %r type" % (key, typeid))
self.__table[key] = value
return self.__table.values()
-class Cache(Config):
+class Cache(Base):
"""gnulib cached configuration"""
_AUTOCONF_ = {
"autoconf" : re.compile(".*AC_PREREQ\\(\\[(.*?)\\]\\)", re.S | re.M),
-class CommandLine(Config):
+class CommandLine(Base):
"""gnulib-tool command line configuration"""
_LIST_ = (1 << 0)
_FIND_ = (1 << 1)
import os
-from .config import Config
-from .module import Module
-from .module import FileModule
+from .config import Base as _BaseConfig_
+from .module import Base as _BaseModule_
+from .module import File as _FileModule_
def __init__(self, root, config):
if not isinstance(root, str):
raise TypeError("root must be of 'str' type")
- if not isinstance(config, Config):
+ if not isinstance(config, _BaseConfig_):
raise TypeError("config must be of 'Config' type")
if not os.path.exists(root):
raise FileNotFoundError(root)
if name in Git._EXCLUDE_:
raise ValueError("illegal module name")
path = os.path.join(self["modules"], name)
- return FileModule(path, name=name) if full else Module(name)
+ return _FileModule_(path, name=name) if full else _BaseModule_(name)
def modules(self, full=True):
import os
-from .config import Config
-from .module import Module
+from .config import Base as _BaseConfig_
+from .module import Base as _BaseModule_
"USE_MSGCTXT = no"
)
def __init__(self, config):
- if not isinstance(config, Config):
+ if not isinstance(config, _BaseConfig_):
raise TypeError("config must be of pygnulib.Config type")
super().__init__()
self.__config = config
class POTFILES(Generator):
"""file list to be passed to xgettext"""
def __init__(self, config, files):
- if not isinstance(config, Config):
+ if not isinstance(config, _BaseConfig_):
raise TypeError("config must be of pygnulib.Config type")
super().__init__()
self.__config = config
no_libtool: disable libtool (regardless of configuration)
no_gettext: disable AM_GNU_GETTEXT invocations if True
"""
- if not isinstance(config, Config):
+ if not isinstance(config, _BaseConfig_):
raise TypeError("config must be of pygnulib.config.Config type")
- if not isinstance(module, Module):
+ if not isinstance(module, _BaseModule_):
raise TypeError("module must be of pygnulib.module.Module type")
if not isinstance(toplevel, bool):
raise TypeError("toplevel must be of bool type")
config: gnulib configuration
macro_prefix: macro prefix; if None, consider configuration
"""
- if not isinstance(config, Config):
+ if not isinstance(config, _BaseConfig_):
raise TypeError("config must be of pygnulib.config.Config type")
if macro_prefix is None:
macro_prefix = config.macro_prefix
-class Module:
+class Base:
"""gnulib generic module"""
_TABLE_ = {
"description" : (0x00, str, "Description"),
raise TypeError("name must be of 'str' type")
self.__name = name
self.__table = {"maintainers": ["all"]}
- for key in Module._TABLE_:
+ for key in Base._TABLE_:
self.__table[key] = ""
for key, value in kwargs.items():
self.__table[key] = value
def dependencies(self):
"""dependencies iterator (name, condition)"""
for entry in self.__table["dependencies"]:
- yield Module._PATTERN_DEPENDENCIES_.findall(entry)[0]
+ yield Base._PATTERN_DEPENDENCIES_.findall(entry)[0]
@dependencies.setter
def dependencies(self, iterable):
def include(self):
"""include files iterator (header, comment)"""
for entry in self.__table["include"]:
- match = Module._PATTERN_INCLUDE_.findall(entry)
+ match = Base._PATTERN_INCLUDE_.findall(entry)
yield match[0] if match else entry
@include.setter
def __str__(self):
result = ""
- for key, (_, typeid, field) in sorted(Module._TABLE_.items(), key=lambda k: k[1][0]):
+ for key, (_, typeid, field) in sorted(Base._TABLE_.items(), key=lambda k: k[1][0]):
field += ":\n"
if typeid is list:
value = "\n".join(self.__table[key])
-class FileModule(Module):
+class File(Base):
"""gnulib module text file"""
_TABLE_ = {
"Description" : (str, "description"),
"License" : (str, "license"),
"Maintainer" : (list, "maintainers"),
}
- _FIELDS_ = [field for (_, _, field) in Module._TABLE_.values()]
+ _FIELDS_ = [field for (_, _, field) in Base._TABLE_.values()]
_PATTERN_ = re.compile("(%s):" % "|".join(_FIELDS_))
or (line.startswith("/*") and line.endswith("*/")):
continue
data += (line + "\n")
- match = FileModule._PATTERN_.split(data)[1:]
+ match = File._PATTERN_.split(data)[1:]
for (group, value) in zip(match[::2], match[1::2]):
- (typeid, key) = FileModule._TABLE_[group]
+ (typeid, key) = File._TABLE_[group]
if typeid is list:
table[key] = [_ for _ in "".join(value).split("\n") if _.strip()]
else: