* gnulib-tool.py: Use 'from A import B' syntax when possible. Remove useless imports. * pygnulib/GLConfig.py: Likewise. * pygnulib/GLEmiter.py: Likewise * pygnulib/GLError.py: Likewise. * pygnulib/GLFileSystem.py: Likewise. * pygnulib/GLImport.py: Likewise. * pygnulib/GLInfo.py: Likewise. * pygnulib/GLMakefileTable.py: Likewise. * pygnulib/GLModuleSystem.py: Likewise. * pygnulib/GLTestDir.py: Likewise. --- gnulib-tool.py | 72 +++++++++---------------------- pygnulib/GLConfig.py | 51 +++------------------- pygnulib/GLEmiter.py | 42 +----------------- pygnulib/GLError.py | 46 ++------------------ pygnulib/GLFileSystem.py | 73 ++++++++----------------------- pygnulib/GLImport.py | 102 +++++++++++++------------------------------- pygnulib/GLInfo.py | 58 ++++++------------------- pygnulib/GLMakefileTable.py | 62 ++++----------------------- pygnulib/GLModuleSystem.py | 82 ++++++++++------------------------- pygnulib/GLTestDir.py | 93 +++++++++++----------------------------- 10 files changed, 148 insertions(+), 533 deletions(-)
diff --git a/gnulib-tool.py b/gnulib-tool.py index 704a015..aedb4fb 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -19,47 +19,17 @@ # This program is meant for authors or maintainers which want to import # modules from gnulib into their packages. - -#=============================================================================== -# Define global imports -#=============================================================================== -import os -import re -import sys +import argparse import codecs import random import shutil -import argparse import subprocess as sp -from pprint import pprint -from pygnulib import constants +import sys +from os import path from pygnulib import classes +from pygnulib import constants +from pygnulib.constants import (ENCS, UTILS, MODES, TESTS, joinpath) - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath - - -#=============================================================================== -# Define main part -#=============================================================================== def main(): # Reset arguments mode = None @@ -582,7 +552,7 @@ def main(): else: # if mode != MODE['--import'] if m4base: - if not isfile(joinpath(destdir, m4base, 'gnulib-cache.m4')): + if not path.isfile(joinpath(destdir, m4base, 'gnulib-cache.m4')): if not sourcebase: sourcebase = 'lib' if not docbase: @@ -604,7 +574,7 @@ def main(): m4dirs = list() dirisnext = bool() filepath = joinpath(destdir, 'Makefile.am') - if isfile(filepath): + if path.isfile(filepath): with codecs.open(filepath, 'rb', 'UTF-8') as file: data = file.read() data = data.split('ACLOCAL_AMFLAGS')[1] @@ -612,16 +582,16 @@ def main(): aclocal_amflags = data.split() for aclocal_amflag in aclocal_amflags: if dirisnext: - if not isabs(aclocal_amflag): + if not path.isabs(aclocal_amflag): m4dirs += [aclocal_amflag] else: # if not dirisnext if aclocal_amflag == '-I': dirisnext = True else: # if aclocal_amflag != '-I' dirisnext = False - else: # if not isfile(filepath) + else: # if not path.isfile(filepath) filepath = joinpath(destdir, 'aclocal.m4') - if isfile(filepath): + if path.isfile(filepath): pattern = constants.compiler( r'm4_include\(\[(.*?)\]\)') with codecs.open(filepath, 'rb', 'UTF-8') as file: @@ -630,7 +600,7 @@ def main(): m4dirs = \ [ # Begin filtering m4dir for m4dir in m4dirs \ - if isfile(joinpath(destdir, m4dir, 'gnulib-cache.m4')) + if path.isfile(joinpath(destdir, m4dir, 'gnulib-cache.m4')) ] # Finish filtering m4dirs = sorted(set(m4dirs)) if len(m4dirs) == 0: @@ -793,7 +763,7 @@ def main(): print('\n'.join(files)) elif mode == 'extract-dependencies': - result = string() + result = constants.string() if avoids: message = '%s: *** ' % constants.APP['name'] message += 'cannot combine --avoid and --extract-dependencies\n' @@ -882,8 +852,8 @@ def main(): config.setTestsBase(testsbase) filesystem = classes.GLFileSystem(config) lookedup, flag = filesystem.lookup(srcpath) - if isdir(dest): - destdir = string(dest) + if path.isdir(dest): + destdir = constants.string(dest) if srcpath.startswith('build-aux/'): destpath = constants.substart( 'build-aux/', '%s/' % auxdir, srcpath) @@ -904,13 +874,13 @@ def main(): destpath = constants.substart('top/', '', srcpath) else: # either case destpath = srcpath - else: # if not isdir(destpath) + else: # if not path.isdir(destpath) destdir = os.path.dirname(destpath) destpath = os.path.basename(destpath) # Create the directory for destfile. dirname = os.path.dirname(joinpath(destdir, destpath)) if not config['dryrun']: - if dirname and not isdir(dirname): + if dirname and not path.isdir(dirname): try: # Try to create directories os.makedirs(dirname) except Exception as error: @@ -922,16 +892,16 @@ def main(): already_present = True assistant.setOriginal(srcpath) assistant.setRewritten(destpath) - if isfile(joinpath(destdir, destpath)): + if path.isfile(joinpath(destdir, destpath)): # The file already exists. assistant.update(lookedup, flag, tmpfile, already_present) - else: # if not isfile(joinpath(destdir, destpath)) + else: # if not path.isfile(joinpath(destdir, destpath)) # Install the file. # Don't protest if the file should be there but isn't: it happens # frequently that developers don't put autogenerated files under version # control. assistant.add(lookedup, flag, tmpfile) - if isfile(tmpfile): + if path.isfile(tmpfile): os.remove(tmpfile) else: @@ -952,7 +922,7 @@ if __name__ == '__main__': if errmode == 0: message = '%s: *** ' % constants.APP['name'] if errinfo == None: - errinfo = string() + errinfo = constants.string() if errno == 1: message += 'file %s not found' % errinfo elif errno == 2: @@ -982,7 +952,7 @@ if __name__ == '__main__': message = 'gnulib-tool: option --conditional-dependencies is not ' message += 'supported with --with-tests\n' elif errno == 11: - incompatibilities = string() + incompatibilities = constants.string() message += 'incompatible license on modules:%s' % constants.NL for pair in errinfo: incompatibilities += pair[0] diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 1e1a090..4c2277c 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -1,53 +1,12 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== -import os -import re -import sys import copy -import codecs +import os import tempfile -import subprocess as sp -from . import constants +from .constants import (ENCS, MODES, TESTS, joinpath, string, relativize) from .GLError import GLError - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -relpath = constants.relativize -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath - - -#=============================================================================== -# Define GLConfig class -#=============================================================================== class GLConfig(object): '''This class is used to store intermediate settings for all pygnulib classes. It contains all necessary attributes to setup any other class. @@ -974,7 +933,7 @@ class GLConfig(object): configure_ac = string(configure_ac, ENCS['system']) if configure_ac: self.table['configure_ac'] = \ - relpath(self.table['destdir'], configure_ac) + relativize(self.table['destdir'], configure_ac) else: # if type of configure_ac is not bytes or string raise(TypeError('configure_ac must be a string, not %s' % type(configure_ac).__name__)) @@ -982,9 +941,9 @@ class GLConfig(object): def resetAutoconfFile(self): '''Reset path of autoconf file relative to destdir.''' configure_ac = string() - if isfile(joinpath(self.table['destdir'], 'configure.ac')): + if os.path.isfile(joinpath(self.table['destdir'], 'configure.ac')): configure_ac = joinpath(self.table['destdir'], 'configure.ac') - elif isfile(joinpath(self.table['destdir'], 'configure.in')): + elif os.path.isfile(joinpath(self.table['destdir'], 'configure.in')): configure_ac = joinpath(self.table['destdir'], 'configure.in') self.table['configure_ac'] = configure_ac diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index a350ba7..9ca83fa 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -1,14 +1,9 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os import re -import sys import codecs -import shutil import subprocess as sp from . import constants from .GLInfo import GLInfo @@ -19,41 +14,8 @@ from .GLModuleSystem import GLModuleTable from .GLMakefileTable import GLMakefileTable from .GLFileSystem import GLFileAssistant from pprint import pprint +from .constants import (ENCS, compiler, joinpath, string) - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath - - -#=============================================================================== -# Define GLEmiter class -#=============================================================================== class GLEmiter(object): '''This class is used to emit the contents of necessary files.''' @@ -830,7 +792,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ insnippets = bool(pattern.findall(allsnippets)) # Then test if $sourcebase/Makefile.am (if it exists) specifies it. path = joinpath(sourcebase, 'Makefile.am') - if makefile and isfile(path): + if makefile and os.path.isfile(path): with codecs.open(path, 'rb', 'UTF-8') as file: data = file.read() inmakefile = bool(pattern.findall(data)) diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py index 9c249a3..258eedc 100644 --- a/pygnulib/GLError.py +++ b/pygnulib/GLError.py @@ -1,50 +1,9 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os -import re -import sys -import locale -import codecs -from . import constants +from .constants import (ENCS, PYTHON3) - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath - - -#=============================================================================== -# Define GLError class -#=============================================================================== class GLError(Exception): '''Exception handler for pygnulib classes.''' @@ -107,8 +66,9 @@ class GLError(Exception): "error when running subprocess: %s" % repr(errinfo), ] # Complete list of errors if not PYTHON3: + dflt = ENCS['default'] self.message = (b'[Errno %d] %s' % - (self.errno, errors[self.errno - 1].encode(ENCS['default']))) + (self.errno, errors[self.errno - 1].encode(dflt))) else: # if PYTHON3 self.message = ('[Errno %d] %s' % (self.errno, errors[self.errno - 1])) diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index d5e253f..9edc398 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -1,54 +1,15 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os -import re -import sys -import codecs import shutil import filecmp import subprocess as sp from . import constants +from .constants import (ENCS, string, joinpath) from .GLError import GLError from .GLConfig import GLConfig - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath - - -#=============================================================================== -# Define GLFileSystem class -#=============================================================================== class GLFileSystem(object): '''GLFileSystem class is used to create virtual filesystem, which is based on the gnulib directory and directory specified by localdir argument. Its main @@ -83,7 +44,7 @@ class GLFileSystem(object): raise(TypeError( 'name must be a string, not %s' % type(module).__name__)) # If name exists in localdir, then we use it - path_gnulib = joinpath(DIRS['root'], name) + path_gnulib = joinpath(constants.DIRS['root'], name) path_local = joinpath(self.config['localdir'], name) path_diff = joinpath(self.config['localdir'], '%s.diff' % name) path_temp = joinpath(self.config['tempdir'], name) @@ -91,13 +52,13 @@ class GLFileSystem(object): os.makedirs(os.path.dirname(path_temp)) except OSError as error: pass # Skip errors if directory exists - if isfile(path_temp): + if os.path.isfile(path_temp): os.remove(path_temp) - if self.config['localdir'] and isfile(path_local): + if self.config['localdir'] and os.path.isfile(path_local): result = (path_local, False) else: # if path_local does not exist - if isfile(path_gnulib): - if self.config['localdir'] and isfile(path_diff): + if os.path.isfile(path_gnulib): + if self.config['localdir'] and os.path.isfile(path_diff): shutil.copy(path_gnulib, path_temp) command = 'patch -s "%s" < "%s" >&2' % (path_temp, path_diff) try: # Try to apply patch @@ -165,7 +126,7 @@ class GLFileAssistant(object): # to guarantee that an 'mv' to "$destdir/$file" works). result = joinpath(self.config['destdir'], '%s.tmp' % path) dirname = os.path.dirname(result) - if dirname and not isdir(dirname): + if dirname and not os.path.isdir(dirname): os.makedirs(dirname) else: # if self.config['dryrun'] # Put the new contents of $file in a file in a temporary directory @@ -173,7 +134,7 @@ class GLFileAssistant(object): tempdir = self.config['tempdir'] result = joinpath(tempdir, '%s.tmp' % os.path.basename(path)) dirname = os.path.dirname(result) - if not isdir(dirname): + if not os.path.isdir(dirname): os.makedirs(dirname) if type(result) is bytes: result = bytes.decode(ENCS['default']) @@ -276,7 +237,7 @@ class GLFileAssistant(object): raise(TypeError('already_present must be a bool, not %s' % type(already_present).__name__)) basename = rewritten - backupname = string('%s~' % basename) + backupname = constants.string('%s~' % basename) basepath = joinpath(destdir, basename) backuppath = joinpath(destdir, backupname) if not filecmp.cmp(basepath, tmpfile): @@ -289,7 +250,7 @@ class GLFileAssistant(object): message += '%s (non-gnulib code backed up in ' % basename message += '%s) !!' % backupname print(message) - if isfile(backuppath): + if os.path.isfile(backuppath): os.remove(backuppath) try: # Try to replace the given file shutil.move(basepath, backuppath) @@ -343,7 +304,7 @@ class GLFileAssistant(object): raise(GLError(15, lookedup)) # Don't process binary files with sed. if not (original.endswith(".class") or original.endswith(".mo")): - transformer = string() + transformer = constants.string() if original.startswith('lib/'): if sed_transform_main_lib_file: transformer = sed_transform_main_lib_file @@ -364,10 +325,10 @@ class GLFileAssistant(object): with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(data) path = joinpath(self.config['destdir'], rewritten) - if isfile(path): + if os.path.isfile(path): self.update(lookedup, tmpflag, tmpfile, already_present) os.remove(tmpfile) - else: # if not isfile(path) + else: # if not os.path.isfile(path) self.add(lookedup, tmpflag, tmpfile) self.addFile(rewritten) @@ -382,22 +343,22 @@ class GLFileAssistant(object): backupname = '%s~' % basename basepath = joinpath(self.config['destdir'], basename) backuppath = joinpath(self.config['destdir'], backupname) - if isfile(basepath): + if os.path.isfile(basepath): if filecmp.cmp(basepath, tmpfile): result_flag = 0 else: # if not filecmp.cmp(basepath, tmpfile) result_flag = 1 if not self.config['dryrun']: - if isfile(backuppath): + if os.path.isfile(backuppath): os.remove(backuppath) shutil.move(basepath, backuppath) shutil.move(tmpfile, basepath) else: # if self.config['dryrun'] os.remove(tmpfile) - else: # if not isfile(basepath) + else: # if not os.path.isfile(basepath) result_flag = 2 if not self.config['dryrun']: - if isfile(basepath): + if os.path.isfile(basepath): os.remove(basepath) shutil.move(tmpfile, basepath) else: # if self.config['dryrun'] diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index b5307e4..1ad0116 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -1,62 +1,20 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os import re -import sys -import locale import codecs import shutil -import filecmp import subprocess as sp from . import constants +from .constants import (ENCS, MODES, TESTS, compiler, joinpath, cleaner, string) from .GLError import GLError from .GLConfig import GLConfig -from .GLModuleSystem import GLModule -from .GLModuleSystem import GLModuleTable -from .GLModuleSystem import GLModuleSystem -from .GLFileSystem import GLFileSystem -from .GLFileSystem import GLFileAssistant +from .GLModuleSystem import (GLModuleTable, GLModuleSystem) +from .GLFileSystem import (GLFileSystem, GLFileAssistant) from .GLMakefileTable import GLMakefileTable from .GLEmiter import GLEmiter - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -relpath = constants.relativize -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath - - -#=============================================================================== -# Define GLImport class -#=============================================================================== class GLImport(object): '''GLImport class is used to provide methods for --import, --add-import, --remove-import and --update actions. This is a high-level class, so @@ -87,9 +45,9 @@ class GLImport(object): # Get cached auxdir and libtool from configure.ac/in. self.cache.setAuxDir('.') path = joinpath(self.config['destdir'], 'configure.ac') - if not isfile(path): + if not os.path.isfile(path): path = joinpath(self.config['destdir'], 'configure.in') - if not isfile(path): + if not os.path.isfile(path): raise(GLError(3, path)) self.config.setAutoconfFile(path) with codecs.open(path, 'rb', 'UTF-8') as file: @@ -115,7 +73,7 @@ class GLImport(object): # Get other cached variables. path = joinpath(self.config['m4base'], 'gnulib-cache.m4') - if isfile(joinpath(self.config['m4base'], 'gnulib-cache.m4')): + if os.path.isfile(joinpath(self.config['m4base'], 'gnulib-cache.m4')): with codecs.open(path, 'rb', 'UTF-8') as file: data = file.read() @@ -204,7 +162,7 @@ class GLImport(object): # Get cached filelist from gnulib-comp.m4. destdir, m4base = self.config.getDestDir(), self.config.getM4Base() path = joinpath(destdir, m4base, 'gnulib-comp.m4') - if isfile(path): + if os.path.isfile(path): with codecs.open(path, 'rb', 'UTF-8') as file: data = file.read() regex = 'AC_DEFUN\\(\\[%s_FILE_LIST\\], \\[(.*?)\\]\\)' % \ @@ -217,14 +175,14 @@ class GLImport(object): # to . or absolute. if not self.config['localdir']: if self.cache['localdir']: - if isabs(self.config['destdir']): + if os.path.isabs(self.config['destdir']): localdir = joinpath( self.config['destdir'], self.cache['localdir']) - else: # if not isabs(self.config['destdir']) - if isabs(self.cache['localdir']): + else: # if not os.path.isabs(self.config['destdir']) + if os.path.isabs(self.cache['localdir']): localdir = joinpath( self.config['destdir'], self.cache['localdir']) - else: # if not isabs(self.cache['localdir']) + else: # if not os.path.isabs(self.cache['localdir']) # NOTE: I NEED TO IMPLEMENT RELATIVE_CONCAT localdir = os.path.relpath(joinpath(self.config['destdir'], self.cache['localdir'])) @@ -688,13 +646,13 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix This method is used to determine ignore argument for _update_ignorelist_ method and then call it.''' destdir = self.config['destdir'] - if isdir(joinpath(destdir, 'CVS')) or \ - isdir(joinpath(destdir, directory, 'CVS')) or \ - isfile(joinpath(destdir, directory, '.cvsignore')): + if os.path.isdir(joinpath(destdir, 'CVS')) or \ + os.path.isdir(joinpath(destdir, directory, 'CVS')) or \ + os.path.isfile(joinpath(destdir, directory, '.cvsignore')): self._update_ignorelist_(directory, '.cvsignore', dirs_added, dirs_removed) - if isdir(joinpath(destdir, '.git')) or \ - isfile(joinpath(destdir, directory, '.gitignore')): + if os.path.isdir(joinpath(destdir, '.git')) or \ + os.path.isfile(joinpath(destdir, directory, '.gitignore')): self._update_ignorelist_(directory, '.gitignore', dirs_added, dirs_removed) @@ -710,7 +668,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix anchor = '' srcpath = joinpath(destdir, directory, ignore) backupname = '%s~' % srcpath - if isfile(srcpath): + if os.path.isfile(srcpath): if dirs_added or dirs_removed: with codecs.open(srcpath, 'rb', 'UTF-8') as file: srcdata = file.read() @@ -733,7 +691,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun'] print('Updating %s (backup in %s)' % (srcpath, backupname)) - else: # if not isfile(srcpath) + else: # if not os.path.isfile(srcpath) if dirs_added: if not self.config['dryrun']: print('Creating %s' % srcpath) @@ -928,7 +886,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix new_files = filelist + ['m4/gnulib-tool.m4'] old_files = list(self.cache['files']) path = joinpath(destdir, m4base, 'gnulib-tool.m4') - if isfile(path): + if os.path.isfile(path): old_files += [joinpath('m4', 'gnulib-tool.m4')] # Construct tables and transformers. @@ -1008,7 +966,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix dirs += [os.path.dirname(pair[0]) for pair in filetable['new']] dirs = sorted(set([joinpath(destdir, d) for d in dirs])) for directory in dirs: - if not isdir(directory): + if not os.path.isdir(directory): print('Creating directory %s' % directory) if not self.config['dryrun']: try: # Try to create directory @@ -1028,7 +986,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix files = sorted(set(pair[0] for pair in pairs)) for file in files: path = joinpath(destdir, file) - if isfile(path) or os.path.islink(path): + if os.path.isfile(path) or os.path.islink(path): if not self.config['dryrun']: backup = string('%s~' % path) print('Removing file %s (backup in )' % (path, backup)) @@ -1124,7 +1082,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun']: print('Create %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Create po/ directory. @@ -1151,7 +1109,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun']: print('Create %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Create po makefile parameterization, part 1. @@ -1173,7 +1131,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun']: print('Create %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Create po makefile parameterization, part 2. @@ -1195,7 +1153,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun']: print('Create %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Fetch PO files. @@ -1235,11 +1193,11 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix elif flag == 2: print('Creating %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) else: # if not self.config['dryrun'] backupname = '%s~' % basename - if isfile(destdir, basename): + if os.path.isfile(destdir, basename): print('Update %s (backup in %s)' % (basename, backupname)) else: # if not isfile(destdir, basename) print('Create %s' % basename) @@ -1266,7 +1224,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix elif emit[-1:] == '\n': emit = emit[:-1] print(emit) - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Create m4/gnulib-comp.m4. @@ -1291,7 +1249,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix elif emit[-1:] == '\n': emit = emit[:-1] print(emit) - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Create tests Makefile. @@ -1317,7 +1275,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix else: # if self.config['dryrun']: print('Create %s' % filename) filetable['added'] += [filename] - if isfile(tmpfile): + if os.path.isfile(tmpfile): os.remove(tmpfile) # Update the .cvsignore and .gitignore files. diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 7347745..7f521a8 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -1,9 +1,6 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os import re import sys @@ -11,41 +8,8 @@ import locale import codecs import subprocess as sp from . import constants +from .constants import (DIRS, ENCS, UTILS, MODES, TESTS, string) - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath - - -#=============================================================================== -# Define GLInfo class -#=============================================================================== class GLInfo(object): '''This class is used to get fromatted information about gnulib-tool. This information is mainly used in stdout messages, but can be used @@ -66,10 +30,11 @@ class GLInfo(object): '''Return formatted string which contains authors. The special __author__ variable is used (type is list).''' result = string() - for item in __author__: - if item == __author__[-2]: + authors = constants.__author__ + for item in authors: + if item == author[-2]: result += '%s ' % item - elif item == __author__[-1]: + elif item == author[-1]: result += 'and %s' % item else: result += '%s, ' % item @@ -87,14 +52,14 @@ class GLInfo(object): def copyright(self): '''Return formatted string which contains copyright. The special __copyright__ variable is used (type is str).''' - result = 'Copyright (C) %s' % __copyright__ + result = 'Copyright (C) %s' % constants.__copyright__ return(result) def date(self): '''Return formatted string which contains date and time in GMT format.''' - if isdir(DIRS['git']): + if os.path.isdir(constants.DIRS['git']): counter = int() # Create counter - result = string() # Create string + result = string() args = ['git', 'log'] result = sp.check_output(args).decode("UTF-8") # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string @@ -292,9 +257,10 @@ Report bugs to <bug-gnulib@gnu.org>.''' def version(self): '''Return formatted string which contains git version.''' - if isdir(DIRS['git']): - version_gen = joinpath(DIRS['build-aux'], 'git-version-gen') - args = [version_gen, DIRS['root']] + if os.path.isdir(constants.DIRS['git']): + version_gen = constants.joinpath(constants.DIRS['build-aux'], + 'git-version-gen') + args = [version_gen, constants.DIRS['root']] result = sp.check_output(args).decode("UTF-8") result = result.strip() if result == 'UNKNOWN': diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index 74e6fe7..eb0bc50 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -1,55 +1,10 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os -import re -import sys -import codecs -import hashlib -import subprocess as sp from . import constants -from .GLError import GLError from .GLConfig import GLConfig -from .GLFileSystem import GLFileSystem - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath -filter_filelist = constants.filter_filelist - - -#=============================================================================== -# Define GLMakefileTable class -#=============================================================================== class GLMakefileTable(object): '''This class is used to edit Makefile and store edits as table. When user creates Makefile, he may need to use this class.''' @@ -79,19 +34,19 @@ class GLMakefileTable(object): to that ${var} mentions ${val}.''' if type(dir) is bytes or type(dir) is string: if type(dir) is bytes: - dir = dir.decode(ENCS['default']) + dir = dir.decode(constants.ENCS['default']) else: # if dir has not bytes or string type raise(TypeError( 'dir must be a string, not %s' % (type(dir).__name__))) if type(var) is bytes or type(var) is string: if type(var) is bytes: - var = var.decode(ENCS['default']) + var = var.decode(constants.ENCS['default']) else: # if var has not bytes or string type raise(TypeError( 'var must be a string, not %s' % (type(var).__name__))) if type(val) is bytes or type(val) is string: if type(val) is bytes: - val = val.decode(ENCS['default']) + val = val.decode(constants.ENCS['default']) else: # if val has not bytes or string type raise(TypeError( 'val must be a string, not %s' % (type(val).__name__))) @@ -108,14 +63,15 @@ class GLMakefileTable(object): sourcebase = self.config['sourcebase'] testsbase = self.config['testsbase'] makefile = self.config['makefile'] - inctests = self.config.checkTestFlag(TESTS['tests']) - dir1 = string('%s%s' % (m4base, os.path.sep)) - mfd = string('Makefile.am') + inctests = self.config.checkTestFlag(constants.TESTS['tests']) + dir1 = constants.string('%s%s' % (m4base, os.path.sep)) + mfd = constants.string('Makefile.am') if not makefile: - mfx = string('Makefile.am') + mfx = constants.string('Makefile.am') else: # if makefile mfx = makefile - dir2 = string() + dir2 = constants.string() + joinpath = constants.joinpath while dir1 and \ (joinpath(self.config['destdir'], dir1, mfd) or joinpath(dir1, mfd) == joinpath(sourcebase, mfx) or diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 59109cc..079349e 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -1,55 +1,19 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== import os import re import sys import codecs import hashlib import subprocess as sp +from os.path import (isdir, isfile) from . import constants +from .constants import (ENCS, TESTS, filter_filelist, joinpath, string) from .GLError import GLError from .GLConfig import GLConfig from .GLFileSystem import GLFileSystem - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath -relpath = os.path.relpath -filter_filelist = constants.filter_filelist - - -#=============================================================================== -# Define GLModuleSystem class -#=============================================================================== class GLModuleSystem(object): '''GLModuleSystem is used to operate with module system using dynamic searching and patching.''' @@ -86,7 +50,7 @@ class GLModuleSystem(object): result = bool() badnames = ['ChangeLog', 'COPYING', 'README', 'TEMPLATE', 'TEMPLATE-EXTENDED', 'TEMPLATE-TESTS'] - if isfile(joinpath(DIRS['modules'], module)) or \ + if isfile(joinpath(constants.DIRS['modules'], module)) or \ all([ # Begin all(iterable) function self.config['localdir'], isdir(joinpath(self.config['localdir'], 'modules')), @@ -159,7 +123,7 @@ class GLModuleSystem(object): sed_args += ['-e', r's,\.diff$,,'] # Save the list of the modules to file. - os.chdir(DIRS['cwd']) + os.chdir(constants.DIRS['cwd']) path = joinpath(self.config['tempdir'], 'list') with codecs.open(path, 'wb', 'UTF-8') as file: file.write(result) @@ -285,7 +249,7 @@ Include:|Link:|License:|Maintainer:)' '''GLModule.getName() -> string Return the name of the module.''' - pattern = compiler(joinpath('modules', '(.*?)$')) + pattern = constants.compiler(joinpath('modules', '(.*?)$')) result = pattern.findall(self.module)[0] return(result) @@ -398,7 +362,7 @@ Include:|Link:|License:|Maintainer:)' result = string() else: # if section in self.content pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex) - pattern = compiler(pattern, re.S | re.M) + pattern = constants.compiler(pattern, re.S | re.M) result = pattern.findall(self.content) if type(result) is list: if not result: @@ -419,7 +383,7 @@ Include:|Link:|License:|Maintainer:)' result = string() else: # if section in self.content pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex) - pattern = compiler(pattern, re.S | re.M) + pattern = constants.compiler(pattern, re.S | re.M) result = pattern.findall(self.content) if type(result) is list: if not result: @@ -447,7 +411,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -473,7 +437,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -499,7 +463,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -537,7 +501,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -570,7 +534,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -611,7 +575,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -637,7 +601,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -677,7 +641,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -708,7 +672,7 @@ Include:|Link:|License:|Maintainer:)' # TODO: unconditional automake snippet for nontests modules snippet = self.getAutomakeSnippet_Conditional() snippet = constants.combine_lines(snippet) - pattern = compiler( + pattern = constants.compiler( '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) mentioned_files = pattern.findall(snippet) if mentioned_files != list(): @@ -775,14 +739,14 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break parts += [line] result = ''.join(parts) result = result.strip() - pattern = compiler('^(["<].*?[>"])', re.S | re.M) + pattern = constants.compiler('^(["<].*?[>"])', re.S | re.M) result = pattern.sub('#include \\1', result) self.cache['include'] = result return(self.cache['include']) @@ -804,7 +768,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -840,7 +804,7 @@ Include:|Link:|License:|Maintainer:)' result = string() else: # if section in self.content pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex) - pattern = compiler(pattern, re.S | re.M) + pattern = constants.compiler(pattern, re.S | re.M) result = pattern.findall(self.content) if type(result) is list: if not result: @@ -868,7 +832,7 @@ Include:|Link:|License:|Maintainer:)' regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' regex += 'Makefile\\.am|Include|Link|License|Maintainer):$' - pattern = compiler(regex) + pattern = constants.compiler(regex) findflag = pattern.findall(line) if findflag: break @@ -1025,7 +989,7 @@ class GLModuleTable(object): if self.config['conddeps']: automake_snippet = \ module.getAutomakeSnippet_Conditional() - pattern = compiler('^if') + pattern = constants.compiler('^if') if not pattern.findall(automake_snippet): self.addUnconditional(module) conditional = self.isConditional(module) @@ -1150,7 +1114,7 @@ class GLModuleTable(object): raise(TypeError('each module must be a GLModule instance')) snippet = module.getAutomakeSnippet() snippet = constants.remove_backslash_newline(snippet) - pattern = compiler( + pattern = constants.compiler( '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) files = pattern.findall(snippet) if files: # if source files were found diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index fded6d7..ea572a2 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -1,62 +1,21 @@ #!/usr/bin/python # encoding: UTF-8 -#=============================================================================== -# Define global imports -#=============================================================================== +import codecs import os import re import sys -import locale -import codecs import shutil -import filecmp import subprocess as sp from . import constants +from .constants import (DIRS, ENCS, UTILS, compiler, joinpath, string) from .GLError import GLError from .GLConfig import GLConfig -from .GLModuleSystem import GLModule -from .GLModuleSystem import GLModuleTable -from .GLModuleSystem import GLModuleSystem -from .GLFileSystem import GLFileSystem -from .GLFileSystem import GLFileAssistant +from .GLModuleSystem import (GLModuleTable, GLModuleSystem) +from .GLFileSystem import (GLFileSystem, GLFileAssistant) from .GLMakefileTable import GLMakefileTable from .GLEmiter import GLEmiter - -#=============================================================================== -# Define module information -#=============================================================================== -__author__ = constants.__author__ -__license__ = constants.__license__ -__copyright__ = constants.__copyright__ - - -#=============================================================================== -# Define global constants -#=============================================================================== -PYTHON3 = constants.PYTHON3 -NoneType = type(None) -APP = constants.APP -DIRS = constants.DIRS -ENCS = constants.ENCS -UTILS = constants.UTILS -MODES = constants.MODES -TESTS = constants.TESTS -compiler = constants.compiler -joinpath = constants.joinpath -cleaner = constants.cleaner -relpath = constants.relativize -string = constants.string -isabs = os.path.isabs -isdir = os.path.isdir -isfile = os.path.isfile -normpath = os.path.normpath - - -#=============================================================================== -# Define GLTestDir class -#=============================================================================== class GLTestDir(object): '''GLTestDir class is used to create a scratch package with the given list of the modules.''' @@ -181,7 +140,7 @@ class GLTestDir(object): # $module-tests. Need this because tests are implicitly GPL and may depend # on GPL modules - therefore we don't want a warning in this case. saved_testflags = list(self.config['testflags']) - self.config.disableTestFlag(TESTS['tests']) + self.config.disableTestFlag(constants.TESTS['tests']) for requested_module in base_modules: requested_licence = requested_module.getLicense() # Here we use self.moduletable.transitive_closure([module]), not just @@ -330,12 +289,12 @@ class GLTestDir(object): dest = row[0] destpath = joinpath(self.testdir, dest) dirname = os.path.dirname(destpath) - if not isdir(dirname): + if not os.path.isdir(dirname): os.makedirs(dirname) if src.startswith('tests=lib/'): src = constants.substart('tests=lib/', 'lib/', src) lookedup, flag = self.filesystem.lookup(src) - if isfile(destpath): + if os.path.isfile(destpath): os.remove(destpath) if flag: shutil.copy(lookedup, destpath) @@ -348,7 +307,7 @@ class GLTestDir(object): # Create $sourcebase/Makefile.am. for_test = True directory = joinpath(self.testdir, sourcebase) - if not isdir(directory): + if not os.path.isdir(directory): os.mkdir(directory) destfile = joinpath(directory, 'Makefile.am') if single_configure: @@ -363,10 +322,10 @@ class GLTestDir(object): # Create $m4base/Makefile.am. directory = joinpath(self.testdir, m4base) - if not isdir(directory): + if not os.path.isdir(directory): os.mkdir(directory) destfile = joinpath(directory, 'Makefile.am') - emit = string() + emit = constants.string() emit += '## Process this file with automake to produce Makefile.in.\n\n' emit += 'EXTRA_DIST =\n' for file in filelist: @@ -383,10 +342,10 @@ class GLTestDir(object): subdirs_with_configure_ac = list() testsbase_appened = False - inctests = self.config.checkTestFlag(TESTS['tests']) + inctests = self.config.checkTestFlag(constants.TESTS['tests']) if inctests: directory = joinpath(self.testdir, testsbase) - if not isdir(directory): + if not os.path.isdir(directory): os.mkdir(directory) if single_configure: # Create $testsbase/Makefile.am. @@ -407,11 +366,11 @@ class GLTestDir(object): with codecs.open(destfile, 'wb', 'UTF-8') as file: file.write(emit) # Viewed from the $testsbase subdirectory, $auxdir is different. - emit = string() + emit = constants.string() saved_auxdir = self.config['auxdir'] testsbase = '%s/' % os.path.normpath(testsbase) counter = int() - auxdir = string() + auxdir = constants.string() finish = (len(testsbase.split('/')) - 1) while counter < finish: auxdir += '../' @@ -519,7 +478,7 @@ class GLTestDir(object): testsbase_appened = True # Create Makefile.am. - emit = string() + emit = constants.string() emit += '## Process this file with automake to produce Makefile.in.\n\n' emit += 'AUTOMAKE_OPTIONS = 1.9.6 foreign\n\n' emit += 'SUBDIRS = %s\n\n' % ' '.join(subdirs) @@ -532,7 +491,7 @@ class GLTestDir(object): file.write(emit) # Create configure.ac - emit = string() + emit = constants.string() emit += '# Process this file with autoconf ' emit += 'to produce a configure script.\n' emit += 'AC_INIT([dummy], [0])\n' @@ -662,14 +621,14 @@ class GLTestDir(object): # autopoint, which brings in older versions of some of our .m4 files. os.chdir(self.testdir) # gettext - if isfile(joinpath(m4base, 'gettext.m4')): + if os.path.isfile(joinpath(m4base, 'gettext.m4')): args = [UTILS['autopoint'], '--force'] constants.execute(args, verbose) for src in os.listdir(m4base): src = joinpath(m4base, src) if src.endswith('.m4~'): dest = src[:-1] - if isfile(dest): + if os.path.isfile(dest): os.remove(dest) shutil.move(src, dest) # libtoolize @@ -679,7 +638,7 @@ class GLTestDir(object): # aclocal args = [UTILS['aclocal'], '-I', m4base] constants.execute(args, verbose) - if not isdir('build-aux'): + if not os.path.isdir('build-aux'): os.mkdir('build-aux') # autoconf args = [UTILS['autoconf']] @@ -696,20 +655,20 @@ class GLTestDir(object): # autopoint, which brings in older versions of some of our .m4 files. os.chdir(joinpath(self.testdir, testsbase)) # gettext - if isfile(joinpath(m4base, 'gettext.m4')): + if os.path.isfile(joinpath(m4base, 'gettext.m4')): args = [UTILS['autopoint'], '--force'] constants.execute(args, verbose) for src in os.listdir(m4base): src = joinpath(m4base, src) if src.endswith('.m4~'): dest = src[:-1] - if isfile(dest): + if os.path.isfile(dest): os.remove(dest) shutil.move(src, dest) # aclocal args = [UTILS['aclocal'], '-I', joinpath('..', m4base)] constants.execute(args, verbose) - if not isdir(joinpath('../build-aux')): + if not os.path.isdir(joinpath('../build-aux')): os.mkdir('../build-aux') # autoconf args = [UTILS['autoconf']] @@ -893,7 +852,7 @@ class GLMegaTestDir(object): megasubdirs += ['ALL'] # Create autobuild. - emit = string() + emit = constants.string() repdict = dict() repdict['Jan'] = repdict['January'] = '01' repdict['Feb'] = repdict['February'] = '02' @@ -947,7 +906,7 @@ class GLMegaTestDir(object): file.write(emit) # Create Makefile.am. - emit = string() + emit = constants.string() emit += '## Process this file with automake to produce Makefile.in.\n\n' emit += 'AUTOMAKE_OPTIONS = 1.9.6 foreign\n\n' emit += 'SUBDIRS = %s\n\n' % ' '.join(megasubdirs) @@ -959,7 +918,7 @@ class GLMegaTestDir(object): with codecs.open(path, 'wb', 'UTF-8') as file: file.write(emit) - emit = string() + emit = constants.string() emit += '# Process this file with autoconf ' emit += 'to produce a configure script.\n' emit += 'AC_INIT([dummy], [0])\n\n' @@ -982,7 +941,7 @@ class GLMegaTestDir(object): args = [UTILS['aclocal']] constants.execute(args, verbose) try: # Try to make a directory - if not isdir('build-aux'): + if not os.path.isdir('build-aux'): os, mkdir('build-aux') except Exception as error: pass -- 2.9.5