unigbrk/uc-grapheme-breaks: Fix build failure.
[gnulib.git] / pygnulib / GLInfo.py
blob7347745d29674764557a1356a7f8b7c8e73c66f0
1 #!/usr/bin/python
2 # encoding: UTF-8
4 #===============================================================================
5 # Define global imports
6 #===============================================================================
7 import os
8 import re
9 import sys
10 import locale
11 import codecs
12 import subprocess as sp
13 from . import constants
16 #===============================================================================
17 # Define module information
18 #===============================================================================
19 __author__ = constants.__author__
20 __license__ = constants.__license__
21 __copyright__ = constants.__copyright__
24 #===============================================================================
25 # Define global constants
26 #===============================================================================
27 PYTHON3 = constants.PYTHON3
28 NoneType = type(None)
29 APP = constants.APP
30 DIRS = constants.DIRS
31 ENCS = constants.ENCS
32 UTILS = constants.UTILS
33 MODES = constants.MODES
34 TESTS = constants.TESTS
35 compiler = constants.compiler
36 joinpath = constants.joinpath
37 cleaner = constants.cleaner
38 string = constants.string
39 isabs = os.path.isabs
40 isdir = os.path.isdir
41 isfile = os.path.isfile
42 normpath = os.path.normpath
43 relpath = os.path.relpath
46 #===============================================================================
47 # Define GLInfo class
48 #===============================================================================
49 class GLInfo(object):
50 '''This class is used to get fromatted information about gnulib-tool.
51 This information is mainly used in stdout messages, but can be used
52 anywhere else. The return values are not the same as for the module,
53 but still depends on them.'''
55 def __repr__(self):
56 '''x.__repr__ <==> repr(x)'''
57 result = '<pygnulib.GLInfo %s>' % hex(id(self))
58 return(result)
60 def package(self):
61 '''Return formatted string which contains name of the package.'''
62 result = 'GNU gnulib'
63 return(result)
65 def authors(self):
66 '''Return formatted string which contains authors.
67 The special __author__ variable is used (type is list).'''
68 result = string()
69 for item in __author__:
70 if item == __author__[-2]:
71 result += '%s ' % item
72 elif item == __author__[-1]:
73 result += 'and %s' % item
74 else:
75 result += '%s, ' % item
76 return(result)
78 def license(self):
79 '''Return formatted string which contains license and its description.'''
80 result = 'License GPLv3+: GNU GPL version 3 or later'
81 result += ' <https://gnu.org/licenses/gpl.html>\n'
82 result += 'This is free software: you are free'
83 result += ' to change and redistribute it.\n'
84 result += 'There is NO WARRANTY, to the extent permitted by law.'
85 return(result)
87 def copyright(self):
88 '''Return formatted string which contains copyright.
89 The special __copyright__ variable is used (type is str).'''
90 result = 'Copyright (C) %s' % __copyright__
91 return(result)
93 def date(self):
94 '''Return formatted string which contains date and time in GMT format.'''
95 if isdir(DIRS['git']):
96 counter = int() # Create counter
97 result = string() # Create string
98 args = ['git', 'log']
99 result = sp.check_output(args).decode("UTF-8")
100 # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string
101 pattern = re.compile('Date:[\t ]*(.*?)$', re.S | re.M)
102 result = pattern.findall(result)[0]
103 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600"
104 pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ')
105 result = pattern.sub('\\1 \\2 \\4 \\3 ', result)
106 # Use GNU date to compute the time in GMT
107 args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S']
108 proc = sp.check_output(args)
109 result = string(proc, "UTF-8")
110 result = result.rstrip(os.linesep)
111 return(result)
113 def usage(self):
114 '''Show help message.'''
115 result = '''\
116 Usage: gnulib-tool --list
117 gnulib-tool --find filename
118 gnulib-tool --import [module1 ... moduleN]
119 gnulib-tool --add-import [module1 ... moduleN]
120 gnulib-tool --remove-import [module1 ... moduleN]
121 gnulib-tool --update
122 gnulib-tool --create-testdir --dir=directory [module1 ... moduleN]
123 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
124 gnulib-tool --test --dir=directory module1 ... moduleN
125 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
126 gnulib-tool --extract-description module
127 gnulib-tool --extract-comment module
128 gnulib-tool --extract-status module
129 gnulib-tool --extract-notice module
130 gnulib-tool --extract-applicability module
131 gnulib-tool --extract-filelist module
132 gnulib-tool --extract-dependencies module
133 gnulib-tool --extract-autoconf-snippet module
134 gnulib-tool --extract-automake-snippet module
135 gnulib-tool --extract-include-directive module
136 gnulib-tool --extract-link-directive module
137 gnulib-tool --extract-license module
138 gnulib-tool --extract-maintainer module
139 gnulib-tool --extract-tests-module module
140 gnulib-tool --copy-file file [destination]
142 Operation modes:
144 --list print the available module names
145 --find find the modules which contain the specified file
146 --import import the given modules into the current package
147 --add-import augment the list of imports from gnulib into the
148 current package, by adding the given modules;
149 if no modules are specified, update the current
150 package from the current gnulib
151 --remove-import reduce the list of imports from gnulib into the
152 current package, by removing the given modules
153 --update update the current package, restore files omitted
154 from version control
155 --create-testdir create a scratch package with the given modules
156 --create-megatestdir create a mega scratch package with the given modules
157 one by one and all together
158 --test test the combination of the given modules
159 (recommended to use CC=\"gcc -Wall\" here)
160 --megatest test the given modules one by one and all together
161 (recommended to use CC=\"gcc -Wall\" here)
162 --extract-description extract the description
163 --extract-comment extract the comment
164 --extract-status extract the status (obsolete etc.)
165 --extract-notice extract the notice or banner
166 --extract-applicability extract the applicability
167 --extract-filelist extract the list of files
168 --extract-dependencies extract the dependencies
169 --extract-autoconf-snippet extract the snippet for configure.ac
170 --extract-automake-snippet extract the snippet for library makefile
171 --extract-include-directive extract the #include directive
172 --extract-link-directive extract the linker directive
173 --extract-license report the license terms of the source files
174 under lib/
175 --extract-maintainer report the maintainer(s) inside gnulib
176 --extract-tests-module report the unit test module, if it exists
177 --copy-file copy a file that is not part of any module
178 --help Show this help text.
179 --version Show version and authorship information.
181 General options:
183 --dir=DIRECTORY Specify the target directory.
184 For --import, this specifies where your
185 configure.ac can be found. Defaults to current
186 directory.
187 --local-dir=DIRECTORY Specify a local override directory where to look
188 up files before looking in gnulib's directory.
189 --cache-modules Enable module caching optimization.
190 --no-cache-modules Disable module caching optimization.
191 --verbose Increase verbosity. May be repeated.
192 --quiet Decrease verbosity. May be repeated.
194 Options for --import, --add/remove-import, --update:
196 --dry-run Only print what would have been done.
198 Options for --import, --add/remove-import:
200 --with-tests Include unit tests for the included modules.
202 Options for --create-[mega]testdir, --[mega]test:
204 --without-tests Don't include unit tests for the included modules.
206 Options for --import, --add/remove-import,
207 --create-[mega]testdir, --[mega]test:
209 --with-obsolete Include obsolete modules when they occur among the
210 dependencies. By default, dependencies to obsolete
211 modules are ignored.
212 --with-c++-tests Include even unit tests for C++ interoperability.
213 --without-c++-tests Exclude unit tests for C++ interoperability.
214 --with-longrunning-tests
215 Include even unit tests that are long-runners.
216 --without-longrunning-tests
217 Exclude unit tests that are long-runners.
218 --with-privileged-tests
219 Include even unit tests that require root
220 privileges.
221 --without-privileged-tests
222 Exclude unit tests that require root privileges.
223 --with-unportable-tests
224 Include even unit tests that fail on some platforms.
225 --without-unportable-tests
226 Exclude unit tests that fail on some platforms.
227 --with-all-tests Include all kinds of problematic unit tests.
228 --avoid=MODULE Avoid including the given MODULE. Useful if you
229 have code that provides equivalent functionality.
230 This option can be repeated.
231 --conditional-dependencies
232 Support conditional dependencies (may save configure
233 time and object code).
234 --no-conditional-dependencies
235 Don't use conditional dependencies.
236 --libtool Use libtool rules.
237 --no-libtool Don't use libtool rules.
239 Options for --import, --add/remove-import:
241 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
242 --source-base=DIRECTORY
243 Directory relative to --dir where source code is
244 placed (default \"lib\").
245 --m4-base=DIRECTORY Directory relative to --dir where *.m4 macros are
246 placed (default \"m4\").
247 --po-base=DIRECTORY Directory relative to --dir where *.po files are
248 placed (default \"po\").
249 --doc-base=DIRECTORY Directory relative to --dir where doc files are
250 placed (default \"doc\").
251 --tests-base=DIRECTORY
252 Directory relative to --dir where unit tests are
253 placed (default \"tests\").
254 --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build
255 tools are placed (default comes from configure.ac).
256 --lgpl[=2|=3] Abort if modules aren't available under the LGPL.
257 Also modify license template from GPL to LGPL.
258 The version number of the LGPL can be specified;
259 the default is currently LGPLv3.
260 --makefile-name=NAME Name of makefile in automake syntax in the
261 source-base and tests-base directories
262 (default \"Makefile.am\").
263 --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and
264 'gl_INIT'. Default is 'gl'.
265 --po-domain=NAME Specify the prefix of the i18n domain. Usually use
266 the package name. A suffix '-gnulib' is appended.
267 --witness-c-macro=NAME Specify the C macro that is defined when the
268 sources in this directory are compiled or used.
269 --vc-files Update version control related files.
270 --no-vc-files Don't update version control related files
271 (.gitignore and/or .cvsignore).
273 Options for --create-[mega]testdir, --[mega]test:
275 --single-configure Generate a single configure file, not a separate
276 configure file for the tests directory.
278 Options for --import, --add/remove-import, --update,
279 --create-[mega]testdir, --[mega]test:
281 -s, --symbolic, --symlink Make symbolic links instead of copying files.
282 --local-symlink Make symbolic links instead of copying files, only
283 for files from the local override directory.
285 Options for --import, --add/remove-import, --update:
287 -S, --more-symlinks Make symbolic links instead of copying files, and
288 don't replace copyright notices.
290 Report bugs to <bug-gnulib@gnu.org>.'''
291 return(result)
293 def version(self):
294 '''Return formatted string which contains git version.'''
295 if isdir(DIRS['git']):
296 version_gen = joinpath(DIRS['build-aux'], 'git-version-gen')
297 args = [version_gen, DIRS['root']]
298 result = sp.check_output(args).decode("UTF-8")
299 result = result.strip()
300 if result == 'UNKNOWN':
301 result = string()
302 return(result)