obstack-zprintf: Add more tests.
[gnulib.git] / pygnulib / GLInfo.py
blobeac4c65071ada5f066e265ce19591ebc32581d1f
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 #===============================================================================
21 import os
22 import re
23 import subprocess as sp
24 from pygnulib import __author__, __copyright__
25 from .constants import DIRS, joinpath
28 #===============================================================================
29 # Define GLInfo class
30 #===============================================================================
31 class GLInfo:
32 '''This class is used to get formatted information about gnulib-tool.
33 This information is mainly used in stdout messages, but can be used
34 anywhere else. The return values are not the same as for the module,
35 but still depends on them.'''
37 def __repr__(self) -> str:
38 '''x.__repr__ <==> repr(x)'''
39 result = '<pygnulib.GLInfo %s>' % hex(id(self))
40 return result
42 def package(self) -> str:
43 '''Return formatted string which contains name of the package.'''
44 result = 'GNU gnulib'
45 return result
47 def authors(self) -> str:
48 '''Return formatted string which contains authors.
49 The special __author__ variable is used (type is list).'''
50 result = ''
51 for item in __author__:
52 if item == __author__[-1]:
53 result += 'and %s' % item
54 else:
55 result += '%s, ' % item
56 return result
58 def license(self) -> str:
59 '''Return formatted string which contains license and its description.'''
60 result = 'License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>\n'
61 result += 'This is free software: you are free to change and redistribute it.\n'
62 result += 'There is NO WARRANTY, to the extent permitted by law.'
63 return result
65 def copyright(self) -> str:
66 '''Return formatted string which contains copyright.
67 The special __copyright__ variable is used (type is str).'''
68 copyright = __copyright__
69 # Per the GNU Coding Standards, show only the last year.
70 copyright = re.compile(r'^[0-9]*-').sub(r'', copyright)
71 result = 'Copyright (C) %s' % copyright
72 return result
74 def date(self) -> str:
75 '''Return formatted string which contains date and time in GMT format.'''
76 if os.path.isdir(DIRS['git']):
77 try:
78 sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
79 have_git = True
80 except:
81 have_git = False
82 if have_git:
83 try:
84 sp.check_call(['date', '--version'], stdout=sp.DEVNULL)
85 have_GNU_date = True
86 except:
87 have_GNU_date = False
88 if have_GNU_date:
89 args = ['git', 'log', '-n', '1', '--format=medium', '--date=iso', 'ChangeLog']
90 result = sp.check_output(args, cwd=DIRS['root']).decode('UTF-8')
91 # Get date as "2008-03-21 07:16:51 -0600" from string
92 pattern = re.compile(r'^Date:[\t ]*(.*?)$', re.M)
93 result = pattern.findall(result)
94 if (len(result) > 0):
95 result = result[0]
96 else:
97 result = ''
98 # Use GNU date to compute the time in GMT
99 args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S']
100 proc = sp.check_output(args)
101 result = str(proc, 'UTF-8')
102 result = result.rstrip(os.linesep)
103 return result
104 # gnulib copy without versioning information.
105 with open(os.path.join(DIRS['root'], 'ChangeLog'), mode='r', newline='\n', encoding='utf-8') as file:
106 line = file.readline()
107 first_changelog_line = line.rstrip()
108 result = re.compile(r' .*').sub(r'', first_changelog_line)
109 return result
111 def copyright_range(self) -> str:
112 '''Returns a formatted copyright string showing a year range.'''
113 return f'Copyright (C) {__copyright__}'
115 def usage(self) -> str:
116 '''Show help message.'''
117 result = '''\
118 Usage: gnulib-tool --list
119 gnulib-tool --find filename
120 gnulib-tool --import [module1 ... moduleN]
121 gnulib-tool --add-import [module1 ... moduleN]
122 gnulib-tool --remove-import [module1 ... moduleN]
123 gnulib-tool --update
124 gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
125 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
126 gnulib-tool --test --dir=directory [module1 ... moduleN]
127 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
128 gnulib-tool --extract-description module
129 gnulib-tool --extract-comment module
130 gnulib-tool --extract-status module
131 gnulib-tool --extract-notice module
132 gnulib-tool --extract-applicability module
133 gnulib-tool --extract-filelist module
134 gnulib-tool --extract-dependencies module
135 gnulib-tool --extract-recursive-dependencies module
136 gnulib-tool --extract-autoconf-snippet module
137 gnulib-tool --extract-automake-snippet module
138 gnulib-tool --extract-include-directive module
139 gnulib-tool --extract-link-directive module
140 gnulib-tool --extract-recursive-link-directive module
141 gnulib-tool --extract-license module
142 gnulib-tool --extract-maintainer module
143 gnulib-tool --extract-tests-module module
144 gnulib-tool --copy-file file [destination]
146 Operation modes:
148 --list print the available module names
149 --find find the modules which contain the specified file
150 --import import the given modules into the current package
151 --add-import augment the list of imports from gnulib into the
152 current package, by adding the given modules;
153 if no modules are specified, update the current
154 package from the current gnulib
155 --remove-import reduce the list of imports from gnulib into the
156 current package, by removing the given modules
157 --update update the current package, restore files omitted
158 from version control
159 --create-testdir create a scratch package with the given modules
160 --create-megatestdir create a mega scratch package with the given modules
161 one by one and all together
162 --test test the combination of the given modules
163 (recommended to use CC=\"gcc -Wall\" here)
164 --megatest test the given modules one by one and all together
165 (recommended to use CC=\"gcc -Wall\" here)
166 --extract-description extract the description
167 --extract-comment extract the comment
168 --extract-status extract the status (obsolete etc.)
169 --extract-notice extract the notice or banner
170 --extract-applicability extract the applicability
171 --extract-filelist extract the list of files
172 --extract-dependencies extract the dependencies
173 --extract-recursive-dependencies extract the dependencies of the module
174 and its dependencies, recursively, all
175 together, but without the conditions
176 --extract-autoconf-snippet extract the snippet for configure.ac
177 --extract-automake-snippet extract the snippet for library makefile
178 --extract-include-directive extract the #include directive
179 --extract-link-directive extract the linker directive
180 --extract-recursive-link-directive extract the linker directive of the
181 module and its dependencies,
182 recursively, all together
183 --extract-license report the license terms of the source files
184 under lib/
185 --extract-maintainer report the maintainer(s) inside gnulib
186 --extract-tests-module report the unit test module, if it exists
187 --copy-file copy a file that is not part of any module
188 --help Show this help text.
189 --version Show version and authorship information.
191 General options:
193 --dir=DIRECTORY Specify the target directory.
194 For --import, this specifies where your
195 configure.ac can be found. Defaults to current
196 directory.
197 --local-dir=DIRECTORY Specify a local override directory where to look
198 up files before looking in gnulib's directory.
199 --verbose Increase verbosity. May be repeated.
200 --quiet Decrease verbosity. May be repeated.
202 Options for --import, --add/remove-import, --update:
204 --dry-run Only print what would have been done.
206 Options for --import, --add/remove-import:
208 --with-tests Include unit tests for the included modules.
210 Options for --create-[mega]testdir, --[mega]test:
212 --without-tests Don't include unit tests for the included modules.
214 Options for --import, --add/remove-import,
215 --create-[mega]testdir, --[mega]test:
217 --with-obsolete Include obsolete modules when they occur among the
218 dependencies. By default, dependencies to obsolete
219 modules are ignored.
220 --with-c++-tests Include even unit tests for C++ interoperability.
221 --without-c++-tests Exclude unit tests for C++ interoperability.
222 --with-longrunning-tests
223 Include even unit tests that are long-runners.
224 --without-longrunning-tests
225 Exclude unit tests that are long-runners.
226 --with-privileged-tests
227 Include even unit tests that require root
228 privileges.
229 --without-privileged-tests
230 Exclude unit tests that require root privileges.
231 --with-unportable-tests
232 Include even unit tests that fail on some platforms.
233 --without-unportable-tests
234 Exclude unit tests that fail on some platforms.
235 --with-all-tests Include all kinds of problematic unit tests.
236 --avoid=MODULE Avoid including the given MODULE. Useful if you
237 have code that provides equivalent functionality.
238 This option can be repeated.
239 --conditional-dependencies
240 Support conditional dependencies (may save configure
241 time and object code).
242 --no-conditional-dependencies
243 Don't use conditional dependencies.
244 --libtool Use libtool rules.
245 --no-libtool Don't use libtool rules.
247 Options for --import, --add/remove-import:
249 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
250 --source-base=DIRECTORY
251 Directory relative to --dir where source code is
252 placed (default \"lib\").
253 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
254 placed (default \"m4\").
255 --po-base=DIRECTORY Directory relative to --dir where *.po files are
256 placed (default \"po\").
257 --doc-base=DIRECTORY Directory relative to --dir where doc files are
258 placed (default \"doc\").
259 --tests-base=DIRECTORY
260 Directory relative to --dir where unit tests are
261 placed (default \"tests\").
262 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
263 tools are placed (default comes from configure.ac).
264 --gnu-make Output for GNU Make instead of for the default
265 Automake
266 --lgpl[=2|=3orGPLv2|=3]
267 Abort if modules aren't available under the LGPL.
268 Also modify license template from GPL to LGPL.
269 The version number of the LGPL can be specified;
270 the default is currently LGPLv3.
271 --makefile-name=NAME Name of makefile in the source-base and tests-base
272 directories (default \"Makefile.am\", or
273 \"Makefile.in\" if --gnu-make).
274 --tests-makefile-name=NAME
275 Name of makefile in the tests-base directory
276 (default as specified through --makefile-name).
277 --automake-subdir Specify that the makefile in the source-base
278 directory be generated in such a way that it can
279 be 'include'd from the toplevel Makefile.am.
280 --automake-subdir-tests
281 Likewise, but for the tests directory.
282 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
283 'gl_INIT'. Default is 'gl'.
284 --po-domain=NAME Specify the prefix of the i18n domain. Usually use
285 the package name. A suffix '-gnulib' is appended.
286 --witness-c-macro=NAME Specify the C macro that is defined when the
287 sources in this directory are compiled or used.
288 --vc-files Update version control related files.
289 --no-vc-files Don't update version control related files
290 (.gitignore and/or .cvsignore).
292 Options for --create-[mega]testdir, --[mega]test:
294 --single-configure Generate a single configure file, not a separate
295 configure file for the tests directory.
297 Options for --import, --add/remove-import, --update,
298 --create-[mega]testdir, --[mega]test:
300 -s, --symbolic, --symlink Make symbolic links instead of copying files.
301 --local-symlink Make symbolic links instead of copying files, only
302 for files from the local override directory.
303 -h, --hardlink Make hard links instead of copying files.
304 --local-hardlink Make hard links instead of copying files, only
305 for files from the local override directory.
307 Options for --import, --add/remove-import, --update:
309 -S, --more-symlinks Deprecated; equivalent to --symlink.
310 -H, --more-hardlinks Deprecated; equivalent to --hardlink.
312 Report bugs to <bug-gnulib@gnu.org>.'''
313 return result
315 def version(self) -> str:
316 '''Return formatted string which contains git version.'''
317 if os.path.isdir(DIRS['git']):
318 try:
319 sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
320 have_git = True
321 except:
322 have_git = False
323 if have_git:
324 version_gen = joinpath(DIRS['build-aux'], 'git-version-gen')
325 args = [version_gen, '/dev/null']
326 result = sp.check_output(args, cwd=DIRS['root']).decode('UTF-8')
327 result = result.strip()
328 result = result.replace('-dirty', '-modified')
329 if result == 'UNKNOWN':
330 result = ''
331 return result
332 # gnulib copy without versioning information.
333 return ''