* gnulib-tool.py: Don't allow 'bytes' as an alternative to 'str'.
* pygnulib/*.py: Likewise.
2022-07-30 Bruno Haible <bruno@clisp.org>
+ gnulib-tool.py: Assume Python 3.
+ * gnulib-tool.py: Don't allow 'bytes' as an alternative to 'str'.
+ * pygnulib/*.py: Likewise.
+
gnulib-tool.py: Assume Python 3.
* gnulib-tool.py: Don't set PYTHON3, string. Use str instead of string.
* pygnulib/*.py: Likewise.
dest = files[1]
else: # if len(files) != 2
dest = '.'
- if type(srcpath) is bytes:
- srcpath = srcpath.decode(ENCS['default'])
- if type(dest) is bytes:
- dest = dest.decode(ENCS['default'])
if not auxdir:
auxdir = 'build-aux'
if not sourcebase:
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
def setDestDir(self, destdir):
'''Specify the target directory. For --import, this specifies where your
configure.ac can be found. Defaults to current directory.'''
- if type(destdir) is bytes or type(destdir) is str:
- if type(destdir) is bytes:
- destdir = str(destdir, ENCS['system'])
+ if type(destdir) is str:
if destdir:
self.table['destdir'] = os.path.normpath(destdir)
- else: # if destdir has not bytes/str type
+ else: # if destdir has not str type
raise TypeError('destdir must be a string, not %s' %
type(destdir).__name__)
def setLocalDir(self, localdir):
'''Specify a local override directory where to look up files before looking
in gnulib's directory.'''
- if type(localdir) is bytes or type(localdir) is str:
- if type(localdir) is bytes:
- localdir = str(localdir, ENCS['system'])
+ if type(localdir) is str:
if localdir:
self.table['localdir'] = localdir
- else: # if localdir has not bytes/str type
+ else: # if localdir has not str type
raise TypeError('localdir must be a string, not %s' %
type(localdir).__name__)
def setAuxDir(self, auxdir):
'''Specify directory relative to --dir where auxiliary build tools are
placed. Default comes from configure.ac or configure.in.'''
- if type(auxdir) is bytes or type(auxdir) is str:
- if type(auxdir) is bytes:
- auxdir = str(auxdir, ENCS['system'])
+ if type(auxdir) is str:
if auxdir:
self.table['auxdir'] = auxdir
- else: # if type of auxdir is not bytes or str
+ else: # if type of auxdir is not str
raise TypeError('auxdir must be a string, not %s' %
type(auxdir).__name__)
def setSourceBase(self, sourcebase):
'''Specify directory relative to destdir where source code is placed.'''
- if type(sourcebase) is bytes or type(sourcebase) is str:
- if type(sourcebase) is bytes:
- sourcebase = str(sourcebase, ENCS['system'])
+ if type(sourcebase) is str:
if sourcebase:
self.table['sourcebase'] = sourcebase
- else: # if type of sourcebase is not bytes or str
+ else: # if type of sourcebase is not str
raise TypeError('sourcebase must be a string, not %s' %
type(sourcebase).__name__)
def setM4Base(self, m4base):
'''Specify directory relative to destdir where *.m4 macros are placed.'''
- if type(m4base) is bytes or type(m4base) is str:
- if type(m4base) is bytes:
- m4base = str(m4base, ENCS['system'])
+ if type(m4base) is str:
if m4base:
self.table['m4base'] = m4base
- else: # if type of m4base is not bytes or str
+ else: # if type of m4base is not str
raise TypeError('m4base must be a string, not %s' %
type(m4base).__name__)
def setPoBase(self, pobase):
'''Specify directory relative to destdir where *.po files are placed.'''
- if type(pobase) is bytes or type(pobase) is str:
- if type(pobase) is bytes:
- pobase = str(pobase, ENCS['system'])
+ if type(pobase) is str:
if pobase:
self.table['pobase'] = pobase
- else: # if type of pobase is not bytes or str
+ else: # if type of pobase is not str
raise TypeError('pobase must be a string, not %s' %
type(pobase).__name__)
def setDocBase(self, docbase):
'''Specify directory relative to destdir where doc files are placed.
Default value for this variable is 'doc').'''
- if type(docbase) is bytes or type(docbase) is str:
- if type(docbase) is bytes:
- docbase = str(docbase, ENCS['system'])
+ if type(docbase) is str:
if docbase:
self.table['docbase'] = docbase
- else: # if type of docbase is not bytes or str
+ else: # if type of docbase is not str
raise TypeError('docbase must be a string, not %s' %
type(docbase).__name__)
def setTestsBase(self, testsbase):
'''Specify directory relative to destdir where unit tests are placed.
Default value for this variable is 'tests').'''
- if type(testsbase) is bytes or type(testsbase) is str:
- if type(testsbase) is bytes:
- testsbase = str(testsbase, ENCS['system'])
+ if type(testsbase) is str:
if testsbase:
self.table['testsbase'] = testsbase
- else: # if type of testsbase is not bytes or str
+ else: # if type of testsbase is not str
raise TypeError('testsbase must be a string, not %s' %
type(testsbase).__name__)
# Define modules methods.
def addModule(self, module):
'''Add the module to the modules list.'''
- if type(module) is bytes or type(module) is str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
+ if type(module) is str:
if module not in self.table['modules']:
self.table['modules'] += [module]
- else: # if module has not bytes or str type
+ else: # if module has not str type
raise TypeError('module must be a string, not %s' %
type(module).__name__)
def removeModule(self, module):
'''Remove the module from the modules list.'''
- if type(module) is bytes or type(module) is str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
+ if type(module) is str:
if module in self.table['modules']:
self.table['modules'].remove(module)
- else: # if module has not bytes or str type
+ else: # if module has not str type
raise TypeError('module must be a string, not %s' %
type(module).__name__)
def addAvoid(self, module):
'''Avoid including the given module. Useful if you have code that provides
equivalent functionality.'''
- if type(module) is bytes or type(module) is str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
+ if type(module) is str:
if module not in self.table['avoids']:
self.table['avoids'].append(module)
- else: # if module has not bytes or str type
+ else: # if module has not str type
raise TypeError('avoid must be a string, not %s' %
type(module).__name__)
def removeAvoid(self, module):
'''Remove the given module from the list of avoided modules.'''
- if type(module) is bytes or type(module) is str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
+ if type(module) is str:
if module in self.table['avoids']:
self.table['avoids'].remove(module)
- else: # if module has not bytes or str type
+ else: # if module has not str type
raise TypeError('avoid must be a string, not %s' %
type(module).__name__)
# Define files methods.
def addFile(self, file):
'''Add file to the list of files.'''
- if type(file) is bytes or type(file) is str:
- if type(file) is bytes:
- file = file.decode(ENCS['default'])
+ if type(file) is str:
if file not in self.table['files']:
self.table['files'].append(file)
- else: # if file has not bytes or str type
+ else: # if file has not str type
raise TypeError('file must be a string, not %s' %
type(file).__name__)
def removeFile(self, file):
'''Remove the given file from the list of files.'''
- if type(file) is bytes or type(file) is str:
- if type(file) is bytes:
- file = file.decode(ENCS['default'])
+ if type(file) is str:
if file in self.table['files']:
self.table['files'].remove(file)
- else: # if file has not bytes or str type
+ else: # if file has not str type
raise TypeError('file must be a string, not %s' %
type(file).__name__)
def setLibName(self, libname):
'''Specify the library name.'''
- if type(libname) is bytes or type(libname) is str:
- if type(libname) is bytes:
- libname = str(libname, ENCS['system'])
+ if type(libname) is str:
if libname:
self.table['libname'] = libname
- else: # if type of libname is not bytes or str
+ else: # if type of libname is not str
raise TypeError('libname must be a string, not %s' %
type(module).__name__)
def setMacroPrefix(self, macro_prefix):
'''Specify the prefix of the macros 'gl_EARLY' and 'gl_INIT'.
Default macro_prefix is 'gl'.'''
- if type(macro_prefix) is bytes or type(macro_prefix) is str:
- if type(macro_prefix) is bytes:
- macro_prefix = str(macro_prefix, ENCS['system'])
+ if type(macro_prefix) is str:
if macro_prefix:
self.table['macro_prefix'] = macro_prefix
- else: # if type of macro_prefix is not bytes or str
+ else: # if type of macro_prefix is not str
raise TypeError('macro_prefix must be a string, not %s' %
type(macro_prefix).__name__)
if macro_prefix == 'gl':
include_guard_prefix = 'GL'
else: # macro_prefix != 'gl'
include_guard_prefix = 'GL_%s' % macro_prefix.upper()
- if type(include_guard_prefix) is bytes:
- include_guard_prefix = include_guard_prefix.decode(ENCS['default'])
self.table['include_guard_prefix'] = include_guard_prefix
def resetMacroPrefix(self):
Default macro_prefix is 'gl'.'''
self.table['macro_prefix'] = 'gl'
include_guard_prefix = 'GL'
- if type(include_guard_prefix) is bytes:
- include_guard_prefix = include_guard_prefix.decode(ENCS['default'])
self.table['include_guard_prefix'] = include_guard_prefix
# Define makefile methods.
def setMakefile(self, makefile):
'''Specify the name of makefile in automake syntax in the source-base and
tests-base directories. Default is 'Makefile.am'.'''
- if type(makefile) is bytes or type(makefile) is str:
- if type(makefile) is bytes:
- makefile = str(makefile, ENCS['system'])
+ if type(makefile) is str:
if makefile:
self.table['makefile'] = makefile
- else: # if type of makefile is not bytes or str
+ else: # if type of makefile is not str
raise TypeError('makefile must be a string, not %s' %
type(makefile).__name__)
def setPoDomain(self, podomain):
'''Specify the prefix of the i18n domain. Usually use the package name.
A suffix '-gnulib' is appended.'''
- if type(podomain) is bytes or type(podomain) is str:
- if type(podomain) is bytes:
- podomain = str(podomain, ENCS['system'])
+ if type(podomain) is str:
if podomain:
self.table['podomain'] = podomain
- else: # if type of podomain is not bytes or str
+ else: # if type of podomain is not str
raise TypeError('podomain must be a string, not %s' %
type(podomain).__name__)
def setWitnessCMacro(self, witness_c_macro):
'''Specify the C macro that is defined when the sources in this directory
are compiled or used.'''
- if type(witness_c_macro) is bytes or type(witness_c_macro) is str:
- if type(witness_c_macro) is bytes:
- witness_c_macro = str(witness_c_macro, ENCS['system'])
+ if type(witness_c_macro) is str:
if witness_c_macro:
self.table['witness_c_macro'] = witness_c_macro
- else: # if type of witness_c_macro is not bytes or str
+ else: # if type of witness_c_macro is not str
raise TypeError('witness_c_macro must be a string, not %s' %
type(witness_c_macro).__name__)
def setAutoconfFile(self, configure_ac):
'''Specify path of autoconf file relative to destdir.'''
- if type(configure_ac) is bytes or type(configure_ac) is str:
- if type(configure_ac) is bytes:
- configure_ac = str(configure_ac, ENCS['system'])
+ if type(configure_ac) is str:
if configure_ac:
self.table['configure_ac'] = \
relpath(self.table['destdir'], configure_ac)
- else: # if type of configure_ac is not bytes or str
+ else: # if type of configure_ac is not str
raise TypeError('configure_ac must be a string, not %s' %
type(configure_ac).__name__)
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.\n"""
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def autoconfSnippet(self, module, fileassistant, toplevel,
if type(disable_gettext) is not bool:
raise TypeError('disable_gettext must be a bool, not %s' %
type(disable_gettext).__name__)
- if type(indentation) is bytes or type(indentation) is str:
- if type(indentation) is bytes:
- indentation = indentation.decode(ENCS['default'])
- else: # if indentation has not bytes or str type
+ if type(indentation) is not str:
raise TypeError('indentation must be a string, not %s' %
type(indentation).__name__)
if not indentation.isspace():
lines = [line for line in emit.split('\n') if line.strip()]
emit = '%s\n' % '\n'.join(lines)
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return emit
def autoconfSnippets(self, modules, moduletable, fileassistant,
lines = [line for line in emit.split('\n') if line.strip()]
emit = '%s\n' % '\n'.join(lines)
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return emit
def preEarlyMacros(self, require, indentation, modules):
# package uses functions taking also a message context, like pgettext(), or
# if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
USE_MSGCTXT = no\n"""
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def po_POTFILES_in(self, files):
emit = ''
sourcebase = self.config['sourcebase']
sourcebase = '%s%s' % (self.sourcebase, os.path.sep)
- if type(sourcebase) is bytes:
- sourcebase = sourcebase.decode(ENCS['default'])
files = [substart('lib/', sourcebase, file) for file in files]
files = [file for file in files if file.startswith(sourcebase)]
emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
emit += "# List of files which contain translatable strings.\n"
emit += '\n'.join(files)
emit += '\n'
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def initmacro_start(self, macro_prefix_arg):
Emit the first few statements of the gl_INIT macro.'''
emit = ''
- if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str:
- if type(macro_prefix_arg) is bytes:
- macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
- else: # if macro_prefix_arg has not bytes or str type
+ if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s' %
type(macro_prefix_arg).__name__)
module_indicator_prefix = self.config.getModuleIndicatorPrefix()
emit += " [" + module_indicator_prefix + "])"
emit += " gl_COMMON\n"
emit = emit.replace('%V1%', macro_prefix_arg)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def initmacro_end(self, macro_prefix_arg):
Emit the last few statements of the gl_INIT macro.'''
emit = ''
- if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str:
- if type(macro_prefix_arg) is bytes:
- macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
- else: # if macro_prefix_arg has not bytes or str type
+ if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s' %
type(macro_prefix_arg).__name__)
# Check the presence of files that are mentioned as AC_LIBSOURCES
AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
])\n"""
emit = emit.replace('%V1%', macro_prefix_arg)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def initmacro_done(self, macro_prefix_arg, sourcebase_arg):
Emit a few statements after the gl_INIT macro.
GLConfig: sourcebase.'''
emit = ''
- if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is str:
- if type(macro_prefix_arg) is bytes:
- macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
- else: # if macro_prefix_arg has not bytes or str type
+ if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s' %
type(macro_prefix_arg).__name__)
- if type(sourcebase_arg) is bytes or type(sourcebase_arg) is str:
- if type(sourcebase_arg) is bytes:
- sourcebase_arg = sourcebase_arg.decode(ENCS['default'])
- else: # if sourcebase_arg has not bytes or str type
+ if type(sourcebase_arg) is not str:
raise TypeError('sourcebase_arg must be a string, not %s' %
type(sourcebase_arg).__name__)
emit += """\
])\n"""
emit = emit.replace('%V1%', macro_prefix_arg)
emit = emit.replace('%V2%', sourcebase_arg)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def lib_Makefile_am(self, destfile, modules,
an empty string e.g. when user wants to generate files for GLTestDir.
for_test is a bool variable; it must be set to True if creating a package
for testing, False otherwise.'''
- if type(destfile) is bytes or type(destfile) is str:
- if type(destfile) is bytes:
- destfile = destfile.decode(ENCS['default'])
- else: # if destfile has not bytes or str type
+ if type(destfile) is not str:
raise TypeError('destfile must be a string, not %s' %
type(destfile).__name__)
for module in modules:
if type(makefiletable) is not GLMakefileTable:
raise TypeError('makefiletable must be a GLMakefileTable, not %s' %
type(makefiletable).__name__)
- if type(actioncmd) is bytes or type(actioncmd) is str:
- if type(actioncmd) is bytes:
- actioncmd = actioncmd.decode(ENCS['default'])
- else: # if actioncmd has not bytes or str type
+ if type(actioncmd) is not str:
raise TypeError('actioncmd must be a string, not %s' %
type(actioncmd).__name__)
if type(for_test) is not bool:
(libname, libext), amsnippet2)
amsnippet2 = amsnippet2.replace(
'$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_')
- if type(amsnippet1) is bytes:
- amsnippet1 = amsnippet1.decode(ENCS['default'])
- if type(amsnippet2) is bytes:
- amsnippet2 = amsnippet1.decode(ENCS['default'])
if not (amsnippet1 + amsnippet2).isspace():
allsnippets += '## begin gnulib module %s\n' % str(module)
if conddeps:
emit += '\tdone; \\\n'
emit += '\t:\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
result = tuple([emit, uses_subdirs])
return result
an empty string e.g. when user wants to generate files for GLTestDir.
for_test is a bool variable; it must be set to True if creating a package
for testing, False otherwise.'''
- if type(destfile) is bytes or type(destfile) is str:
- if type(destfile) is bytes:
- destfile = destfile.decode(ENCS['default'])
- else: # if destfile has not bytes or str type
+ if type(destfile) is not str:
raise TypeError('destfile must be a string, not %s' %
type(destfile).__name__)
for module in modules:
if type(makefiletable) is not GLMakefileTable:
raise TypeError('makefiletable must be a GLMakefileTable, not %s' %
type(makefiletable).__name__)
- if type(witness_macro) is bytes or type(witness_macro) is str:
- if type(witness_macro) is bytes:
- witness_macro = witness_macro.decode(ENCS['default'])
- else: # if witness_macro has not bytes or str type
+ if type(witness_macro) is not str:
raise TypeError('witness_macro must be a string, not %s' %
type(witness_macro).__name__)
if type(for_test) is not bool:
emit += '\tdone; \\\n'
emit += '\t:\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
result = tuple([emit, uses_subdirs])
return result
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
GLError telling that file was not found. Function also returns flag which
indicates whether file is a temporary file.
GLConfig: localdir.'''
- if type(name) is bytes or type(name) is str:
- if type(name) is bytes:
- name = name.decode(ENCS['default'])
- else: # if name has not bytes or str type
+ if type(name) is not str:
raise TypeError(
'name must be a string, not %s' % type(module).__name__)
# If name exists in localdir, then we use it
transformers[key] = 's,x,x,'
else: # if key in transformers
value = transformers[key]
- if type(value) is bytes or type(value) is str:
- if type(value) is bytes:
- transformers[key] = value.decode(ENCS['default'])
- else: # if value has not bytes or str type
+ if type(value) is not str:
raise TypeError('transformers[%s] must be a string, not %s' %
(key, type(value).__name__))
self.original = None
'''GLFileAssistant.tmpfilename() -> str
Return the name of a temporary file (file is relative to destdir).'''
- if type(path) is bytes or type(path) is str:
- if type(path) is bytes:
- path = path.decode(ENCS['default'])
- else: # if path has not bytes or str type
+ if type(path) is not str:
raise TypeError(
'path must be a string, not %s' % (type(path).__name__))
if not self.config['dryrun']:
dirname = os.path.dirname(result)
if not isdir(dirname):
os.makedirs(dirname)
- if type(result) is bytes:
- result = bytes.decode(ENCS['default'])
return result
def setOriginal(self, original):
'''GLFileAssistant.setOriginal(original)
Set the name of the original file which will be used.'''
- if type(original) is bytes or type(original) is str:
- if type(original) is bytes:
- original = original.decode(ENCS['default'])
- else: # if original has not bytes or str type
+ if type(original) is not str:
raise TypeError(
'original must be a string, not %s' % (type(original).__name__))
self.original = original
'''GLFileAssistant.setRewritten(rewritten)
Set the name of the rewritten file which will be used.'''
- if type(rewritten) is bytes or type(rewritten) is str:
- if type(rewritten) is bytes:
- rewritten = rewritten.decode(ENCS['default'])
- else: # if rewritten has not bytes or str type
+ if type(rewritten) is not str:
raise TypeError(
'rewritten must be a string, not %s' % type(rewritten).__name__)
self.rewritten = rewritten
raise TypeError('original must be set before applying the method')
elif rewritten == None:
raise TypeError('rewritten must be set before applying the method')
- if type(lookedup) is bytes or type(lookedup) is str:
- if type(lookedup) is bytes:
- lookedup = lookedup.decode(ENCS['default'])
- else: # if lookedup has not bytes or str type
+ if type(lookedup) is not str:
raise TypeError('lookedup must be a string, not %s' %
type(lookedup).__name__)
if type(already_present) is not bool:
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
if type(files) is not list:
raise TypeError(
'files argument must has list type, not %s' % type(files).__name__)
- files = \
- [ # Begin to convert bytes to string
- file.decode(ENCS['default']) \
- if type(file) is bytes else file \
- for file in files
- ] # Finish to convert bytes to string
for file in files:
if type(file) is not str:
raise TypeError('each file must be a string instance')
if type(files) is not list:
raise TypeError(
'files argument must has list type, not %s' % type(files).__name__)
- files = \
- [ # Begin to convert bytes to string
- file.decode(ENCS['default']) \
- if type(file) is bytes else file \
- for file in files
- ] # Finish to convert bytes to string
for file in files:
if type(file) is not str:
raise TypeError('each file must be a string instance')
emit += 'gl_WITNESS_C_MACRO([%s])\n' % witness_c_macro
if vc_files:
emit += 'gl_VC_FILES([%s])\n' % vc_files
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return constants.nlconvert(emit)
def gnulib_comp(self, files):
AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
emit += ' %s\n' % '\n '.join(files)
emit += '])\n'
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
return emit
def _done_dir_(self, directory, dirs_added, dirs_removed):
data = '# Set of available languages.\n'
files = [constants.subend('.po', '', file)
for file in os.listdir(joinpath(destdir, pobase))]
- files = [file.decode(ENCS['default']) if type(file) is bytes
- else file for file in files]
data += '\n'.join(files)
with codecs.open(tmpfile, 'wb', 'UTF-8') as file:
file.write(data)
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
This method is used to remember that ${dir}Makefile.am needs to be edited
to that ${var} mentions ${val}.'''
- if type(dir) is bytes or type(dir) is str:
- if type(dir) is bytes:
- dir = dir.decode(ENCS['default'])
- else: # if dir has not bytes or str type
+ if type(dir) is not str:
raise TypeError(
'dir must be a string, not %s' % (type(dir).__name__))
- if type(var) is bytes or type(var) is str:
- if type(var) is bytes:
- var = var.decode(ENCS['default'])
- else: # if var has not bytes or str type
+ if type(var) is not str:
raise TypeError(
'var must be a string, not %s' % (type(var).__name__))
- if type(val) is bytes or type(val) is str:
- if type(val) is bytes:
- val = val.decode(ENCS['default'])
- else: # if val has not bytes or str type
+ if type(val) is not str:
raise TypeError(
'val must be a string, not %s' % (type(val).__name__))
dictionary = {'dir': dir, 'var': var, 'val': val}
Check whether the given module exists.
GLConfig: localdir.'''
- if type(module) is bytes or str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
- else: # if module has not bytes or str type
+ if type(module) is not str:
raise TypeError(
'module must be a string, not %s' % type(module).__name__)
result = bool()
'''GLModuleSystem.find(module) -> GLModule
Find the given module.'''
- if type(module) is bytes or str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
- else: # if module has not bytes or str type
+ if type(module) is not str:
raise TypeError(
'module must be a string, not %s' % type(module).__name__)
if self.exists(module):
if type(config) is not GLConfig:
raise TypeError('config must be a GLConfig, not %s' %
type(config).__name__)
- if type(module) is bytes or type(module) is str:
- if type(module) is bytes:
- module = module.decode(ENCS['default'])
- else: # if module has not bytes or str type
+ if type(module) is not str:
raise TypeError('module must be a string, not %s' %
type(module).__name__)
if type(patched) is not bool:
module = module.encode(ENCS['default'])
module = hashlib.md5(module).hexdigest()
result = 'func_%s_gnulib_m4code_%s' % (macro_prefix, module)
- if type(result) is bytes:
- result = result.decode(ENCS['default'])
return result
def getShellVar(self):
module = module.encode(ENCS['default'])
module = hashlib.md5(module).hexdigest()
result = '%s_gnulib_enabled_%s' % (macro_prefix, module)
- if type(result) is bytes:
- result = result.decode(ENCS['default'])
return result
def getConditionalName(self):
conditional = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name)
else: # if not nonascii
result = '%s_GNULIB_ENABLED_%s' % (macro_prefix, name)
- if type(result) is bytes:
- result = result.decode(ENCS['default'])
return result
def getDescription(self):
result = 'tests'
else: # if not self.getName().endswith('-tests')
result = 'main'
- if type(result) is bytes:
- result = result.decode(ENCS['default'])
result = result.strip()
self.cache['applicability'] = result
return self.cache['applicability']
else: # if len(split) != 1
module = split[0]
condition = split[1]
- if type(condition) is bytes:
- condition = condition.decode(ENCS['default'])
result += [tuple([self.modulesystem.find(module), condition])]
self.cache['dependencies'] = result
return list(self.cache['dependencies'])
if type(module) is not GLModule:
raise TypeError('module must be a GLModule, not %s' %
type(module).__name__)
- if type(condition) is bytes or type(condition) is str \
- or condition == True:
- if type(condition) is bytes:
- condition = condition.decode(ENCS['default'])
- else: # if condition has not bytes or str type or is not True
+ if not (type(condition) is str or condition == True):
raise TypeError('condition must be a string or True, not %s' %
type(condition).__name__)
if not str(module) in self.unconditionals:
NoneType = type(None)
APP = constants.APP
DIRS = constants.DIRS
-ENCS = constants.ENCS
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
if type(config) is not GLConfig:
raise TypeError('config must be a GLConfig, not %s' %
type(config).__name__)
- if type(testdir) is bytes or type(testdir) is str:
- if type(testdir) is bytes:
- testdir = testdir.decode(ENCS['default'])
+ if type(testdir) is not str:
+ raise TypeError('testdir must be a string, not %s' %
+ type(testdir).__name__)
self.config = config
self.testdir = os.path.normpath(testdir)
if not os.path.exists(self.testdir):
if type(files) is not list:
raise TypeError(
'files argument must has list type, not %s' % type(files).__name__)
- files = \
- [ # Begin to convert bytes to string
- file.decode(ENCS['default']) \
- if type(file) is bytes else file \
- for file in files
- ] # Finish to convert bytes to string
for file in files:
if type(file) is not str:
raise TypeError('each file must be a string instance')
file = constants.substart('m4/', '', file)
emit += 'EXTRA_DIST += %s\n' % file
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
with codecs.open(destfile, 'wb', 'UTF-8') as file:
file.write(emit)
emit += 'AC_CONFIG_FILES([Makefile])\n'
emit += 'AC_OUTPUT\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
path = joinpath(self.testdir, testsbase, 'configure.ac')
with codecs.open(path, 'wb', 'UTF-8') as file:
file.write(emit)
emit += 'SUBDIRS = %s\n\n' % ' '.join(subdirs)
emit += 'ACLOCAL_AMFLAGS = -I %s\n' % m4base
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
path = joinpath(self.testdir, 'Makefile.am')
with codecs.open(path, 'wb', 'UTF-8') as file:
file.write(emit)
if type(config) is not GLConfig:
raise TypeError('config must be a GLConfig, not %s' %
type(config).__name__)
- if type(megatestdir) is bytes or type(megatestdir) is str:
- if type(megatestdir) is bytes:
- megatestdir = megatestdir.decode(ENCS['default'])
+ if type(megatestdir) is not str:
+ raise TypeError('megatestdir must be a string, not %s' %
+ type(megatestdir).__name__)
self.config = config
self.megatestdir = os.path.normpath(megatestdir)
if not os.path.exists(self.megatestdir):
emit += 'sed -e "$AUTOBUILD_SUBST"; else cat; fi; } > logs/$safemodule\n'
emit += 'done\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
path = joinpath(self.megatestdir, 'do-autobuild')
with codecs.open(path, 'wb', 'UTF-8') as file:
file.write(emit)
emit += 'SUBDIRS = %s\n\n' % ' '.join(megasubdirs)
emit += 'EXTRA_DIST = do-autobuild\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
path = joinpath(self.megatestdir, 'Makefile.am')
with codecs.open(path, 'wb', 'UTF-8') as file:
file.write(emit)
emit += 'AC_CONFIG_FILES([Makefile])\n'
emit += 'AC_OUTPUT\n'
emit = constants.nlconvert(emit)
- if type(emit) is bytes:
- emit = emit.decode(ENCS['default'])
path = joinpath(self.megatestdir, 'Makefile.am')
with codecs.open(path, 'wb', 'UTF-8') as file:
file.write(emit)
if not APP['name']:
APP['name'] = 'gnulib-tool.py'
APP['path'] = os.path.realpath(sys.argv[0])
-if type(APP['name']) is bytes:
- APP['name'] = str(APP['name'], ENCS['system'])
-if type(APP['path']) is bytes:
- APP['path'] = str(APP['path'], ENCS['system'])
# Set DIRS dictionary
DIRS['root'] = os.path.dirname(APP['path'])
# Commands like automake produce output to stderr even when they succeed.
# Turn this output off if the command succeeds.
temp = tempfile.mktemp()
- if type(temp) is bytes:
- temp = temp.decode(ENCS['system'])
xargs = '%s > %s 2>&1' % (' '.join(args), temp)
try: # Try to run
retcode = sp.call(xargs, shell=True)
component is an absolute path, all previous path components will be
discarded. The second argument may be string or list of strings.'''
newtail = list()
- if type(head) is bytes:
- head = head.decode(ENCS['default'])
for item in tail:
- if type(item) is bytes:
- item = item.decode(ENCS['default'])
newtail += [item]
result = os.path.normpath(os.path.join(head, *tail))
- if type(result) is bytes:
- result = result.decode(ENCS['default'])
return result
def relativize(dir1, dir2):
'''Compute a relative pathname reldir such that dir1/reldir = dir2.'''
dir0 = os.getcwd()
- if type(dir1) is bytes:
- dir1 = dir1.decode(ENCS['default'])
- if type(dir2) is bytes:
- dir2 = dir2.decode(ENCS['default'])
while dir1:
dir1 = '%s%s' % (os.path.normpath(dir1), os.path.sep)
dir2 = '%s%s' % (os.path.normpath(dir2), os.path.sep)
def link_relative(src, dest):
'''Like ln -s, except that src is given relative to the current directory
(or absolute), not given relative to the directory of dest.'''
- if type(src) is bytes or type(src) is str:
- if type(src) is bytes:
- src = src.decode(ENCS['default'])
- else: # if src has not bytes or str type
+ if type(src) is not str:
raise TypeError(
'src must be a string, not %s' % (type(src).__name__))
- if type(dest) is bytes or type(dest) is str:
- if type(dest) is bytes:
- dest = dest.decode(ENCS['default'])
- else: # if dest has not bytes or str type
+ if type(dest) is not str:
raise TypeError(
'dest must be a string, not %s' % (type(dest).__name__))
if src.startswith('/') or (len(src) >= 2 and src[1] == ':'):
destdir = os.path.dirname(dest)
if not destdir:
destdir = '.'
- if type(destdir) is bytes:
- destdir = destdir.decode(ENCS['default'])
src = relativize(destdir, src)
os.symlink(src, dest)
def link_if_changed(src, dest):
'''Create a symlink, but avoids munging timestamps if the link is correct.'''
- if type(src) is bytes:
- src = src.decode(ENCS['default'])
- if type(dest) is bytes:
- dest = dest.decode(ENCS['default'])
ln_target = os.path.realpath(src)
if not (os.path.islink(dest) and src == ln_target):
os.remove(dest)