-import argparse
-import codecs
-import collections
-import os
-import re
-import sys
+import argparse as _argparse_
+import codecs as _codecs_
+import collections as _collections_
+import os as _os_
+import re as _re_
+import sys as _sys_
+
from .error import type_assert as _type_assert_
from .error import AutoconfVersionError as _AutoconfVersionError_
class Cache(Base):
"""gnulib cached configuration"""
_AUTOCONF_ = {
- "autoconf" : re.compile(".*AC_PREREQ\\(\\[(.*?)\\]\\)", re.S | re.M),
- "auxdir" : re.compile("^AC_CONFIG_AUX_DIR\\(\\[(.*?)\\]\\)$", re.S | re.M),
- "libtool" : re.compile("A[CM]_PROG_LIBTOOL", re.S | re.M)
+ "autoconf" : _re_.compile(".*AC_PREREQ\\(\\[(.*?)\\]\\)", _re_.S | _re_.M),
+ "auxdir" : _re_.compile("^AC_CONFIG_AUX_DIR\\(\\[(.*?)\\]\\)$", _re_.S | _re_.M),
+ "libtool" : _re_.compile("A[CM]_PROG_LIBTOOL", _re_.S | _re_.M)
}
_GNULIB_CACHE_ = {
"local" : (str, "gl_LOCAL_DIR"),
_GNULIB_CACHE_STR_ += [_key_]
else:
_GNULIB_CACHE_LIST_ += [_key_]
- _GNULIB_CACHE_PATTERN_ = re.compile("^(gl_.*?)\\(\\[(.*?)\\]\\)$", re.S | re.M)
+ _GNULIB_CACHE_PATTERN_ = _re_.compile("^(gl_.*?)\\(\\[(.*?)\\]\\)$", _re_.S | _re_.M)
def __init__(self, root, m4_base, autoconf=None, **kwargs):
def __autoconf(self, root, autoconf):
if not autoconf:
- autoconf = os.path.join(root, "configure.ac")
- if not os.path.exists(autoconf):
- autoconf = os.path.join(root, "configure.in")
- if not os.path.isabs(autoconf):
- autoconf = os.path.join(root, autoconf)
- autoconf = os.path.normpath(autoconf)
- with codecs.open(autoconf, "rb", "UTF-8") as stream:
+ autoconf = _os_.path.join(root, "configure.ac")
+ if not _os_.path.exists(autoconf):
+ autoconf = _os_.path.join(root, "configure.in")
+ if not _os_.path.isabs(autoconf):
+ autoconf = _os_.path.join(root, autoconf)
+ autoconf = _os_.path.normpath(autoconf)
+ with _codecs_.open(autoconf, "rb", "UTF-8") as stream:
data = stream.read()
for key, pattern in Cache._AUTOCONF_.items():
match = pattern.findall(data)
def __gnulib_cache(self, root):
m4base = self.m4_base
- gnulib_cache = os.path.join(root, m4base, "gnulib-cache.m4")
- if os.path.exists(gnulib_cache):
- with codecs.open(gnulib_cache, "rb", "UTF-8") as stream:
+ gnulib_cache = _os_.path.join(root, m4base, "gnulib-cache.m4")
+ if _os_.path.exists(gnulib_cache):
+ with _codecs_.open(gnulib_cache, "rb", "UTF-8") as stream:
data = stream.read()
for key in Cache._GNULIB_CACHE_BOOL_:
(_, macro) = Cache._GNULIB_CACHE_[key]
def __gnulib_comp(self, root):
m4base = self.m4_base
- gnulib_comp = os.path.join(root, m4base, "gnulib-comp.m4")
- if os.path.exists(gnulib_comp):
- with codecs.open(gnulib_comp, "rb", "UTF-8") as stream:
+ gnulib_comp = _os_.path.join(root, m4base, "gnulib-comp.m4")
+ if _os_.path.exists(gnulib_comp):
+ with _codecs_.open(gnulib_comp, "rb", "UTF-8") as stream:
data = stream.read()
regex = "AC_DEFUN\\(\\[%s_FILE_LIST\\], \\[(.*?)\\]\\)" % self["macro-prefix"]
- pattern = re.compile(regex, re.S | re.M)
+ pattern = _re_.compile(regex, _re_.S | _re_.M)
match = pattern.findall(data)
if match:
self.files = [_.strip() for _ in match[-1].split("\n") if _.strip()]
_LINK_NOTICE_ = (1 << 3)
- class _ModeAction_(argparse.Action):
+ class _ModeAction_(_argparse_.Action):
def __init__(self, *args, **kwargs):
mode = kwargs["const"]
kwargs["dest"] = "mode"
setattr(namespace, self.dest, new_mode)
- class _AvoidAction_(argparse.Action):
+ class _AvoidAction_(_argparse_.Action):
def __call__(self, parser, namespace, value, option=None):
values = getattr(namespace, self.dest)
values += value
- class _VerboseAction_(argparse.Action):
+ class _VerboseAction_(_argparse_.Action):
def __call__(self, parser, namespace, value, option=None):
value = getattr(namespace, self.dest)
verbose = option in ("-v", "--verbose")
setattr(namespace, self.dest, value)
- class _LinkAction_(argparse.Action):
+ class _LinkAction_(_argparse_.Action):
def __call__(self, parser, namespace, value, option=None):
flags = getattr(namespace, self.dest)
symlink = ("-s", "--symlink", "--local-symlink", "-S", "--more-symlink")
def __init__(self, program, argv, **kwargs):
_type_assert_("program", program, str)
- _type_assert_("argv", argv, collections.Iterable)
+ _type_assert_("argv", argv, _collections_.Iterable)
super().__init__(**kwargs)
- parser = argparse.ArgumentParser(prog=program, add_help=False, allow_abbrev=False)
+ parser = _argparse_.ArgumentParser(prog=program, add_help=False, allow_abbrev=False)
for (_, _, args) in CommandLine._SECTIONS_:
for arg in args:
(options, kwargs) = arg
parser.add_argument(*options, **kwargs)
- self.__program = os.path.basename(program)
+ self.__program = _os_.path.basename(program)
parser.format_usage = self.__usage
parser.format_help = self.__help
if "--help" in argv:
parser.print_help()
- sys.exit(0)
+ _sys_.exit(0)
namespace = parser.parse_args(argv)
namespace = vars(namespace)
-import os
+import os as _os_
+
from .error import type_assert as _type_assert_
from .config import Base as _BaseConfig_
def __init__(self, root, config):
_type_assert_("root", root, str)
_type_assert_("config", config, _BaseConfig_)
- if not os.path.exists(root):
+ if not _os_.path.exists(root):
raise FileNotFoundError(root)
- if not os.path.isdir(root):
+ if not _os_.path.isdir(root):
raise NotADirectoryError(root)
self.__config = config
- self.__root = os.path.realpath(root)
+ self.__root = _os_.path.realpath(root)
def __getitem__(self, name):
_type_assert_("name", name, str)
parts = []
replaced = False
- path = os.path.normpath(name)
- if os.path.isabs(path):
+ path = _os_.path.normpath(name)
+ if _os_.path.isabs(path):
raise ValueError("name must be a relative path")
- for part in path.split(os.path.sep):
+ for part in path.split(_os_.path.sep):
if part == "..":
parts += [part]
continue
part = self.__config[new]
replaced = True
parts += [part]
- path = os.path.sep.join([self.__root] + parts)
- if not os.path.exists(path):
+ path = _os_.path.sep.join([self.__root] + parts)
+ if not _os_.path.exists(path):
raise FileNotFoundError(name)
return path
def __init__(self, root, config):
super().__init__(root, config)
- if not os.path.isdir(os.path.join(self.root, ".git")):
+ if not _os_.path.isdir(_os_.path.join(self.root, ".git")):
raise TypeError("%r is not a gnulib repository")
_type_assert_("full", full, bool)
if name in Git._EXCLUDE_:
raise ValueError("illegal module name")
- path = os.path.join(self["modules"], name)
+ path = _os_.path.join(self["modules"], name)
return _FileModule_(path, name=name) if full else _BaseModule_(name)
def modules(self, full=True):
"""iterate over all available modules"""
prefix = self["modules"]
- for root, _, files in os.walk(prefix):
+ for root, _, files in _os_.walk(prefix):
names = []
for name in files:
exclude = False
if not exclude:
names += [name]
for name in names:
- path = os.path.join(root, name)
+ path = _os_.path.join(root, name)
name = path[len(prefix) + 1:]
yield self.module(name, full)
-import os
+import os as _os_
+
from .error import type_assert as _type_assert_
from .config import Base as _BaseConfig_
yield ""
yield "# These two variables depend on the location of this directory."
yield "subdir = %s" % self.po_domain
- yield "top_subdir = %s" % "/".join([".." for _ in self.po_base.split(os.path.sep)])
+ yield "top_subdir = %s" % "/".join([".." for _ in self.po_base.split(_os_.path.sep)])
for line in POMakefile._TEMPLATE_:
yield line
yield line
yield "# List of files which contain translatable strings."
for file in [_ for _ in self.files if _.startswith("lib/")]:
- yield os.path.join(self.__config.source_base, file[4:])
+ yield _os_.path.join(self.__config.source_base, file[4:])
-import codecs
-import collections
-import hashlib
-import os
-import re
+import codecs as _codecs_
+import collections as _collections_
+import hashlib as _hashlib_
+import os as _os_
+import re as _re_
+
from .error import type_assert as _type_assert_
"license" : (0x0C, str, "License"),
"maintainers" : (0x0D, list, "Maintainer"),
}
- _PATTERN_DEPENDENCIES_ = re.compile("^(\\S+)(?:\\s+(.+))*$")
- _PATTERN_INCLUDE_ = re.compile("^[\\<\"]([A-Za-z0-9/\\-_]+\\.h)[\\>\"](?:\\s+.*^)*$")
+ _PATTERN_DEPENDENCIES_ = _re_.compile("^(\\S+)(?:\\s+(.+))*$")
+ _PATTERN_INCLUDE_ = _re_.compile("^[\\<\"]([A-Za-z0-9/\\-_]+\\.h)[\\>\"](?:\\s+.*^)*$")
def __init__(self, name, **kwargs):
@files.setter
def files(self, value):
- _type_assert_("files", value, collections.Iterable)
+ _type_assert_("files", value, _collections_.Iterable)
result = []
for item in value:
_type_assert_("file", item, str)
@dependencies.setter
def dependencies(self, value):
- _type_assert_("files", value, collections.Iterable)
+ _type_assert_("files", value, _collections_.Iterable)
result = []
for (name, condition) in value:
_type_assert_("name", name, str)
@include.setter
def include(self, value):
- _type_assert_("include", value, collections.Iterable)
+ _type_assert_("include", value, _collections_.Iterable)
result = []
for (header, comment) in value:
_type_assert_("header", header, str)
@link.setter
def link(self, value):
- _type_assert_("link", value, collections.Iterable)
+ _type_assert_("link", value, _collections_.Iterable)
result = []
for item in value:
_type_assert_("directive", item, str)
@maintainers.setter
def maintainers(self, value):
- _type_assert_("maintainers", value, collections.Iterable)
+ _type_assert_("maintainers", value, _collections_.Iterable)
result = []
for item in value:
_type_assert_("maintainer", item, str)
module = self.name
if len(module) != len(module.encode()):
module = (module + "\n").encode("UTF-8")
- module = hashlib.md5(module).hexdigest()
+ module = _hashlib_.md5(module).hexdigest()
return "%s_gnulib_enabled_%s" % (macro_prefix, module)
module = self.name
if len(module) != len(module.encode()):
module = (module + "\n").encode("UTF-8")
- module = hashlib.md5(module).hexdigest()
+ module = _hashlib_.md5(module).hexdigest()
return "func_%s_gnulib_m4code_%s" % (macro_prefix, module)
module = self.name
if len(module) != len(module.encode()):
module = (module + "\n").encode("UTF-8")
- module = hashlib.md5(module).hexdigest()
+ module = _hashlib_.md5(module).hexdigest()
return "%s_GNULIB_ENABLED_%s" % (macro_prefix, module)
"Maintainer" : (list, "maintainers"),
}
_FIELDS_ = [field for (_, _, field) in Base._TABLE_.values()]
- _PATTERN_ = re.compile("(%s):" % "|".join(_FIELDS_))
+ _PATTERN_ = _re_.compile("(%s):" % "|".join(_FIELDS_))
def __init__(self, path, mode="r", name=None, **kwargs):
if name is None:
- name = os.path.basename(path)
+ name = _os_.path.basename(path)
if mode not in ("r", "w", "rw"):
raise ValueError("illegal mode: %r" % mode)
if mode == "r":
table = {}
- with codecs.open(path, "rb", "UTF-8") as stream:
+ with _codecs_.open(path, "rb", "UTF-8") as stream:
data = ""
for line in stream:
line = line.strip("\n")
self.__stream = None
elif mode == "w":
super().__init__(name)
- self.__stream = codecs.open(path, "w+", "UTF-8")
+ self.__stream = _codecs_.open(path, "w+", "UTF-8")
elif mode == "rw":
self.__init__(path, "r")
- self.__stream = codecs.open(path, "w+", "UTF-8")
+ self.__stream = _codecs_.open(path, "w+", "UTF-8")
else:
raise ValueError("invalid mode: %r" % mode)