]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Improve some error messages.
authorBruno Haible <bruno@clisp.org>
Sun, 31 Jul 2022 21:02:58 +0000 (23:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 31 Jul 2022 21:52:58 +0000 (23:52 +0200)
* 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
gnulib-tool.py
pygnulib/GLError.py
pygnulib/GLModuleSystem.py

index 1d642ca30f0fe1d81ffa8386bd138e592cd5e0b4..cc3c89fd1478a0fd3c89c42c343a267e88d481be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2022-07-31  Bruno Haible  <bruno@clisp.org>
 
+       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.
 
index f936a92031e600600b45a673f3866adb9f896849..302aaf340595c87be11cd2d393981043ef04b63a 100755 (executable)
@@ -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)
index a7cb81afe2aeeda41664b4f3bbd03e6fb3fab777..a366da5b1ae0723d46706973de641fbd863ccab7 100644 (file)
@@ -65,41 +65,53 @@ class GLError(Exception):
          17: cannot update the given file: <file>
          18: module lacks a license: <module>
          19: could not create destination directory: <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
index 00b2c5f035d4b8ca9b80bf78cb696866e3b02d09..319175dee8b97a27e55e2403cc76d47935735595 100644 (file)
@@ -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