4 #===============================================================================
5 # Define global imports
6 #===============================================================================
12 import subprocess
as sp
13 from . import constants
14 from .GLError
import GLError
15 from .GLConfig
import GLConfig
16 from .GLFileSystem
import GLFileSystem
19 #===============================================================================
20 # Define module information
21 #===============================================================================
22 __author__
= constants
.__author
__
23 __license__
= constants
.__license
__
24 __copyright__
= constants
.__copyright
__
27 #===============================================================================
28 # Define global constants
29 #===============================================================================
30 PYTHON3
= constants
.PYTHON3
35 UTILS
= constants
.UTILS
36 MODES
= constants
.MODES
37 TESTS
= constants
.TESTS
38 compiler
= constants
.compiler
39 joinpath
= constants
.joinpath
40 cleaner
= constants
.cleaner
41 string
= constants
.string
44 isfile
= os
.path
.isfile
45 normpath
= os
.path
.normpath
46 relpath
= os
.path
.relpath
47 filter_filelist
= constants
.filter_filelist
50 #===============================================================================
51 # Define GLMakefileTable class
52 #===============================================================================
53 class GLMakefileTable(object):
54 '''This class is used to edit Makefile and store edits as table.
55 When user creates Makefile, he may need to use this class.'''
57 def __init__(self
, config
):
58 '''GLMakefileTable.__init__(config) -> GLMakefileTable
60 Create GLMakefileTable instance.'''
61 if type(config
) is not GLConfig
:
62 raise(TypeError('config must be a GLConfig, not %s' %
63 type(config
).__name
__))
67 def __getitem__(self
, y
):
68 '''x.__getitem__(y) = x[y]'''
69 if type(y
) is not int:
70 raise(TypeError('indices must be integers, not %s' %
72 result
= self
.table
[y
]
75 def editor(self
, dir, var
, val
):
76 '''GLMakefileTable.editor(dir, var, val)
78 This method is used to remember that ${dir}Makefile.am needs to be edited
79 to that ${var} mentions ${val}.'''
80 if type(dir) is bytes
or type(dir) is string
:
81 if type(dir) is bytes
:
82 dir = dir.decode(ENCS
['default'])
83 else: # if dir has not bytes or string type
85 'dir must be a string, not %s' % (type(dir).__name
__)))
86 if type(var
) is bytes
or type(var
) is string
:
87 if type(var
) is bytes
:
88 var
= var
.decode(ENCS
['default'])
89 else: # if var has not bytes or string type
91 'var must be a string, not %s' % (type(var
).__name
__)))
92 if type(val
) is bytes
or type(val
) is string
:
93 if type(val
) is bytes
:
94 val
= val
.decode(ENCS
['default'])
95 else: # if val has not bytes or string type
97 'val must be a string, not %s' % (type(val
).__name
__)))
98 dictionary
= {'dir': dir, 'var': var
, 'val': val
}
99 self
.table
+= [dictionary
]
102 '''GLMakefileTable.parent()
104 Add a special row to Makefile.am table with the first parent directory
105 which contains or will contain Makefile.am file.
106 GLConfig: sourcebase, m4base, testsbase, testflags, makefile.'''
107 m4base
= self
.config
['m4base']
108 sourcebase
= self
.config
['sourcebase']
109 testsbase
= self
.config
['testsbase']
110 makefile
= self
.config
['makefile']
111 inctests
= self
.config
.checkTestFlag(TESTS
['tests'])
112 dir1
= string('%s%s' % (m4base
, os
.path
.sep
))
113 mfd
= string('Makefile.am')
115 mfx
= string('Makefile.am')
120 (joinpath(self
.config
['destdir'], dir1
, mfd
) or
121 joinpath(dir1
, mfd
) == joinpath(sourcebase
, mfx
) or
122 (inctests
and joinpath(dir1
, mfd
) == joinpath(testsbase
, mfx
))):
123 dir2
= joinpath(os
.path
.basename(dir1
), dir2
)
124 dir1
= os
.path
.dirname(dir1
)
125 self
.editor(dir1
, 'EXTRA_DIST', joinpath(dir2
, 'gnulib-cache.m4'))
128 '''GLMakefileTable.count() -> int
130 Count number of edits which were applied.'''
131 return(len(self
.table
))