Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/, repoman/pym/repoman/modules/scan/
Date: Mon, 10 Jul 2017 17:52:38
Message-Id: 1499709019.3b4030e3e2f85bb92463dd89f9fa2f514a49b56a.dolsen@gentoo
1 commit: 3b4030e3e2f85bb92463dd89f9fa2f514a49b56a
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jul 10 17:39:04 2017 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Mon Jul 10 17:50:19 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3b4030e3
7
8 repoman: Create a new ModuleConfig class
9
10 This class will load the module configuration data from the target repo.
11 Move the Modules class handling code to this new class.
12 Update scanner.py to use the new ModuleConfig class for Modules class
13 calls.
14 Move the hard-coded loop lists to use the ModuleConfig instance
15 configure/dynamically determined lists.
16
17 TODO: add masters inheritance config stacking.
18
19 repoman/pym/repoman/modules/scan/module.py | 84 ++++++++++++++++++++++++++++++
20 repoman/pym/repoman/scanner.py | 83 ++++++++++++-----------------
21 2 files changed, 118 insertions(+), 49 deletions(-)
22
23 diff --git a/repoman/pym/repoman/modules/scan/module.py b/repoman/pym/repoman/modules/scan/module.py
24 new file mode 100644
25 index 000000000..f7f135f73
26 --- /dev/null
27 +++ b/repoman/pym/repoman/modules/scan/module.py
28 @@ -0,0 +1,84 @@
29 +
30 +'''
31 +moudules/scan/module.py
32 +Module loading and run list generator
33 +'''
34 +
35 +import logging
36 +import os
37 +import yaml
38 +
39 +from portage.module import InvalidModuleName, Modules
40 +from portage.util import stack_lists
41 +
42 +MODULES_PATH = os.path.dirname(__file__)
43 +# initial development debug info
44 +logging.debug("module path: %s", MODULES_PATH)
45 +
46 +
47 +class ModuleConfig(object):
48 + '''Holds the scan modules configuration information and
49 + creates the ordered list of modulles to run'''
50 +
51 + def __init__(self, configpaths):
52 + '''Module init
53 +
54 + @param configpaths: ordered list of filepaths to load
55 + '''
56 + self.configpaths = configpaths
57 +
58 + self.controller = Modules(path=MODULES_PATH, namepath="repoman.modules.scan")
59 + logging.debug("module_names: %s", self.controller.module_names)
60 +
61 + self._configs = None
62 + self.enabled = []
63 + self.pkgs_loop = []
64 + self.ebuilds_loop = []
65 + self.final_loop = []
66 + self.modules_forced = ['ebuild', 'mtime']
67 + self.load_configs()
68 + for loop in ['pkgs', 'ebuilds', 'final']:
69 + logging.debug("ModuleConfig; Processing loop %s", loop)
70 + setattr(self, '%s_loop' % loop, self._determine_list(loop))
71 +
72 +
73 + def load_configs(self, configpaths=None):
74 + '''load the config files in order'''
75 + if configpaths:
76 + self.configpaths = configpaths
77 + elif not self.configpaths:
78 + logging.error("ModuleConfig; Error: No repository.yml files defined")
79 + configs = []
80 + for path in self.configpaths:
81 + logging.debug("ModuleConfig; Processing: %s", path)
82 + if os.path.exists(path):
83 + try:
84 + with open(path, 'r') as inputfile:
85 + configs.append(yaml.safe_load(inputfile.read()))
86 + except IOError as error:
87 + logging,error("Failed to load file: %s", inputfile)
88 + logging.exception(error)
89 + logging.debug("ModuleConfig; completed : %s", path)
90 + logging.debug("ModuleConfig; new _configs: %s", configs)
91 + self._configs = configs
92 +
93 + def _determine_list(self, loop):
94 + '''Determine the ordered list from the config data and
95 + the moule_runsIn value in the module_spec
96 +
97 + @returns: list of modules
98 + '''
99 + lists = [c['modules'] for c in self._configs]
100 + stacked = self.modules_forced + stack_lists(lists)
101 + mlist = []
102 + try:
103 + for mod in stacked:
104 + logging.debug("ModuleConfig; checking loop %s, module: %s, in: %s",
105 + loop, mod, self.controller.get_spec(mod, 'module_runsIn'))
106 + if loop in self.controller.get_spec(mod, 'module_runsIn'):
107 + mlist.append(mod)
108 + except InvalidModuleName:
109 + logging.error("ModuleConfig; unkown module: %s, skipping", mod)
110 +
111 + logging.debug("ModuleConfig; mlist: %s", mlist)
112 + return mlist
113
114 diff --git a/repoman/pym/repoman/scanner.py b/repoman/pym/repoman/scanner.py
115 index e13d4f68b..ffce701be 100644
116 --- a/repoman/pym/repoman/scanner.py
117 +++ b/repoman/pym/repoman/scanner.py
118 @@ -15,20 +15,10 @@ from repoman.modules.commit import repochecks
119 from repoman.modules.commit import manifest
120 from repoman.profile import check_profiles, dev_profile_keywords, setup_profile
121 from repoman.repos import repo_metadata
122 +from repoman.modules.scan.module import ModuleConfig
123 from repoman.modules.scan.scan import scan
124 from repoman.modules.vcs.vcs import vcs_files_to_cps
125
126 -from portage.module import Modules
127 -
128 -MODULES_PATH = os.path.join(os.path.dirname(__file__), "modules", "scan")
129 -# initial development debug info
130 -logging.debug("module path: %s", MODULES_PATH)
131 -
132 -MODULE_CONTROLLER = Modules(path=MODULES_PATH, namepath="repoman.modules.scan")
133 -
134 -MODULE_NAMES = MODULE_CONTROLLER.module_names[:]
135 -# initial development debug info
136 -logging.debug("module_names: %s", MODULE_NAMES)
137
138 DATA_TYPES = {'dict': dict, 'Future': ExtendedFuture, 'list': list, 'set': set}
139
140 @@ -124,6 +114,12 @@ class Scanner(object):
141 if self.vcs_settings.vcs is None:
142 self.options.echangelog = 'n'
143
144 + # Initialize the ModuleConfig class here
145 + # TODO Add layout.conf masters repository.yml config to the list to load/stack
146 + self.moduleconfig = ModuleConfig([
147 + '/home/bdolbec/git/gentoo/metadata/repoman/repository.yml',
148 + ])
149 +
150 checks = {}
151 # The --echangelog option causes automatic ChangeLog generation,
152 # which invalidates changelog.ebuildadded and changelog.missing
153 @@ -212,7 +208,7 @@ class Scanner(object):
154 @returns: dictionary
155 '''
156 kwargs = {}
157 - for key in MODULE_CONTROLLER.modules[mod]['mod_kwargs']:
158 + for key in self.moduleconfig.controller.modules[mod]['mod_kwargs']:
159 kwargs[key] = self.kwargs[key]
160 return kwargs
161
162 @@ -224,7 +220,7 @@ class Scanner(object):
163 @param dynamic_data: dictionary structure
164 @returns: dictionary
165 '''
166 - func_kwargs = MODULE_CONTROLLER.modules[mod]['func_kwargs']
167 + func_kwargs = self.moduleconfig.controller.modules[mod]['func_kwargs']
168 # determine new keys
169 required = set(list(func_kwargs))
170 exist = set(list(dynamic_data))
171 @@ -324,19 +320,16 @@ class Scanner(object):
172 'validity_future',
173 ]
174 # need to set it up for ==> self.modules or some other ordered list
175 - for mod in [('manifests', 'Manifests'), ('ebuild', 'Ebuild'),
176 - ('keywords', 'KeywordChecks'), ('files', 'FileChecks'),
177 - ('fetches', 'FetchChecks'),
178 - ('pkgmetadata', 'PkgMetadata'),
179 - ]:
180 - mod_class = MODULE_CONTROLLER.get_class(mod[0])
181 + logging.debug("***** starting pkgs_loop: %s", self.moduleconfig.pkgs_loop)
182 + for mod in self.moduleconfig.pkgs_loop:
183 + mod_class = self.moduleconfig.controller.get_class(mod)
184 logging.debug("Initializing class name: %s", mod_class.__name__)
185 - self.modules[mod_class.__name__] = mod_class(**self.set_kwargs(mod[0]))
186 - logging.debug("scan_pkgs; module: %s", mod[1])
187 - do_it, functions = self.modules[mod[1]].runInPkgs
188 + self.modules[mod_class.__name__] = mod_class(**self.set_kwargs(mod))
189 + logging.debug("scan_pkgs; module: %s", mod_class.__name__)
190 + do_it, functions = self.modules[mod_class.__name__].runInPkgs
191 if do_it:
192 for func in functions:
193 - _continue = func(**self.set_func_kwargs(mod[0], dynamic_data))
194 + _continue = func(**self.set_func_kwargs(mod, dynamic_data))
195 if _continue:
196 # If we can't access all the metadata then it's totally unsafe to
197 # commit since there's no way to generate a correct Manifest.
198 @@ -373,28 +366,19 @@ class Scanner(object):
199
200 # initialize per ebuild plugin checks here
201 # need to set it up for ==> self.modules_list or some other ordered list
202 - for mod in [('ebuild', 'Ebuild'), ('live', 'LiveEclassChecks'),
203 - ('eapi', 'EAPIChecks'), ('ebuild_metadata', 'EbuildMetadata'),
204 - ('fetches', 'FetchChecks'),
205 - ('description', 'DescriptionChecks'),
206 - ('keywords', 'KeywordChecks'),
207 - ('pkgmetadata', 'PkgMetadata'), ('ruby', 'RubyEclassChecks'),
208 - ('restrict', 'RestrictChecks'),
209 - ('mtime', 'MtimeChecks'), ('multicheck', 'MultiCheck'),
210 - # Options.is_forced() is used to bypass further checks
211 - ('options', 'Options'), ('profile', 'ProfileDependsChecks'),
212 - ]:
213 - if mod[0] and mod[1] not in self.modules:
214 - mod_class = MODULE_CONTROLLER.get_class(mod[0])
215 - logging.debug("Initializing class name: %s", mod_class.__name__)
216 - self.modules[mod[1]] = mod_class(**self.set_kwargs(mod[0]))
217 - logging.debug("scan_ebuilds: module: %s", mod[1])
218 - do_it, functions = self.modules[mod[1]].runInEbuilds
219 + for mod in self.moduleconfig.ebuilds_loop:
220 + if mod:
221 + mod_class = self.moduleconfig.controller.get_class(mod)
222 + if mod_class.__name__ not in self.modules:
223 + logging.debug("Initializing class name: %s", mod_class.__name__)
224 + self.modules[mod_class.__name__] = mod_class(**self.set_kwargs(mod))
225 + logging.debug("scan_ebuilds: module: %s", mod_class.__name__)
226 + do_it, functions = self.modules[mod_class.__name__].runInEbuilds
227 logging.debug("do_it: %s, functions: %s", do_it, [x.__name__ for x in functions])
228 if do_it:
229 for func in functions:
230 logging.debug("\tRunning function: %s", func)
231 - _continue = func(**self.set_func_kwargs(mod[0], dynamic_data))
232 + _continue = func(**self.set_func_kwargs(mod, dynamic_data))
233 if _continue:
234 # If we can't access all the metadata then it's totally unsafe to
235 # commit since there's no way to generate a correct Manifest.
236 @@ -414,18 +398,19 @@ class Scanner(object):
237 # initialize per pkg plugin final checks here
238 # need to set it up for ==> self.modules_list or some other ordered list
239 xpkg_complete = False
240 - for mod in [('pkgmetadata', 'PkgMetadata'), ('keywords', 'KeywordChecks')]:
241 - if mod[0] and mod[1] not in self.modules:
242 - mod_class = MODULE_CONTROLLER.get_class(mod[0])
243 - logging.debug("Initializing class name: %s", mod_class.__name__)
244 - self.modules[mod[1]] = mod_class(**self.set_kwargs(mod[0]))
245 - logging.debug("scan_ebuilds final checks: module: %s", mod[1])
246 - do_it, functions = self.modules[mod[1]].runInFinal
247 + for mod in self.moduleconfig.final_loop:
248 + if mod:
249 + mod_class = self.moduleconfig.controller.get_class(mod)
250 + if mod_class.__name__ not in self.modules:
251 + logging.debug("Initializing class name: %s", mod_class.__name__)
252 + self.modules[mod_class.__name__] = mod_class(**self.set_kwargs(mod))
253 + logging.debug("scan_ebuilds final checks: module: %s", mod_class.__name__)
254 + do_it, functions = self.modules[mod_class.__name__].runInFinal
255 logging.debug("do_it: %s, functions: %s", do_it, [x.__name__ for x in functions])
256 if do_it:
257 for func in functions:
258 logging.debug("\tRunning function: %s", func)
259 - _continue = func(**self.set_func_kwargs(mod[0], dynamic_data))
260 + _continue = func(**self.set_func_kwargs(mod, dynamic_data))
261 if _continue:
262 xpkg_complete = True
263 # logging.debug("\t>>> Continuing")