1 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 from __future__
import annotations
18 #===============================================================================
19 # Define global imports
20 #===============================================================================
22 from typing
import Any
25 #===============================================================================
26 # Define GLError class
27 #===============================================================================
28 class GLError(Exception):
29 '''Exception handler for pygnulib classes.'''
35 def __init__(self
, errno
: int, errinfo
: Any
= None) -> None:
36 '''Each error has following parameters:
37 errno: code of error; used to catch error type
38 1: file does not exist in GLFileSystem: <file>
39 2: cannot patch file inside GLFileSystem: <file>
40 3: configure file does not exist: <configure.ac>
41 4: minimum supported autoconf version is 2.64, not <version>
42 5: <gnulib-comp.m4> is expected to contain gl_M4_BASE([<m4base>])
43 6: missing sourcebase argument
44 7: missing docbase argument
45 8: missing testsbase argument
46 9: missing libname argument
47 11: incompatible licenses on modules: <modules>
48 12: cannot process empty filelist
49 13: cannot create the given directory: <directory>
50 14: cannot delete the given file: <file>
51 15: cannot create the given file: <file>
52 16: cannot transform the given file: <file>
53 17: cannot update the given file: <file>
54 18: module lacks a license: <module>
55 19: could not create destination directory: <directory>
56 20: could not patch test-driver script
57 21: Option --automake-subdir is only supported if the definition of AUTOMAKE_OPTIONS in Makefile.am contains 'subdir-objects'.
58 22: not overwriting destination directory: <directory>
59 23: module <module> doesn't exist
60 24: module <module> cannot be used in a testdir
61 errinfo: additional information'''
63 self
.errinfo
= errinfo
64 self
.args
= (self
.errno
, self
.errinfo
)
66 def __repr__(self
) -> str:
68 errinfo
= self
.errinfo
69 if self
.message
== None:
72 message
= 'file does not exist in GLFileSystem: %s' % repr(errinfo
)
74 message
= 'cannot patch file inside GLFileSystem: %s' % repr(errinfo
)
76 message
= 'configure file does not exist: %s' % repr(errinfo
)
78 message
= 'minimum supported autoconf version is 2.64, not %s' % repr(errinfo
)
80 message
= '%s is expected to contain gl_M4_BASE([%s])' % (repr(os
.path
.join(errinfo
, 'gnulib-comp.m4')), repr(errinfo
))
82 message
= "missing sourcebase argument; cache file doesn't contain it, so you might have to set this argument"
84 message
= 'missing docbase argument; you might have to create GLImport instance with mode 0 and docbase argument'
86 message
= "missing testsbase argument; cache file doesn't contain it, so you might have to set this argument"
88 message
= "missing libname argument; cache file doesn't contain it, so you might have to set this argument"
90 message
= 'incompatible licenses on modules: %s' % repr(errinfo
)
92 message
= 'cannot process empty filelist'
94 message
= 'cannot create the given directory: %s' % repr(errinfo
)
96 message
= 'cannot remove the given file: %s' % repr(errinfo
)
98 message
= 'cannot create the given file: %s' % repr(errinfo
)
100 message
= 'cannot transform the given file: %s' % repr(errinfo
)
102 message
= 'cannot update/replace the given file: %s' % repr(errinfo
)
104 message
= 'module lacks a license: %s' % repr(errinfo
)
106 message
= 'error when running subprocess: %s' % repr(errinfo
)
108 message
= 'could not patch test-driver script'
110 message
= ('Option --automake-subdir/--automake-subdir-tests are only '
111 'supported if the definition of AUTOMAKE_OPTIONS in '
112 'Makefile.am contains \'subdir-objects\'.')
114 message
= 'not overwriting destination directory: %s' % repr(errinfo
)
116 message
= "module %s doesn't exist" % repr(errinfo
)
118 message
= 'module %s cannot be used in a testdir' % repr(errinfo
)
119 self
.message
= '[Errno %d] %s' % (errno
, message
)