From 6b79ce37dd0153046cd05a43e0957dab20234d5e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 Jul 2022 23:02:58 +0200 Subject: gnulib-tool.py: Improve some error messages. * gnulib-tool.py (main): Write "*** Stop." instead of "*** Exit.". (__main__): Print an error message for GLError 5, 13, 14, 15, 16, 17, 18. * pygnulib/GLError.py (GLError.__repr__): Compute one error message, not 19. --- ChangeLog | 6 ++++ gnulib-tool.py | 39 +++++++++++++----------- pygnulib/GLError.py | 74 +++++++++++++++++++++++++++------------------- pygnulib/GLModuleSystem.py | 3 +- 4 files changed, 72 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d642ca30f..cc3c89fd14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2022-07-31 Bruno Haible + gnulib-tool.py: Improve some error messages. + * gnulib-tool.py (main): Write "*** Stop." instead of "*** Exit.". + (__main__): Print an error message for GLError 5, 13, 14, 15, 16, 17, 18. + * pygnulib/GLError.py (GLError.__repr__): Compute one error message, + not 19. + gnulib-tool.py: Write errors to stderr, not stdout. * pygnulib/constants.py: Write error messages to stderr, not stdout. diff --git a/gnulib-tool.py b/gnulib-tool.py index f936a92031..302aaf3405 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -486,7 +486,7 @@ def main(): if len(cmdargs.non_option_arguments) < 1 or len(cmdargs.non_option_arguments) > 2: message = '%s: *** ' % constants.APP['name'] message += 'invalid number of arguments for --%s' % mode - message += '\n%s: *** Exit.\n' % constants.APP['name'] + message += '\n%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) files = list(cmdargs.non_option_arguments) @@ -722,7 +722,7 @@ def main(): if not destdir: message = '%s: *** ' % constants.APP['name'] message += 'please specify --dir option' - message += '\n%s: *** Exit.\n' % constants.APP['name'] + message += '\n%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) if not auxdir: @@ -735,7 +735,7 @@ def main(): if not destdir: message = '%s: *** ' % constants.APP['name'] message += 'please specify --dir option' - message += '\n%s: *** Exit.\n' % constants.APP['name'] + message += '\n%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) if not auxdir: @@ -846,7 +846,7 @@ def main(): if avoids: message = '%s: *** ' % constants.APP['name'] message += 'cannot combine --avoid and --extract-dependencies\n' - message += '%s: *** Exit.\n' % constants.APP['name'] + message += '%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) modulesystem = classes.GLModuleSystem(config) @@ -978,7 +978,7 @@ def main(): else: message = '%s: *** ' % constants.APP['name'] message += 'no mode specified' - message += '\n%s: *** Exit.\n' % constants.APP['name'] + message += '\n%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) @@ -999,15 +999,13 @@ if __name__ == '__main__': elif errno == 2: message += 'patch file %s didn\'t apply cleanly' % errinfo elif errno == 3: - message += 'cannot find %s - make sure ' % errinfo - message += 'you run gnulib-tool from within your package\'s directory' + message += 'cannot find %s - make sure you run gnulib-tool from within your package\'s directory' % errinfo elif errno == 4: message += 'minimum supported autoconf version is 2.59. Try adding' message += 'AC_PREREQ([%s])' % constants.DEFAULT_AUTOCONF_MINVERSION message += ' to your configure.ac.' elif errno == 5: - "%s is expected to contain gl_M4_BASE([%s])" % \ - (repr(os.path.join(errinfo, 'gnulib-comp.m4')), repr(errinfo)) + message += '%s is expected to contain gl_M4_BASE([%s])' % (repr(os.path.join(errinfo, 'gnulib-comp.m4')), repr(errinfo)) elif errno == 6: message += 'missing --source-base option' elif errno == 7: @@ -1020,8 +1018,7 @@ if __name__ == '__main__': elif errno == 9: message += 'missing --lib option' elif errno == 10: - message = 'gnulib-tool: option --conditional-dependencies is not ' - message += 'supported with --with-tests\n' + message = 'gnulib-tool: option --conditional-dependencies is not supported with --with-tests' elif errno == 11: incompatibilities = '' message += 'incompatible license on modules:%s' % constants.NL @@ -1035,17 +1032,25 @@ if __name__ == '__main__': sed_table = 's,^\\([^ ]*\\) ,\\1' + ' ' * 51 + ',\n' sed_table += 's,^\\(' + '.' * 49 + '[^ ]*\\) *,' + ' ' * 17 + '\\1 ,' args = ['sed', '-e', sed_table, tempname] - incompatibilities = sp.check_output( - args).decode(ENCS['default']) + incompatibilities = sp.check_output(args).decode(ENCS['default']) message += incompatibilities os.remove(tempname) elif errno == 12: message += 'refusing to do nothing' - elif errno in [13, 14, 15, 16, 17]: - message += 'failed' + elif errno == 13: + message += 'could not create directory %s' % errinfo + elif errno == 14: + message += 'could not delete file %s' % errinfo + elif errno == 15: + message += 'could not create file %s' % errinfo + elif errno == 16: + message += 'could not transform file %s' % errinfo + elif errno == 17: + message += 'could not update file %s' % errinfo + elif errno == 18: + message += 'module %s lacks a license' % errinfo elif errno == 19: message += 'could not create destination directory: %s' % errinfo - if errno != 10: - message += '\n%s: *** Exit.\n' % constants.APP['name'] + message += '\n%s: *** Stop.\n' % constants.APP['name'] sys.stderr.write(message) sys.exit(1) diff --git a/pygnulib/GLError.py b/pygnulib/GLError.py index a7cb81afe2..a366da5b1a 100644 --- a/pygnulib/GLError.py +++ b/pygnulib/GLError.py @@ -65,41 +65,53 @@ class GLError(Exception): 17: cannot update the given file: 18: module lacks a license: 19: could not create destination directory: - errinfo: additional information; - style: 0 or 1, whether old-style''' + errinfo: additional information''' self.errno = errno self.errinfo = errinfo self.args = (self.errno, self.errinfo) def __repr__(self): + errno = self.errno errinfo = self.errinfo - errors = \ - [ # Begin list of errors - "file does not exist in GLFileSystem: %s" % repr(errinfo), - "cannot patch file inside GLFileSystem: %s" % repr(errinfo), - "configure file does not exist: %s" % repr(errinfo), - "minimum supported autoconf version is 2.59, not %s" % repr( - errinfo), - "%s is expected to contain gl_M4_BASE([%s])" % \ - (repr(os.path.join(errinfo, 'gnulib-comp.m4')), repr(errinfo)), - "missing sourcebase argument; cache file doesn't contain it," - + " so you might have to set this argument", - "missing docbase argument; you might have to create GLImport" \ - + " instance with mode 0 and docbase argument", - "missing testsbase argument; cache file doesn't contain it," - + " so you might have to set this argument" - "missing libname argument; cache file doesn't contain it," - + " so you might have to set this argument", - "conddeps are not supported with inctests", - "incompatible licenses on modules: %s" % repr(errinfo), - "cannot process empty filelist", - "cannot create the given directory: %s" % repr(errinfo), - "cannot remove the given file: %s" % repr(errinfo), - "cannot create the given file: %s" % repr(errinfo), - "cannot transform the given file: %s" % repr(errinfo), - "cannot update/replace the given file: %s" % repr(errinfo), - "module lacks a license: %s" % repr(errinfo), - "error when running subprocess: %s" % repr(errinfo), - ] # Complete list of errors - self.message = '[Errno %d] %s' % (self.errno, errors[self.errno - 1]) + if self.message == None: + message = None + if errno == 1: + message = "file does not exist in GLFileSystem: %s" % repr(errinfo) + elif errno == 2: + message = "cannot patch file inside GLFileSystem: %s" % repr(errinfo) + elif errno == 3: + message = "configure file does not exist: %s" % repr(errinfo) + elif errno == 4: + message = "minimum supported autoconf version is 2.59, not %s" % repr(errinfo) + elif errno == 5: + message = "%s is expected to contain gl_M4_BASE([%s])" % (repr(os.path.join(errinfo, 'gnulib-comp.m4')), repr(errinfo)) + elif errno == 6: + message = "missing sourcebase argument; cache file doesn't contain it, so you might have to set this argument" + elif errno == 7: + message = "missing docbase argument; you might have to create GLImport instance with mode 0 and docbase argument" + elif errno == 8: + message = "missing testsbase argument; cache file doesn't contain it, so you might have to set this argument" + elif errno == 9: + message = "missing libname argument; cache file doesn't contain it, so you might have to set this argument" + elif errno == 10: + message = "conddeps are not supported with inctests" + elif errno == 11: + message = "incompatible licenses on modules: %s" % repr(errinfo) + elif errno == 12: + message = "cannot process empty filelist" + elif errno == 13: + message = "cannot create the given directory: %s" % repr(errinfo) + elif errno == 14: + message = "cannot remove the given file: %s" % repr(errinfo) + elif errno == 15: + message = "cannot create the given file: %s" % repr(errinfo) + elif errno == 16: + message = "cannot transform the given file: %s" % repr(errinfo) + elif errno == 17: + message = "cannot update/replace the given file: %s" % repr(errinfo) + elif errno == 18: + message = "module lacks a license: %s" % repr(errinfo) + elif errno == 19: + message = "error when running subprocess: %s" % repr(errinfo) + self.message = '[Errno %d] %s' % (errno, message) return self.message diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 00b2c5f035..319175dee8 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -802,8 +802,7 @@ Include:|Link:|License:|Maintainer:)' if self.config['errors']: raise GLError(18, str(self)) else: # if not self.config['errors'] - sys.stderr.write('gnulib-tool: warning: ') - sys.stderr.write('module %s lacks a license\n' % str(self)) + sys.stderr.write('gnulib-tool: warning: module %s lacks a license\n' % str(self)) if not license: license = 'GPL' return license -- cgit v1.2.1