summaryrefslogtreecommitdiff
path: root/pygnulib/GLConfig.py
blob: a2392bf90419e47e753d483b97dd64875de1920c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
# Copyright (C) 2002-2023 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

#===============================================================================
# Define global imports
#===============================================================================
import os
import copy
import tempfile
from . import constants
from .GLError import GLError


#===============================================================================
# Define module information
#===============================================================================
__author__ = constants.__author__
__license__ = constants.__license__
__copyright__ = constants.__copyright__


#===============================================================================
# Define global constants
#===============================================================================
MODES = constants.MODES
TESTS = constants.TESTS
joinpath = constants.joinpath
relpath = constants.relativize
remove_trailing_slashes = constants.remove_trailing_slashes
isfile = os.path.isfile
normpath = os.path.normpath


#===============================================================================
# Define GLConfig class
#===============================================================================
class GLConfig(object):
    '''This class is used to store intermediate settings for all pygnulib
    classes. It contains all necessary attributes to setup any other class.
    By default all attributes are set to empty string, empty list or zero.
    The most common value, however, is a None value.'''

    def __init__(self, destdir=None, localpath=None, auxdir=None,
                 sourcebase=None, m4base=None, pobase=None, docbase=None, testsbase=None,
                 modules=None, avoids=None, files=None,
                 incl_test_categories=None, excl_test_categories=None, libname=None,
                 lgpl=None, makefile_name=None, libtool=None, conddeps=None, macro_prefix=None,
                 podomain=None, witness_c_macro=None, vc_files=None, symbolic=None,
                 lsymbolic=None, configure_ac=None, ac_version=None,
                 libtests=None, single_configure=None, verbose=None, dryrun=None,
                 errors=None):
        '''GLConfig.__init__(arguments) -> GLConfig

        Create new GLConfig instance.'''
        self.table = dict()
        self.table['tempdir'] = tempfile.mkdtemp()
        # Check and store the attributes.
        # Remove trailing slashes from the directory names. This is necessary
        # for m4base (to avoid an error in func_import) and optional for the
        # others.
        # destdir
        self.resetDestDir()
        if destdir != None:
            self.setDestDir(destdir)
        # localpath
        self.resetLocalPath()
        if localpath != None:
            self.setLocalPath(localpath)
        # auxdir
        self.resetAuxDir()
        if auxdir != None:
            self.setAuxDir(auxdir)
        # sourcebase
        self.resetSourceBase()
        if sourcebase != None:
            self.setSourceBase(sourcebase)
        # m4base
        self.resetM4Base()
        if m4base != None:
            self.setM4Base(m4base)
        # pobase
        self.resetPoBase()
        if pobase != None:
            self.setPoBase(pobase)
        # docbase
        self.resetDocBase()
        if docbase != None:
            self.setDocBase(docbase)
        # testsbase
        self.resetTestsBase()
        if testsbase != None:
            self.setTestsBase(testsbase)
        # modules
        self.resetModules()
        if modules != None:
            self.setModules(modules)
        # avoids
        self.resetAvoids()
        if avoids != None:
            self.setAvoids(avoids)
        # files
        self.resetFiles()
        if files != None:
            self.setFiles(files)
        # test categories to include
        self.resetInclTestCategories()
        if incl_test_categories != None:
            self.setInclTestCategories(incl_test_categories)
        # test categories to exclude
        self.resetExclTestCategories()
        if excl_test_categories != None:
            self.setExclTestCategories(excl_test_categories)
        # libname
        self.resetLibName()
        if libname != None:
            self.setLibName(libname)
        # lgpl
        self.resetLGPL()
        if lgpl != None:
            self.setLGPL(lgpl)
        # makefile_name
        self.resetMakefileName()
        if makefile_name != None:
            self.setMakefileName(makefile_name)
        # libtool
        self.resetLibtool()
        if libtool != None:
            self.setLibtool(libtool)
        # conddeps
        self.resetCondDeps()
        if conddeps != None:
            self.setCondDeps(conddeps)
        # macro_prefix
        self.resetMacroPrefix()
        if macro_prefix != None:
            self.setMacroPrefix(macro_prefix)
        # podomain
        self.resetPoDomain()
        if podomain != None:
            self.setPoDomain(podomain)
        # witness_c_macro
        self.resetWitnessCMacro()
        if witness_c_macro != None:
            self.setWitnessCMacro(witness_c_macro)
        # vc_files
        self.resetVCFiles()
        if vc_files != None:
            self.setVCFiles(vc_files)
        # symbolic
        self.resetSymbolic()
        if symbolic != None:
            self.setSymbolic(symbolic)
        # lsymbolic
        self.resetLSymbolic()
        if lsymbolic != None:
            self.setLSymbolic(lsymbolic)
        # configure_ac
        self.resetAutoconfFile()
        if configure_ac != None:
            self.setAutoconfFile(configure_ac)
        # ac_version
        self.resetAutoconfVersion()
        if ac_version != None:
            self.setAutoconfVersion(ac_version)
        # libtests
        self.resetLibtests()
        if libtests != None:
            self.setLibtests(libtests)
        # single_configure
        self.resetSingleConfigure()
        if single_configure != None:
            self.setSingleConfigure(single_configure)
        # verbose
        self.resetVerbosity()
        if verbose != None:
            self.setVerbosity(verbose)
        # dryrun
        self.resetDryRun()
        if dryrun != None:
            self.setDryRun(dryrun)
        # errors
        self.resetErrors()
        if errors != None:
            self.setErrors(errors)

    # Define special methods.
    def __repr__(self):
        '''x.__repr__() <==> repr(x)'''
        return '<pygnulib.GLConfig>'

    def __getitem__(self, y):
        '''x.__getitem__(y) <==> x[y]'''
        if y in self.table:
            result = self.table[y]
            if type(y) is list:
                result = list(self.table[y])
            if y == "auxdir":
                if self.table['auxdir']:
                    return self.table['auxdir']
                return "build-aux"
            return self.table[y]
        else:  # if y not in self.table
            raise KeyError('GLConfig does not contain key: %s' % repr(y))

    def dictionary(self):
        '''Return the configuration as a dict object.'''
        return dict(self.table)

    def copy(self):
        '''Return the copy of the configuration.'''
        table = copy.deepcopy(self)
        return table

    def update(self, dictionary):
        '''Specify the dictionary whose keys will be used to update config.'''
        if type(dictionary) is not GLConfig:
            raise TypeError('dictionary must be a GLConfig, not %s'
                            % type(dictionary).__name__)
        dictionary = dict(dictionary.table)
        result = dict()
        for key in dictionary:
            src = self.table[key]
            dest = dictionary[key]
            result[key] = src
            if src != dest:
                if self.isdefault(key, src):
                    result[key] = dest
                else:  # if not self.isdefault(key, src)
                    result[key] == src
                    if not self.isdefault(key, dest):
                        if key in ['modules', 'avoids', 'tests']:
                            dest = sorted(set(src + dest))
                        result[key] = dest
        self.table = dict(result)

    def update_key(self, dictionary, key):
        '''Update the given key using value from the given dictionary.'''
        if key in self.table:
            if type(dictionary) is not GLConfig:
                raise TypeError('dictionary must be a GLConfig, not %s'
                                % type(dictionary).__name__)
            dictionary = dict(dictionary.table)
            self.table[key] = dictionary[key]
        else:  # if key not in self.table
            raise KeyError('GLConfig does not contain key: %s' % repr(key))

    def default(self, key):
        '''Return default value for the given key.'''
        if key in self.table:
            if key == 'libname':
                return 'libgnu'
            elif key == 'macro_prefix':
                return 'gl'
            elif key == 'include_guard_prefix':
                return 'GL'
            elif key == 'ac_version':
                return 2.59
            elif key == 'verbosity':
                return 0
            elif key == 'copyrights':
                return True
            elif key in ['modules', 'avoids', 'tests', 'incl_test_categories', 'excl_test_categories']:
                return list()
            elif key in ['libtool', 'lgpl', 'conddeps', 'symbolic', 'lsymbolic',
                         'libtests', 'dryrun']:
                return False
            elif key == 'vc_files':
                return None
            elif key == 'errors':
                return True
            else:  # otherwise
                return ''
        else:  # if key not in self.table
            raise KeyError('GLConfig does not contain key: %s' % repr(key))

    def isdefault(self, key, value):
        '''Check whether the value for the given key is a default value.'''
        if key in self.table:
            default = self.default(key)
            return value == default
        else:  # if key not in self.table
            raise KeyError('GLConfig does not contain key: %s' % repr(key))

    def keys(self):
        '''Return list of keys.'''
        return list(self.table.keys())

    def values(self):
        '''Return list of values.'''
        return list(self.table.values())

    # Define destdir methods.
    def getDestDir(self):
        '''Return the target directory. For --import, this specifies where your
        configure.ac can be found. Defaults to current directory.'''
        return self.table['destdir']

    def setDestDir(self, destdir):
        '''Specify the target directory. For --import, this specifies where your
        configure.ac can be found. Defaults to current directory.'''
        if type(destdir) is str:
            if destdir:
                self.table['destdir'] = os.path.normpath(destdir)
        else:  # if destdir has not str type
            raise TypeError('destdir must be a string, not %s'
                            % type(destdir).__name__)

    def resetDestDir(self):
        '''Reset the target directory. For --import, this specifies where your
        configure.ac can be found. Defaults to current directory.'''
        self.table['destdir'] = ''

    # Define localpath methods.
    def getLocalPath(self):
        '''Return a list of local override directories where to look up files
        before looking in gnulib's directory. The first one has the highest
        priority.'''
        return self.table['localpath']

    def setLocalPath(self, localpath):
        '''Specify a list of local override directories where to look up files
        before looking in gnulib's directory. The first one has the highest
        priority.'''
        if type(localpath) is list:
            for dir in localpath:
                if type(dir) is not str:
                    raise TypeError('localpath element must be a string, not %s' % type(dir).__name__)
        else:
            raise TypeError('localpath must be a list, not %s' % type(localpath).__name__)
        self.table['localpath'] = [ remove_trailing_slashes(dir)
                                    for dir in localpath ]

    def resetLocalPath(self):
        '''Reset a list of local override directories where to look up files
        before looking in gnulib's directory.'''
        self.table['localpath'] = []

    # Define auxdir methods.
    def getAuxDir(self):
        '''Return directory relative to --dir where auxiliary build tools are
        placed. Default comes from configure.ac or configure.in.'''
        if self.table['auxdir']:
            return self.table['auxdir']
        return "build-aux"

    def setAuxDir(self, auxdir):
        '''Specify directory relative to --dir where auxiliary build tools are
        placed. Default comes from configure.ac or configure.in.'''
        if type(auxdir) is str:
            if auxdir:
                self.table['auxdir'] = remove_trailing_slashes(auxdir)
        else:  # if type of auxdir is not str
            raise TypeError('auxdir must be a string, not %s'
                            % type(auxdir).__name__)

    def resetAuxDir(self):
        '''Reset directory relative to --dir where auxiliary build tools are
        placed. Default comes from configure.ac or configure.in.'''
        self.table['auxdir'] = ''

    # Define sourcebase methods.
    def getSourceBase(self):
        '''Return directory relative to destdir where source code is placed.'''
        return self.table['sourcebase']

    def setSourceBase(self, sourcebase):
        '''Specify directory relative to destdir where source code is placed.'''
        if type(sourcebase) is str:
            if sourcebase:
                self.table['sourcebase'] = remove_trailing_slashes(sourcebase)
        else:  # if type of sourcebase is not str
            raise TypeError('sourcebase must be a string, not %s'
                            % type(sourcebase).__name__)

    def resetSourceBase(self):
        '''Return directory relative to destdir where source code is placed.'''
        self.table['sourcebase'] = ''

    # Define m4base methods.
    def getM4Base(self):
        '''Return directory relative to destdir where *.m4 macros are placed.'''
        return self.table['m4base']

    def setM4Base(self, m4base):
        '''Specify directory relative to destdir where *.m4 macros are placed.'''
        if type(m4base) is str:
            if m4base:
                self.table['m4base'] = remove_trailing_slashes(m4base)
        else:  # if type of m4base is not str
            raise TypeError('m4base must be a string, not %s'
                            % type(m4base).__name__)

    def resetM4Base(self):
        '''Reset directory relative to destdir where *.m4 macros are placed.'''
        self.table['m4base'] = ''

    # Define pobase methods.
    def getPoBase(self):
        '''Return directory relative to destdir where *.po files are placed.'''
        return self.table['pobase']

    def setPoBase(self, pobase):
        '''Specify directory relative to destdir where *.po files are placed.'''
        if type(pobase) is str:
            if pobase:
                self.table['pobase'] = remove_trailing_slashes(pobase)
        else:  # if type of pobase is not str
            raise TypeError('pobase must be a string, not %s'
                            % type(pobase).__name__)

    def resetPoBase(self):
        '''Reset directory relative to destdir where *.po files are placed.'''
        self.table['pobase'] = ''

    # Define docbase methods.
    def getDocBase(self):
        '''Return directory relative to destdir where doc files are placed.
        Default value for this variable is 'doc').'''
        return self.table['docbase']

    def setDocBase(self, docbase):
        '''Specify directory relative to destdir where doc files are placed.
        Default value for this variable is 'doc').'''
        if type(docbase) is str:
            if docbase:
                self.table['docbase'] = remove_trailing_slashes(docbase)
        else:  # if type of docbase is not str
            raise TypeError('docbase must be a string, not %s'
                            % type(docbase).__name__)

    def resetDocBase(self):
        '''Reset directory relative to destdir where doc files are placed.
        Default value for this variable is 'doc').'''
        self.table['docbase'] = ''

    # Define testsbase methods.
    def getTestsBase(self):
        '''Return directory relative to destdir where unit tests are placed.
        Default value for this variable is 'tests').'''
        return self.table['testsbase']

    def setTestsBase(self, testsbase):
        '''Specify directory relative to destdir where unit tests are placed.
        Default value for this variable is 'tests').'''
        if type(testsbase) is str:
            if testsbase:
                self.table['testsbase'] = remove_trailing_slashes(testsbase)
        else:  # if type of testsbase is not str
            raise TypeError('testsbase must be a string, not %s'
                            % type(testsbase).__name__)

    def resetTestsBase(self):
        '''Reset directory relative to destdir where unit tests are placed.
        Default value for this variable is 'tests').'''
        self.table['testsbase'] = ''

    # Define modules methods.
    def addModule(self, module):
        '''Add the module to the modules list.'''
        if type(module) is str:
            if module not in self.table['modules']:
                self.table['modules'] += [module]
        else:  # if module has not str type
            raise TypeError('module must be a string, not %s'
                            % type(module).__name__)

    def removeModule(self, module):
        '''Remove the module from the modules list.'''
        if type(module) is str:
            if module in self.table['modules']:
                self.table['modules'].remove(module)
        else:  # if module has not str type
            raise TypeError('module must be a string, not %s'
                            % type(module).__name__)

    def getModules(self):
        '''Return the modules list.'''
        return list(self.table['modules'])

    def setModules(self, modules):
        '''Set the modules list.'''
        if type(modules) is list or type(modules) is tuple:
            old_modules = self.table['modules']
            self.table['modules'] = list()
            for module in modules:
                try:  # Try to add each module
                    self.addModule(module)
                except TypeError as error:
                    self.table['modules'] = old_modules
                    raise TypeError('each module must be a string')
                except GLError:
                    self.table['modules'] = old_modules
                    raise
        else:  # if type of modules is not list or tuple
            raise TypeError('modules must be a list or a tuple, not %s'
                            % type(modules).__name__)

    def resetModules(self):
        '''Reset the list of the modules.'''
        self.table['modules'] = list()

    # Define avoids methods.
    def addAvoid(self, module):
        '''Avoid including the given module. Useful if you have code that provides
        equivalent functionality.'''
        if type(module) is str:
            if module not in self.table['avoids']:
                self.table['avoids'].append(module)
        else:  # if module has not str type
            raise TypeError('avoid must be a string, not %s'
                            % type(module).__name__)

    def removeAvoid(self, module):
        '''Remove the given module from the list of avoided modules.'''
        if type(module) is str:
            if module in self.table['avoids']:
                self.table['avoids'].remove(module)
        else:  # if module has not str type
            raise TypeError('avoid must be a string, not %s'
                            % type(module).__name__)

    def getAvoids(self):
        '''Return the list of the avoided modules.'''
        return list(self.table['avoids'])

    def setAvoids(self, modules):
        '''Specify the modules which will be avoided.'''
        if type(modules) is list or type(modules) is tuple:
            old_avoids = self.table['avoids']
            self.table['avoids'] = list()
            for module in modules:
                try:  # Try to add each module
                    self.addAvoid(module)
                except TypeError as error:
                    self.table['avoids'] = old_avoids
                    raise TypeError('each module must be a string')
                except GLError:
                    self.table['avoids'] = old_avoids
                    raise
        else:  # if type of modules is not list or tuple
            raise TypeError('modules must be a list or a tuple, not %s'
                            % type(modules).__name__)

    def resetAvoids(self):
        '''Reset the list of the avoided modules.'''
        self.table['avoids'] = list()

    # Define files methods.
    def addFile(self, file):
        '''Add file to the list of files.'''
        if type(file) is str:
            if file not in self.table['files']:
                self.table['files'].append(file)
        else:  # if file has not str type
            raise TypeError('file must be a string, not %s'
                            % type(file).__name__)

    def removeFile(self, file):
        '''Remove the given file from the list of files.'''
        if type(file) is str:
            if file in self.table['files']:
                self.table['files'].remove(file)
        else:  # if file has not str type
            raise TypeError('file must be a string, not %s'
                            % type(file).__name__)

    def getFiles(self):
        '''Return the list of the fileed files.'''
        return list(self.table['files'])

    def setFiles(self, files):
        '''Specify the list of files.'''
        if type(files) is list or type(files) is tuple:
            old_files = self.table['files']
            self.table['files'] = list()
            for file in files:
                try:  # Try to add each file
                    self.addFile(file)
                except TypeError as error:
                    self.table['files'] = old_files
                    raise TypeError('each file must be a string')
                except GLError:
                    self.table['files'] = old_files
                    raise
        else:  # if type of files is not list or tuple
            raise TypeError('files must be a list or a tuple, not %s'
                            % type(files).__name__)

    def resetFiles(self):
        '''Reset the list of files.'''
        self.table['files'] = list()

    # Define incl_test_categories methods
    def checkInclTestCategory(self, category):
        '''Tests whether the given test category is included.'''
        if category in TESTS.values():
            return category in self.table['incl_test_categories']
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def enableInclTestCategory(self, category):
        '''Enable the given test category.'''
        if category in TESTS.values():
            if category not in self.table['incl_test_categories']:
                self.table['incl_test_categories'].append(category)
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def disableInclTestCategory(self, category):
        '''Disable the given test category.'''
        if category in TESTS.values():
            if category in self.table['incl_test_categories']:
                self.table['incl_test_categories'].remove(category)
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def setInclTestCategory(self, category, enable):
        '''Enable or disable the given test category.'''
        if enable:
            self.enableInclTestCategory(category)
        else:
            self.disableInclTestCategory(category)

    def getInclTestCategories(self):
        '''Return the test categories that should be included.
        To get the list of all test categories, use the TESTS variable.'''
        return list(self.table['incl_test_categories'])

    def setInclTestCategories(self, categories):
        '''Specify the test categories that should be included.'''
        if type(categories) is list or type(categories) is tuple:
            old_categories = self.table['incl_test_categories']
            self.table['incl_test_categories'] = list()
            for category in categories:
                try:  # Try to enable each category
                    self.enableInclTestCategory(category)
                except TypeError as error:
                    self.table['incl_test_categories'] = old_categories
                    raise TypeError('each category must be one of TESTS integers')
        else:  # if type of categories is not list or tuple
            raise TypeError('categories must be a list or a tuple, not %s'
                            % type(categories).__name__)

    def resetInclTestCategories(self):
        '''Reset test categories.'''
        self.table['incl_test_categories'] = list()

    # Define excl_test_categories methods
    def checkExclTestCategory(self, category):
        '''Tests whether the given test category is excluded.'''
        if category in TESTS.values():
            return category in self.table['excl_test_categories']
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def enableExclTestCategory(self, category):
        '''Enable the given test category.'''
        if category in TESTS.values():
            if category not in self.table['excl_test_categories']:
                self.table['excl_test_categories'].append(category)
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def disableExclTestCategory(self, category):
        '''Disable the given test category.'''
        if category in TESTS.values():
            if category in self.table['excl_test_categories']:
                self.table['excl_test_categories'].remove(category)
        else:  # if category is not in TESTS
            raise TypeError('unknown category: %s' % repr(category))

    def getExclTestCategories(self):
        '''Return the test categories that should be excluded.
        To get the list of all test categories, use the TESTS variable.'''
        return list(self.table['excl_test_categories'])

    def setExclTestCategories(self, categories):
        '''Specify the test categories that should be excluded.'''
        if type(categories) is list or type(categories) is tuple:
            old_categories = self.table['excl_test_categories']
            self.table['excl_test_categories'] = list()
            for category in categories:
                try:  # Try to enable each category
                    self.enableExclTestCategory(category)
                except TypeError as error:
                    self.table['excl_test_categories'] = old_categories
                    raise TypeError('each category must be one of TESTS integers')
        else:  # if type of categories is not list or tuple
            raise TypeError('categories must be a list or a tuple, not %s'
                            % type(categories).__name__)

    def resetExclTestCategories(self):
        '''Reset test categories.'''
        self.table['excl_test_categories'] = list()

    # Define libname methods.
    def getLibName(self):
        '''Return the library name.'''
        return self.table['libname']

    def setLibName(self, libname):
        '''Specify the library name.'''
        if type(libname) is str:
            if libname:
                self.table['libname'] = libname
        else:  # if type of libname is not str
            raise TypeError('libname must be a string, not %s'
                            % type(libname).__name__)

    def resetLibName(self):
        '''Reset the library name to 'libgnu'.'''
        self.table['libname'] = 'libgnu'

    # Define libtool methods.
    def checkLibtool(self):
        '''Check if user enabled libtool rules.'''
        return self.table['libtool']

    def setLibtool(self, value):
        '''Enable / disable libtool rules.'''
        if type(value) is bool:
            self.table['libtool'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetLibtool(self):
        '''Reset libtool rules.'''
        self.table['libtool'] = False

    # Define conddeps methods.
    def checkCondDeps(self):
        '''Check if user enabled conditional dependencies.'''
        return self.table['conddeps']

    def setCondDeps(self, value):
        '''Enable / disable conditional dependencies (may save configure time and object code).'''
        if type(value) is bool:
            self.table['conddeps'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetCondDeps(self):
        '''Reset conditional dependencies (may save configure time and object code).'''
        self.table['conddeps'] = False

    # Define lgpl methods.
    def getLGPL(self):
        '''Check for abort if modules aren't available under the LGPL.
        Default value is None, which means that lgpl is disabled.'''
        return self.table['lgpl']

    def setLGPL(self, lgpl):
        '''Abort if modules aren't available under the LGPL.
        Default value is None, which means that lgpl is disabled.'''
        if lgpl in [None, True, '2', '3orGPLv2', '3']:
            self.table['lgpl'] = lgpl
        else:
            raise TypeError('invalid LGPL version: %s' % repr(lgpl))

    def resetLGPL(self):
        '''Disable abort if modules aren't available under the LGPL.
        Default value is None, which means that lgpl is disabled.'''
        self.table['lgpl'] = None

    def getModuleIndicatorPrefix(self):
        '''Return module_indicator_prefix to use inside GLEmiter class.'''
        return self.getIncludeGuardPrefix()

    # Define macro_prefix and include_guard_prefix methods.
    # The include_guard_prefix is a replacement for ${gl_include_guard_prefix}.
    # It is determined from the macro_prefix.
    def getMacroPrefix(self):
        '''Return the prefix of the macros 'gl_EARLY' and 'gl_INIT'.
        Default macro_prefix is 'gl'.'''
        return self.table['macro_prefix']

    def getIncludeGuardPrefix(self):
        '''Return the replacement for ${gl_include_guard_prefix}.'''
        return self.table['include_guard_prefix']

    def setMacroPrefix(self, macro_prefix):
        '''Specify the prefix of the macros 'gl_EARLY' and 'gl_INIT'.
        Default macro_prefix is 'gl'.'''
        if type(macro_prefix) is str:
            if macro_prefix:
                self.table['macro_prefix'] = macro_prefix
        else:  # if type of macro_prefix is not str
            raise TypeError('macro_prefix must be a string, not %s'
                            % type(macro_prefix).__name__)
        if macro_prefix == 'gl':
            include_guard_prefix = 'GL'
        else:  # macro_prefix != 'gl'
            include_guard_prefix = 'GL_%s' % macro_prefix.upper()
        self.table['include_guard_prefix'] = include_guard_prefix

    def resetMacroPrefix(self):
        '''Reset the prefix of the macros 'gl_EARLY' and 'gl_INIT'.
        Default macro_prefix is 'gl'.'''
        self.table['macro_prefix'] = 'gl'
        self.table['include_guard_prefix'] = 'GL'

    # Define makefile_name methods.
    def getMakefileName(self):
        '''Return the name of makefile in automake syntax in the source-base and
        tests-base directories. Default is 'Makefile.am'.'''
        return self.table['makefile_name']

    def setMakefileName(self, makefile_name):
        '''Specify the name of makefile in automake syntax in the source-base and
        tests-base directories. Default is 'Makefile.am'.'''
        if type(makefile_name) is str:
            if makefile_name:
                self.table['makefile_name'] = makefile_name
        else:  # if type of makefile_name is not str
            raise TypeError('makefile_name must be a string, not %s'
                            % type(makefile_name).__name__)

    def resetMakefileName(self):
        '''Reset the name of makefile in automake syntax in the source-base and
        tests-base directories. Default is 'Makefile.am'.'''
        self.table['makefile_name'] = ''

    # Define podomain methods.
    def getPoDomain(self):
        '''Return the prefix of the i18n domain. Usually use the package name.
        A suffix '-gnulib' is appended.'''
        return self.table['podomain']

    def setPoDomain(self, podomain):
        '''Specify the prefix of the i18n domain. Usually use the package name.
        A suffix '-gnulib' is appended.'''
        if type(podomain) is str:
            if podomain:
                self.table['podomain'] = podomain
        else:  # if type of podomain is not str
            raise TypeError('podomain must be a string, not %s'
                            % type(podomain).__name__)

    def resetPoDomain(self):
        '''Reset the prefix of the i18n domain. Usually use the package name.
        A suffix '-gnulib' is appended.'''
        self.table['podomain'] = ''

    # Define witness_c_macro methods.
    def getWitnessCMacro(self):
        '''Return the C macro that is defined when the sources in this directory
        are compiled or used.'''
        return self.table['witness_c_macro']

    def setWitnessCMacro(self, witness_c_macro):
        '''Specify the C macro that is defined when the sources in this directory
        are compiled or used.'''
        if type(witness_c_macro) is str:
            if witness_c_macro:
                self.table['witness_c_macro'] = witness_c_macro
        else:  # if type of witness_c_macro is not str
            raise TypeError('witness_c_macro must be a string, not %s'
                            % type(witness_c_macro).__name__)

    def resetWitnessCMacro(self):
        '''Return the C macro that is defined when the sources in this directory
        are compiled or used.'''
        self.table['witness_c_macro'] = ''

    # Define vc_files methods.
    def checkVCFiles(self):
        '''Check if update of the version control files is enabled or disabled.'''
        return self.table['vc_files']

    def setVCFiles(self, value):
        '''Enable /disable update of the version control files.'''
        if type(value) is bool:
            self.table['vc_files'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetVCFiles(self):
        '''Reset update of the version control files and set it to None.'''
        self.table['vc_files'] = None

    # Define configure_ac methods.
    def getAutoconfFile(self):
        '''Return path of autoconf file relative to destdir.'''
        return self.table['configure_ac']

    def setAutoconfFile(self, configure_ac):
        '''Specify path of autoconf file relative to destdir.'''
        if type(configure_ac) is str:
            if configure_ac:
                self.table['configure_ac'] = \
                    relpath(self.table['destdir'], configure_ac)
        else:  # if type of configure_ac is not str
            raise TypeError('configure_ac must be a string, not %s'
                            % type(configure_ac).__name__)

    def resetAutoconfFile(self):
        '''Reset path of autoconf file relative to destdir.'''
        configure_ac = ''
        if isfile(joinpath(self.table['destdir'], 'configure.ac')):
            configure_ac = joinpath(self.table['destdir'], 'configure.ac')
        elif isfile(joinpath(self.table['destdir'], 'configure.in')):
            configure_ac = joinpath(self.table['destdir'], 'configure.in')
        self.table['configure_ac'] = configure_ac

    # Define ac_version methods.
    def getAutoconfVersion(self):
        '''Return preferred autoconf version. Default value is 2.59.'''
        return self.table['ac_version']

    def setAutoconfVersion(self, ac_version):
        '''Specify preferred autoconf version. Default value is 2.59.'''
        if type(ac_version) is float or type(ac_version) is int:
            self.table['ac_version'] = float(ac_version)
        else:  # if ac_version has not int or float type
            raise TypeError('ac_version must be an int or a float, not %s'
                            % type(ac_version).__name__)

    def resetAutoconfVersion(self):
        '''Specify preferred autoconf version. Default value is 2.59.'''
        self.table['ac_version'] = 2.59

    def checkCopyrights(self):
        '''Check if copyright notices in files should be replaced.'''
        return self.table['copyrights']

    # Define symbolic methods.
    def checkSymbolic(self):
        '''Check if pygnulib will make symbolic links instead of copying files.'''
        return self.table['symbolic']

    def setSymbolic(self, value):
        '''Enable / disable creation of the symbolic links instead of copying files.'''
        if type(value) is bool:
            self.table['symbolic'] = value
            self.table['copyrights'] = not value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetSymbolic(self):
        '''Reset creation of the symbolic links instead of copying files.'''
        self.table['symbolic'] = False
        self.table['copyrights'] = True

    # Define lsymbolic methods.
    def checkLSymbolic(self):
        '''Check if pygnulib will make symbolic links instead of copying files,
        only for files from the local override directories.'''
        return self.table['lsymbolic']

    def setLSymbolic(self, value):
        '''Enable / disable creation of symbolic links instead of copying files,
        only for files from the local override directories.'''
        if type(value) is bool:
            self.table['lsymbolic'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetLSymbolic(self):
        '''Reset creation of symbolic links instead of copying files, only for
        files from the local override directories.'''
        self.table['lsymbolic'] = False

    # Define verbosity methods.
    def getVerbosity(self):
        '''Get verbosity level.'''
        return self.table['verbosity']

    def decreaseVerbosity(self):
        '''Decrease verbosity level.'''
        if self.table['verbosity'] > MODES['verbose-min']:
            self.table['verbosity'] -= 1

    def increaseVerbosity(self):
        '''Increase verbosity level.'''
        if self.table['verbosity'] < MODES['verbose-max']:
            self.table['verbosity'] += 1

    def setVerbosity(self, verbose):
        '''Set verbosity level to verbose, where -2 <= verbose <= 2.
        If verbosity level is less than -2, verbosity level will be set to -2.
        If verbosity level is greater than 2, verbosity level will be set to 2.'''
        if type(verbose) is int:
            if MODES['verbose-min'] <= verbose <= MODES['verbose-max']:
                self.table['verbosity'] = verbose
            elif verbose < MODES['verbose-min']:
                self.table['verbosity'] = MODES['verbose-min']
            elif verbose > MODES['verbose-max']:
                self.table['verbosity'] = MODES['verbose-max']
        else:  # if type(verbose) is not int
            raise TypeError('verbosity must be an int, not %s'
                            % type(verbose).__name__)

    def resetVerbosity(self):
        '''Reset verbosity level.'''
        self.table['verbosity'] = 0

    # Define libtests methods.
    def checkLibtests(self):
        '''Return True if a testsbase/libtests.a is needed.'''
        return self.table['libtests']

    def setLibtests(self, value):
        '''Specifies whether testsbase/libtests.a is needed.'''
        if type(value) is bool:
            self.table['libtests'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetLibtests(self):
        '''Reset status of testsbase/libtests.a.'''
        self.table['libtests'] = False

    # Define single_configure methods.
    def checkSingleConfigure(self):
        '''Check whether single configure file should be generated.'''
        return self.table['single_configure']

    def setSingleConfigure(self, value):
        '''Enable / disable generation of the single configure file.'''
        if type(value) is bool:
            self.table['single_configure'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetSingleConfigure(self):
        '''Reset status of the single configure file generation.'''
        self.table['single_configure'] = False

    # Define dryrun methods.
    def checkDryRun(self):
        '''Check whether dryrun is enabled.'''
        return self.table['dryrun']

    def setDryRun(self, value):
        '''Enable / disable dryrun mode.'''
        if type(value) is bool:
            self.table['dryrun'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetDryRun(self):
        '''Reset status of dryrun mode.'''
        self.table['dryrun'] = False

    # Define errors methods.
    def checkErrors(self):
        '''Check if GLError will be raised in non-critical situations.'''
        return self.table['errors']

    def setErrors(self, value):
        '''Enable / disable raising GLError in non-critical situations.'''
        if type(value) is bool:
            self.table['errors'] = value
        else:  # if type(value) is not bool
            raise TypeError('value must be a bool, not %s'
                            % type(value).__name__)

    def resetErrors(self):
        '''Reset status of raising GLError in non-critical situations.'''
        self.table['errors'] = False