Gentoo Archives: gentoo-commits

From: Magnus Granberg <zorry@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] dev/zorry:master commit in: gobs/bin/, gobs/pym/
Date: Mon, 26 Sep 2011 23:25:40
Message-Id: 93a89cfd8ee53292632f081909cc0440f5b6052b.zorry@gentoo
1 commit: 93a89cfd8ee53292632f081909cc0440f5b6052b
2 Author: Magnus Granberg <zorry <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 26 23:23:49 2011 +0000
4 Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 26 23:23:49 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=dev/zorry.git;a=commit;h=93a89cfd
7
8 Add copy of action_build post_emerge emerge_main and fix some code
9
10 ---
11 gobs/bin/gobs_buildquerys | 12 +-
12 gobs/pym/build_queru.py | 701 ++++++++++++++++++++++++++++++++++++++++-----
13 gobs/pym/check_setup.py | 21 +-
14 gobs/pym/flags.py | 37 ---
15 gobs/pym/pgsql.py | 39 ++--
16 5 files changed, 664 insertions(+), 146 deletions(-)
17
18 diff --git a/gobs/bin/gobs_buildquerys b/gobs/bin/gobs_buildquerys
19 index 7b8121b..fc2506d 100755
20 --- a/gobs/bin/gobs_buildquerys
21 +++ b/gobs/bin/gobs_buildquerys
22 @@ -17,26 +17,24 @@ import portage
23 import sys
24 import os
25
26 -def main_loop(CM, config_profile):
27 +def main_loop(config_profile):
28 repeat = True
29 #get a connection from the pool
30 - conn=CM.getConnection()
31 init_queru = queruaction(config_profile)
32 - fail_querue_dict = {}
33 while repeat:
34 - if check_configure_guest(conn, config_profile) is not True:
35 + #FIXME do a git reop check
36 + if check_configure_guest( config_profile) is not True:
37 # time.sleep(60)
38 continue # retunr to the start of the function
39 else:
40 - fail_querue_list = init_queru.procces_qureru(fail_querue_dict)
41 + init_queru.procces_qureru()
42 sys.exit()
43 - CM.putConnection(conn)
44
45 def main():
46 # Main
47 config_profile = gobs_settings_dict['gobs_config']
48 #we provide the main_loop with the ConnectionManager so we can hand out connections from within the loop
49 - main_loop(CM, config_profile)
50 + main_loop(config_profile)
51 connectionManager.closeAllConnections()
52
53 if __name__ == "__main__":
54
55 diff --git a/gobs/pym/build_queru.py b/gobs/pym/build_queru.py
56 index 0e481da..7f5e3c1 100644
57 --- a/gobs/pym/build_queru.py
58 +++ b/gobs/pym/build_queru.py
59 @@ -12,10 +12,43 @@ if CM.getName()=='pgsql':
60
61 import portage
62 import os
63 +import re
64 +import sys
65 +import signal
66 from gobs.manifest import gobs_manifest
67 from gobs.depclean import main_depclean
68 from gobs.flags import gobs_use_flags
69 -from _emerge.main import emerge_main
70 +from portage import _encodings
71 +from portage import _unicode_decode
72 +from portage.versions import cpv_getkey
73 +import portage.xpak, errno, re, time
74 +from _emerge.main import parse_opts, profile_check, apply_priorities, repo_name_duplicate_check, \
75 + config_protect_check, check_procfs, ensure_required_sets, expand_set_arguments, \
76 + validate_ebuild_environment, chk_updated_info_files, display_preserved_libs
77 +from _emerge.actions import action_config, action_sync, action_metadata, \
78 + action_regen, action_search, action_uninstall, \
79 + adjust_configs, chk_updated_cfg_files, display_missing_pkg_set, \
80 + display_news_notification, getportageversion, load_emerge_config
81 +from portage.util import cmp_sort_key, writemsg, \
82 + writemsg_level, writemsg_stdout, shlex_split
83 +from _emerge.sync.old_tree_timestamp import old_tree_timestamp_warn
84 +from _emerge.create_depgraph_params import create_depgraph_params
85 +from _emerge.depgraph import backtrack_depgraph, depgraph, resume_depgraph
86 +from _emerge.DepPrioritySatisfiedRange import DepPrioritySatisfiedRange
87 +from _emerge.Scheduler import Scheduler
88 +from _emerge.clear_caches import clear_caches
89 +from _emerge.unmerge import unmerge
90 +from _emerge.emergelog import emergelog
91 +from _emerge._flush_elog_mod_echo import _flush_elog_mod_echo
92 +from portage._global_updates import _global_updates
93 +from portage._sets import SETPREFIX
94 +from portage.const import PORTAGE_PACKAGE_ATOM, USER_CONFIG_PATH
95 +from _emerge.is_valid_package_atom import is_valid_package_atom
96 +from _emerge.stdout_spinner import stdout_spinner
97 +from portage.output import blue, bold, colorize, create_color_func, darkgreen, \
98 + red, yellow, colorize, xtermTitle, xtermTitleReset
99 +good = create_color_func("GOOD")
100 +bad = create_color_func("BAD")
101
102 class queruaction(object):
103
104 @@ -24,40 +57,561 @@ class queruaction(object):
105 self._config_profile = config_profile
106 self._myportdb = portage.portdb
107
108 - def log_fail_queru(self, build_dict, fail_querue_dict):
109 - fail_times = 0
110 - if fail_querue_dict == {}:
111 - attDict = {}
112 - attDict[build_dict['type_fail']] = 1
113 - attDict['build_info'] = build_dict
114 - fail_querue_dict[build_dict['querue_id']] = attDict
115 - return fail_querue_dict
116 + def log_fail_queru(self, build_dict, settings):
117 + conn=CM.getConnection()
118 + print('build_dict', build_dict)
119 + fail_querue_dict = get_fail_querue_dict(conn, build_dict)
120 + print('fail_querue_dict', fail_querue_dict)
121 + if fail_querue_dict is None:
122 + fail_querue_dict = {}
123 + fail_querue_dict['querue_id'] = build_dict['queue_id']
124 + fail_querue_dict['fail_type'] = build_dict['type_fail']
125 + fail_querue_dict['fail_times'] = 1
126 + print('fail_querue_dict', fail_querue_dict)
127 + add_fail_querue_dict(conn, fail_querue_dict)
128 else:
129 - # FIXME:If is 5 remove fail_querue_dict[build_dict['querue_id'] from
130 - # fail_querue_dict and add log to db.
131 - if not fail_querue_dict[build_dict['querue_id']] is None:
132 - if fail_querue_dict[build_dict['querue_id']][build_dict['type_fail']] is None:
133 - fail_querue_dict[build_dict['querue_id']][build_dict['type_fail']] = 1
134 - return fail_querue_dict
135 + if fail_querue_dict['fail_times'][0] < 6:
136 + fail_querue_dict['fail_times'] = fail_querue_dict['fail_times'][0] + 1
137 + fail_querue_dict['querue_id'] = build_dict['queue_id']
138 + fail_querue_dict['fail_type'] = build_dict['type_fail']
139 + update_fail_times(conn, fail_querue_dict)
140 + return
141 + else:
142 + build_log_dict = {}
143 + error_log_list = []
144 + qa_error_list = []
145 + repoman_error_list = []
146 + sum_build_log_list = []
147 + sum_build_log_list.append("fail")
148 + error_log_list.append(build_dict['type_fail'])
149 + build_log_dict['repoman_error_list'] = repoman_error_list
150 + build_log_dict['qa_error_list'] = qa_error_list
151 + build_log_dict['summary_error_list'] = sum_build_log_list
152 + if build_dict['type_fail'] == 'merge fail':
153 + error_log_list = []
154 + for k, v in build_dict['failed_merge'].iteritems():
155 + error_log_list.append(v['fail_msg'])
156 + build_log_dict['error_log_list'] = error_log_list
157 + build_error = ""
158 + if error_log_list != []:
159 + for log_line in error_log_list:
160 + build_error = build_error + log_line
161 + summary_error = ""
162 + if sum_build_log_list != []:
163 + for sum_log_line in sum_build_log_list:
164 + summary_error = summary_error + " " + sum_log_line
165 + if settings.get("PORTAGE_LOG_FILE") is not None:
166 + build_log_dict['logfilename'] = re.sub("\/var\/log\/portage\/", "", settings.get("PORTAGE_LOG_FILE"))
167 else:
168 - fail_times = fail_querue_dict[build_dict['querue_id']][build_dict['type_fail']]
169 - fail_times = fail_times + 1
170 - if not fail_times is 5:
171 - fail_querue_dict[build_dict['querue_id']][build_dict['type_fail']] = fail_times
172 - return fail_querue_dict
173 - else:
174 - # FIXME:If is 5 remove fail_querue_dict[build_dict['querue_id']] from
175 - # fail_querue_dict and add log to db.
176 - return fail_querue_dict
177 + build_log_dict['logfilename'] = ""
178 + move_queru_buildlog(conn, build_dict['queue_id'], build_error, summary_error, build_log_dict)
179 +
180 + def action_build(self, settings, trees, mtimedb, myopts, myaction, myfiles, spinner, build_dict):
181 +
182 + if '--usepkgonly' not in myopts:
183 + old_tree_timestamp_warn(settings['PORTDIR'], settings)
184 +
185 + # It's best for config updates in /etc/portage to be processed
186 + # before we get here, so warn if they're not (bug #267103).
187 + chk_updated_cfg_files(settings['EROOT'], ['/etc/portage'])
188 +
189 + resume = False
190 +
191 + ldpath_mtimes = mtimedb["ldpath"]
192 + favorites=[]
193 + buildpkgonly = "--buildpkgonly" in myopts
194 + pretend = "--pretend" in myopts
195 + fetchonly = "--fetchonly" in myopts or "--fetch-all-uri" in myopts
196 + ask = "--ask" in myopts
197 + enter_invalid = '--ask-enter-invalid' in myopts
198 + nodeps = "--nodeps" in myopts
199 + oneshot = "--oneshot" in myopts or "--onlydeps" in myopts
200 + tree = "--tree" in myopts
201 + if nodeps and tree:
202 + tree = False
203 + del myopts["--tree"]
204 + portage.writemsg(colorize("WARN", " * ") + \
205 + "--tree is broken with --nodeps. Disabling...\n")
206 + debug = "--debug" in myopts
207 + verbose = "--verbose" in myopts
208 + quiet = "--quiet" in myopts
209 +
210 + myparams = create_depgraph_params(myopts, myaction)
211 + try:
212 + success, mydepgraph, favorites = backtrack_depgraph(
213 + settings, trees, myopts, myparams, myaction, myfiles, spinner)
214 + except portage.exception.PackageSetNotFound as e:
215 + root_config = trees[settings["ROOT"]]["root_config"]
216 + display_missing_pkg_set(root_config, e.value)
217 + build_dict['type_fail'] = "depgraph fail"
218 + build_dict['check_fail'] = True
219 + use_changes = None
220 + if mydepgraph._dynamic_config._needed_use_config_changes:
221 + use_changes = {}
222 + for pkg, needed_use_config_changes in mydepgraph._dynamic_config._needed_use_config_changes.items():
223 + new_use, changes = needed_use_config_changes
224 + use_changes[pkg.cpv] = changes
225 + iteritems_packages = {}
226 + for k, v in use_changes.iteritems():
227 + k_package = portage.versions.cpv_getkey(k)
228 + iteritems_packages[ k_package ] = v
229 + print('iteritems_packages', iteritems_packages)
230 + build_cpv_dict = iteritems_packages
231 + if use_changes is not None:
232 + for k, v in build_cpv_dict.iteritems():
233 + build_use_flags_list = []
234 + for x, y in v.iteritems():
235 + if y is True:
236 + build_use_flags_list.append(x)
237 + if y is False:
238 + build_use_flags_list.append("-" + x)
239 + print(k, build_use_flags_list)
240 + if not build_use_flags_list == []:
241 + build_use_flags = ""
242 + for flags in build_use_flags_list:
243 + build_use_flags = build_use_flags + flags + ' '
244 + filetext = k + ' ' + build_use_flags
245 + print('filetext', filetext)
246 + with open("/etc/portage/package.use/gobs.use", "a") as f:
247 + f.write(filetext)
248 + f.write('\n')
249 +
250 + settings, trees, mtimedb = load_emerge_config()
251 + myparams = create_depgraph_params(myopts, myaction)
252 + try:
253 + success, mydepgraph, favorites = backtrack_depgraph(
254 + settings, trees, myopts, myparams, myaction, myfiles, spinner)
255 + except portage.exception.PackageSetNotFound as e:
256 + root_config = trees[settings["ROOT"]]["root_config"]
257 + display_missing_pkg_set(root_config, e.value)
258 + build_dict['type_fail'] = "depgraph fail"
259 + build_dict['check_fail'] = True
260 + if not success:
261 + mydepgraph.display_problems()
262 + build_dict['type_fail'] = "depgraph fail"
263 + build_dict['check_fail'] = True
264 +
265 + if build_dict['check_fail'] is True:
266 + self.log_fail_queru(build_dict, settings)
267 + return 1, settings, trees, mtimedb
268 +
269 + if "--buildpkgonly" in myopts:
270 + graph_copy = mydepgraph._dynamic_config.digraph.copy()
271 + removed_nodes = set()
272 + for node in graph_copy:
273 + if not isinstance(node, Package) or \
274 + node.operation == "nomerge":
275 + removed_nodes.add(node)
276 + graph_copy.difference_update(removed_nodes)
277 + if not graph_copy.hasallzeros(ignore_priority = \
278 + DepPrioritySatisfiedRange.ignore_medium):
279 + print("\n!!! --buildpkgonly requires all dependencies to be merged.")
280 + print("!!! Cannot merge requested packages. Merge deps and try again.\n")
281 + return 1, settings, trees, mtimedb
282 +
283 + mydepgraph.saveNomergeFavorites()
284 +
285 + mergetask = Scheduler(settings, trees, mtimedb, myopts,
286 + spinner, favorites=favorites,
287 + graph_config=mydepgraph.schedulerGraph())
288 +
289 + del mydepgraph
290 + clear_caches(trees)
291 +
292 + retval = mergetask.merge()
293 + print('retval', retval)
294 + if retval:
295 + build_dict['type_fail'] = 'merge fail'
296 + build_dict['check_fail'] = True
297 + attict = {}
298 + failed_pkgs_dict = {}
299 + for x in mergetask._failed_pkgs_all:
300 + attict['fail_msg'] = str(x.pkg)[0] + ' ' + str(x.pkg)[1] + ' ' + re.sub("\/var\/log\/portage\/", "", mergetask._locate_failure_log(x))
301 + failed_pkgs_dict[str(x.pkg.cpv)] = attict
302 + build_dict['failed_merge'] = failed_pkgs_dict
303 + self.log_fail_queru(build_dict, settings)
304 + if retval == os.EX_OK and not (buildpkgonly or fetchonly or pretend):
305 + if "yes" == settings.get("AUTOCLEAN"):
306 + portage.writemsg_stdout(">>> Auto-cleaning packages...\n")
307 + unmerge(trees[settings["ROOT"]]["root_config"],
308 + myopts, "clean", [],
309 + ldpath_mtimes, autoclean=1)
310 else:
311 - attDict = {}
312 - attDict[build_dict['type_fail']] = 1
313 - attDict['build_info'] = build_dict
314 - fail_querue_dict[build_dict['querue_id']] = attDict
315 - return fail_querue_dict
316 + portage.writemsg_stdout(colorize("WARN", "WARNING:")
317 + + " AUTOCLEAN is disabled. This can cause serious"
318 + + " problems due to overlapping packages.\n")
319 +
320 + return retval, settings, trees, mtimedb
321 +
322 + def post_emerge(self, myaction, myopts, myfiles, target_root, trees, mtimedb, retval):
323 +
324 + root_config = trees[target_root]["root_config"]
325 + vardbapi = trees[target_root]["vartree"].dbapi
326 + settings = vardbapi.settings
327 + info_mtimes = mtimedb["info"]
328 +
329 + # Load the most current variables from ${ROOT}/etc/profile.env
330 + settings.unlock()
331 + settings.reload()
332 + settings.regenerate()
333 + settings.lock()
334 +
335 + config_protect = shlex_split(settings.get("CONFIG_PROTECT", ""))
336 + infodirs = settings.get("INFOPATH","").split(":") + \
337 + settings.get("INFODIR","").split(":")
338 +
339 + os.chdir("/")
340 +
341 + if retval == os.EX_OK:
342 + exit_msg = " *** exiting successfully."
343 + else:
344 + exit_msg = " *** exiting unsuccessfully with status '%s'." % retval
345 + emergelog("notitles" not in settings.features, exit_msg)
346 +
347 + _flush_elog_mod_echo()
348 +
349 + if not vardbapi._pkgs_changed:
350 + display_news_notification(root_config, myopts)
351 + # If vdb state has not changed then there's nothing else to do.
352 + return
353 +
354 + vdb_path = os.path.join(root_config.settings['EROOT'], portage.VDB_PATH)
355 + portage.util.ensure_dirs(vdb_path)
356 + vdb_lock = None
357 + if os.access(vdb_path, os.W_OK) and not "--pretend" in myopts:
358 + vardbapi.lock()
359 + vdb_lock = True
360 +
361 + if vdb_lock:
362 + try:
363 + if "noinfo" not in settings.features:
364 + chk_updated_info_files(target_root,
365 + infodirs, info_mtimes, retval)
366 + mtimedb.commit()
367 + finally:
368 + if vdb_lock:
369 + vardbapi.unlock()
370 +
371 + chk_updated_cfg_files(settings['EROOT'], config_protect)
372 +
373 + display_news_notification(root_config, myopts)
374 + if retval in (None, os.EX_OK) or (not "--pretend" in myopts):
375 + display_preserved_libs(vardbapi, myopts)
376 +
377 + postemerge = os.path.join(settings["PORTAGE_CONFIGROOT"],
378 + portage.USER_CONFIG_PATH, "bin", "post_emerge")
379 + if os.access(postemerge, os.X_OK):
380 + hook_retval = portage.process.spawn(
381 + [postemerge], env=settings.environ())
382 + if hook_retval != os.EX_OK:
383 + writemsg_level(
384 + " %s spawn failed of %s\n" % (bad("*"), postemerge,),
385 + level=logging.ERROR, noiselevel=-1)
386 +
387 + if "--quiet" not in myopts and \
388 + myaction is None and "@world" in myfiles:
389 + show_depclean_suggestion()
390 +
391 + return
392 +
393 + def emerge_main(self, args, build_dict):
394 +
395 + portage._disable_legacy_globals()
396 + portage.dep._internal_warnings = True
397 + # Disable color until we're sure that it should be enabled (after
398 + # EMERGE_DEFAULT_OPTS has been parsed).
399 + portage.output.havecolor = 0
400 + # This first pass is just for options that need to be known as early as
401 + # possible, such as --config-root. They will be parsed again later,
402 + # together with EMERGE_DEFAULT_OPTS (which may vary depending on the
403 + # the value of --config-root).
404 + myaction, myopts, myfiles = parse_opts(args, silent=True)
405 + if "--debug" in myopts:
406 + os.environ["PORTAGE_DEBUG"] = "1"
407 + if "--config-root" in myopts:
408 + os.environ["PORTAGE_CONFIGROOT"] = myopts["--config-root"]
409 + if "--root" in myopts:
410 + os.environ["ROOT"] = myopts["--root"]
411 + if "--accept-properties" in myopts:
412 + os.environ["ACCEPT_PROPERTIES"] = myopts["--accept-properties"]
413 +
414 + # Portage needs to ensure a sane umask for the files it creates.
415 + os.umask(0o22)
416 + settings, trees, mtimedb = load_emerge_config()
417 + portdb = trees[settings["ROOT"]]["porttree"].dbapi
418 + rval = profile_check(trees, myaction)
419 + if rval != os.EX_OK:
420 + return rval
421 +
422 + tmpcmdline = []
423 + if "--ignore-default-opts" not in myopts:
424 + tmpcmdline.extend(settings["EMERGE_DEFAULT_OPTS"].split())
425 + tmpcmdline.extend(args)
426 + myaction, myopts, myfiles = parse_opts(tmpcmdline)
427 +
428 + if myaction not in ('help', 'info', 'version') and \
429 + myopts.get('--package-moves') != 'n' and \
430 + _global_updates(trees, mtimedb["updates"], quiet=("--quiet" in myopts)):
431 + mtimedb.commit()
432 + # Reload the whole config from scratch.
433 + settings, trees, mtimedb = load_emerge_config(trees=trees)
434 + portdb = trees[settings["ROOT"]]["porttree"].dbapi
435 +
436 + xterm_titles = "notitles" not in settings.features
437 + if xterm_titles:
438 + xtermTitle("emerge")
439 +
440 + adjust_configs(myopts, trees)
441 + apply_priorities(settings)
442 +
443 + spinner = stdout_spinner()
444 + if "candy" in settings.features:
445 + spinner.update = spinner.update_scroll
446 +
447 + if "--quiet" not in myopts:
448 + portage.deprecated_profile_check(settings=settings)
449 + if portage.const._ENABLE_REPO_NAME_WARN:
450 + # Bug #248603 - Disable warnings about missing
451 + # repo_name entries for stable branch.
452 + repo_name_check(trees)
453 + repo_name_duplicate_check(trees)
454 + config_protect_check(trees)
455 + check_procfs()
456 +
457 + if "getbinpkg" in settings.features:
458 + myopts["--getbinpkg"] = True
459 +
460 + if "--getbinpkgonly" in myopts:
461 + myopts["--getbinpkg"] = True
462 +
463 + if "--getbinpkgonly" in myopts:
464 + myopts["--usepkgonly"] = True
465 +
466 + if "--getbinpkg" in myopts:
467 + myopts["--usepkg"] = True
468 +
469 + if "--usepkgonly" in myopts:
470 + myopts["--usepkg"] = True
471 +
472 + if "buildpkg" in settings.features or "--buildpkgonly" in myopts:
473 + myopts["--buildpkg"] = True
474 +
475 + if "--buildpkgonly" in myopts:
476 + # --buildpkgonly will not merge anything, so
477 + # it cancels all binary package options.
478 + for opt in ("--getbinpkg", "--getbinpkgonly",
479 + "--usepkg", "--usepkgonly"):
480 + myopts.pop(opt, None)
481 +
482 + for mytrees in trees.values():
483 + mydb = mytrees["porttree"].dbapi
484 + # Freeze the portdbapi for performance (memoize all xmatch results).
485 + mydb.freeze()
486 +
487 + if myaction in ('search', None) and \
488 + "--usepkg" in myopts:
489 + # Populate the bintree with current --getbinpkg setting.
490 + # This needs to happen before expand_set_arguments(), in case
491 + # any sets use the bintree.
492 + mytrees["bintree"].populate(
493 + getbinpkgs="--getbinpkg" in myopts)
494 +
495 + del mytrees, mydb
496 +
497 + for x in myfiles:
498 + ext = os.path.splitext(x)[1]
499 + if (ext == ".ebuild" or ext == ".tbz2") and os.path.exists(os.path.abspath(x)):
500 + print(colorize("BAD", "\n*** emerging by path is broken and may not always work!!!\n"))
501 + break
502 +
503 + root_config = trees[settings["ROOT"]]["root_config"]
504 + if myaction == "list-sets":
505 + writemsg_stdout("".join("%s\n" % s for s in sorted(root_config.sets)))
506 + return os.EX_OK
507 +
508 + ensure_required_sets(trees)
509 +
510 + # only expand sets for actions taking package arguments
511 + oldargs = myfiles[:]
512 + if myaction in ("clean", "config", "depclean", "info", "prune", "unmerge", None):
513 + myfiles, retval = expand_set_arguments(myfiles, myaction, root_config)
514 + if retval != os.EX_OK:
515 + return retval
516 +
517 + # Need to handle empty sets specially, otherwise emerge will react
518 + # with the help message for empty argument lists
519 + if oldargs and not myfiles:
520 + print("emerge: no targets left after set expansion")
521 + return 0
522 +
523 + if ("--tree" in myopts) and ("--columns" in myopts):
524 + print("emerge: can't specify both of \"--tree\" and \"--columns\".")
525 + return 1
526 +
527 + if '--emptytree' in myopts and '--noreplace' in myopts:
528 + writemsg_level("emerge: can't specify both of " + \
529 + "\"--emptytree\" and \"--noreplace\".\n",
530 + level=logging.ERROR, noiselevel=-1)
531 + return 1
532 +
533 + if ("--quiet" in myopts):
534 + spinner.update = spinner.update_quiet
535 + portage.util.noiselimit = -1
536 +
537 + if "--fetch-all-uri" in myopts:
538 + myopts["--fetchonly"] = True
539 +
540 + if "--skipfirst" in myopts and "--resume" not in myopts:
541 + myopts["--resume"] = True
542 +
543 + # Allow -p to remove --ask
544 + if "--pretend" in myopts:
545 + myopts.pop("--ask", None)
546 +
547 + # forbid --ask when not in a terminal
548 + # note: this breaks `emerge --ask | tee logfile`, but that doesn't work anyway.
549 + if ("--ask" in myopts) and (not sys.stdin.isatty()):
550 + portage.writemsg("!!! \"--ask\" should only be used in a terminal. Exiting.\n",
551 + noiselevel=-1)
552 + return 1
553 +
554 + if settings.get("PORTAGE_DEBUG", "") == "1":
555 + spinner.update = spinner.update_quiet
556 + portage.util.noiselimit = 0
557 + if "python-trace" in settings.features:
558 + import portage.debug as portage_debug
559 + portage_debug.set_trace(True)
560 +
561 + if not ("--quiet" in myopts):
562 + if '--nospinner' in myopts or \
563 + settings.get('TERM') == 'dumb' or \
564 + not sys.stdout.isatty():
565 + spinner.update = spinner.update_basic
566 +
567 + if "--debug" in myopts:
568 + print("myaction", myaction)
569 + print("myopts", myopts)
570 +
571 + pretend = "--pretend" in myopts
572 + fetchonly = "--fetchonly" in myopts or "--fetch-all-uri" in myopts
573 + buildpkgonly = "--buildpkgonly" in myopts
574 +
575 + # check if root user is the current user for the actions where emerge needs this
576 + if portage.secpass < 2:
577 + # We've already allowed "--version" and "--help" above.
578 + if "--pretend" not in myopts and myaction not in ("search","info"):
579 + need_superuser = myaction in ('clean', 'depclean', 'deselect',
580 + 'prune', 'unmerge') or not \
581 + (fetchonly or \
582 + (buildpkgonly and secpass >= 1) or \
583 + myaction in ("metadata", "regen", "sync"))
584 + if portage.secpass < 1 or \
585 + need_superuser:
586 + if need_superuser:
587 + access_desc = "superuser"
588 + else:
589 + access_desc = "portage group"
590 + # Always show portage_group_warning() when only portage group
591 + # access is required but the user is not in the portage group.
592 + from portage.data import portage_group_warning
593 + if "--ask" in myopts:
594 + myopts["--pretend"] = True
595 + del myopts["--ask"]
596 + print(("%s access is required... " + \
597 + "adding --pretend to options\n") % access_desc)
598 + if portage.secpass < 1 and not need_superuser:
599 + portage_group_warning()
600 + else:
601 + sys.stderr.write(("emerge: %s access is required\n") \
602 + % access_desc)
603 + if portage.secpass < 1 and not need_superuser:
604 + portage_group_warning()
605 + return 1
606 +
607 + disable_emergelog = False
608 + if disable_emergelog:
609 + """ Disable emergelog for everything except build or unmerge
610 + operations. This helps minimize parallel emerge.log entries that can
611 + confuse log parsers. We especially want it disabled during
612 + parallel-fetch, which uses --resume --fetchonly."""
613 + _emerge.emergelog._disable = True
614 +
615 + else:
616 + if 'EMERGE_LOG_DIR' in settings:
617 + try:
618 + # At least the parent needs to exist for the lock file.
619 + portage.util.ensure_dirs(settings['EMERGE_LOG_DIR'])
620 + except portage.exception.PortageException as e:
621 + writemsg_level("!!! Error creating directory for " + \
622 + "EMERGE_LOG_DIR='%s':\n!!! %s\n" % \
623 + (settings['EMERGE_LOG_DIR'], e),
624 + noiselevel=-1, level=logging.ERROR)
625 + else:
626 + global _emerge_log_dir
627 + _emerge_log_dir = settings['EMERGE_LOG_DIR']
628 +
629 + if not "--pretend" in myopts:
630 + emergelog(xterm_titles, "Started emerge on: "+\
631 + _unicode_decode(
632 + time.strftime("%b %d, %Y %H:%M:%S", time.localtime()),
633 + encoding=_encodings['content'], errors='replace'))
634 + myelogstr=""
635 + if myopts:
636 + myelogstr=" ".join(myopts)
637 + if myaction:
638 + myelogstr+=" "+myaction
639 + if myfiles:
640 + myelogstr += " " + " ".join(oldargs)
641 + emergelog(xterm_titles, " *** emerge " + myelogstr)
642 + del oldargs
643 +
644 + def emergeexitsig(signum, frame):
645 + signal.signal(signal.SIGINT, signal.SIG_IGN)
646 + signal.signal(signal.SIGTERM, signal.SIG_IGN)
647 + portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % {"signal":signum})
648 + sys.exit(128 + signum)
649 + signal.signal(signal.SIGINT, emergeexitsig)
650 + signal.signal(signal.SIGTERM, emergeexitsig)
651 +
652 + def emergeexit():
653 + """This gets out final log message in before we quit."""
654 + if "--pretend" not in myopts:
655 + emergelog(xterm_titles, " *** terminating.")
656 + if xterm_titles:
657 + xtermTitleReset()
658 + portage.atexit_register(emergeexit)
659 +
660 +
661 + # "update", "system", or just process files
662 + validate_ebuild_environment(trees)
663 +
664 + for x in myfiles:
665 + if x.startswith(SETPREFIX) or \
666 + is_valid_package_atom(x, allow_repo=True):
667 + continue
668 + if x[:1] == os.sep:
669 + continue
670 + try:
671 + os.lstat(x)
672 + continue
673 + except OSError:
674 + pass
675 + msg = []
676 + msg.append("'%s' is not a valid package atom." % (x,))
677 + msg.append("Please check ebuild(5) for full details.")
678 + writemsg_level("".join("!!! %s\n" % line for line in msg),
679 + level=logging.ERROR, noiselevel=-1)
680 + return 1
681 + if "--pretend" not in myopts:
682 + display_news_notification(root_config, myopts)
683 + retval, settings, trees, mtimedb = self.action_build(settings, trees, mtimedb,
684 + myopts, myaction, myfiles, spinner, build_dict)
685 + self.post_emerge(myaction, myopts, myfiles, settings["ROOT"],
686 + trees, mtimedb, retval)
687 +
688 + return retval
689
690 def make_build_list(self, build_dict):
691 - conn=CM.getConnection()
692 cpv = build_dict['category']+'/'+build_dict['package']+'-'+build_dict['ebuild_version']
693 pkgdir = os.path.join(self._mysettings['PORTDIR'], build_dict['category'] + "/" + build_dict['package'])
694 init_manifest = gobs_manifest(self._mysettings, pkgdir)
695 @@ -66,36 +620,34 @@ class queruaction(object):
696 except:
697 ebuild_version_checksum_tree = None
698 if ebuild_version_checksum_tree == build_dict['checksum']:
699 - if portage.getmaskingstatus(cpv, settings=self._mysettings, portdb=self._myportdb) == []:
700 - init_flags = gobs_use_flags(self._mysettings, self._myportdb, cpv)
701 - build_use_flags_list = init_flags.comper_useflags(build_dict)
702 - print("build_use_flags_list", build_use_flags_list)
703 - manifest_error = init_manifest.check_file_in_manifest(self._myportdb, cpv, build_dict, build_use_flags_list)
704 - if manifest_error is None:
705 - build_dict['check_fail'] = False
706 - build_cpv_dict = init_flags.get_needed_dep_useflags(build_use_flags_list)
707 - print(build_cpv_dict, build_use_flags_list, cpv)
708 - build_use_flags_dict = {}
709 - if build_use_flags_list is None:
710 - build_use_flags_dict['None'] = None
711 - if build_cpv_dict is None:
712 - build_cpv_dict = {}
713 - build_cpv_dict[cpv] = build_use_flags_dict
714 - else:
715 - build_cpv_dict[cpv] = build_use_flags_dict
716 - print(build_cpv_dict)
717 - return build_cpv_dict, build_dict
718 - else:
719 - build_dict['1'] = 1
720 + init_flags = gobs_use_flags(self._mysettings, self._myportdb, cpv)
721 + build_use_flags_list = init_flags.comper_useflags(build_dict)
722 + print("build_use_flags_list", build_use_flags_list)
723 + manifest_error = init_manifest.check_file_in_manifest(self._myportdb, cpv, build_dict, build_use_flags_list)
724 + if manifest_error is None:
725 + build_dict['check_fail'] = False
726 + build_use_flags_dict = {}
727 + if build_use_flags_list is None:
728 + build_use_flags_dict['None'] = None
729 + build_cpv_dict = {}
730 + build_cpv_dict[cpv] = build_use_flags_dict
731 + print(build_cpv_dict)
732 + return build_cpv_dict
733 else:
734 - build_dict['2'] = 2
735 + build_dict['type_fail'] = "Manifest error"
736 + build_dict['check_fail'] = True
737 else:
738 - build_dict['3'] = 3
739 - build_dict['check_fail'] = True
740 - return build_cpv_dict, build_dict
741 + build_dict['type_fail'] = "Wrong ebuild checksum"
742 + build_dict['check_fail'] = True
743 + if build_dict['check_fail'] is True:
744 + self.log_fail_queru(build_dict, portage.settings)
745 + return None
746 + return build_cpv_dict
747
748 def build_procces(self, buildqueru_cpv_dict, build_dict):
749 build_cpv_list = []
750 + abs_user_config = os.path.join(self._mysettings["PORTAGE_CONFIGROOT"], USER_CONFIG_PATH)
751 + print('abs_user_config', abs_user_config)
752 for k, v in buildqueru_cpv_dict.iteritems():
753 build_use_flags_list = []
754 for x, y in v.iteritems():
755 @@ -104,13 +656,16 @@ class queruaction(object):
756 if y is False:
757 build_use_flags_list.append("-" + x)
758 print(k, build_use_flags_list)
759 - if build_use_flags_list == []:
760 - build_cpv_list.append("=" + k)
761 - else:
762 + build_cpv_list.append("=" + k)
763 + if not build_use_flags_list == []:
764 build_use_flags = ""
765 for flags in build_use_flags_list:
766 - build_use_flags = build_use_flags + flags + ","
767 - build_cpv_list.append("=" + k + "[" + build_use_flags + "]")
768 + build_use_flags = build_use_flags + flags + " "
769 + filetext = k + ' ' + build_use_flags
770 + print('filetext', filetext)
771 + with open("/etc/portage/package.use/gobs.use", "a") as f:
772 + f.write(filetext)
773 + f.write('\n')
774 print('build_cpv_list', build_cpv_list)
775 argscmd = []
776 if not "nooneshort" in build_dict['post_message']:
777 @@ -121,37 +676,31 @@ class queruaction(object):
778 argscmd.append(build_cpv)
779 print(argscmd)
780 # Call main_emerge to build the package in build_cpv_list
781 - try:
782 - build_fail = emerge_main(args=argscmd)
783 - except:
784 - build_fail = False
785 + build_fail = self.emerge_main(argscmd, build_dict)
786 # Run depclean
787 + print('build_fail', build_fail)
788 if not "nodepclean" in build_dict['post_message']:
789 depclean_fail = main_depclean()
790 if build_fail is False or depclean_fail is False:
791 return False
792 return True
793
794 - def procces_qureru(self, fail_querue_dict):
795 + def procces_qureru(self):
796 conn=CM.getConnection()
797 build_dict = {}
798 build_dict = get_packages_to_build(conn, self._config_profile)
799 + if build_dict is None:
800 + return
801 print("build_dict", build_dict)
802 - if build_dict is None and fail_querue_dict == {}:
803 - return fail_querue_dict
804 - if build_dict is None and fail_querue_dict != {}:
805 - return fail_querue_dict
806 if not build_dict['ebuild_id'] is None and build_dict['checksum'] is not None:
807 - buildqueru_cpv_dict, build_dict = self.make_build_list(build_dict)
808 + buildqueru_cpv_dict = self.make_build_list(build_dict)
809 print('buildqueru_cpv_dict', buildqueru_cpv_dict)
810 if buildqueru_cpv_dict is None:
811 - return fail_querue_dict
812 + return
813 fail_build_procces = self.build_procces(buildqueru_cpv_dict, build_dict)
814 - if build_dict['check_fail'] is True:
815 - fail_querue_dict = self.log_fail_queru(build_dict, fail_querue_dict)
816 - return fail_querue_dict
817 + return
818 if not build_dict['post_message'] is [] and build_dict['ebuild_id'] is None:
819 - return fail_querue_dict
820 + return
821 if not build_dict['ebuild_id'] is None and build_dict['checksum'] is None:
822 del_old_queue(conn, build_dict['queue_id'])
823 - return fail_querue_dict
824 + return
825
826 diff --git a/gobs/pym/check_setup.py b/gobs/pym/check_setup.py
827 index 7dcd053..6b52f29 100644
828 --- a/gobs/pym/check_setup.py
829 +++ b/gobs/pym/check_setup.py
830 @@ -14,10 +14,10 @@ CM=connectionManager(gobs_settings_dict)
831 if CM.getName()=='pgsql':
832 from gobs.pgsql import *
833
834 -def check_make_conf(conn):
835 +def check_make_conf():
836 # FIXME: mark any config updating true in the db when updating the configs
837 # Get the config list
838 - ##selective import the pgsql/mysql queries
839 + conn=CM.getConnection()
840 config_list_all = get_config_list_all(conn)
841 print("Checking configs for changes and errors")
842 configsDict = {}
843 @@ -53,13 +53,17 @@ def check_make_conf(conn):
844 update__make_conf(conn,configsDict)
845 print("Updated configurtions")
846
847 -def check_make_conf_guest(connection, config_profile):
848 - make_conf_checksum_db = get_profile_checksum(connection,config_profile)[0]
849 +def check_make_conf_guest(config_profile):
850 + conn=CM.getConnection()
851 + print('config_profile', config_profile)
852 + make_conf_checksum_db = get_profile_checksum(conn,config_profile)
853 + print('make_conf_checksum_db', make_conf_checksum_db)
854 if make_conf_checksum_db is None:
855 return "1"
856 make_conf_file = "/etc/portage/make.conf"
857 make_conf_checksum_tree = portage.checksum.sha256hash(make_conf_file)[0]
858 - if make_conf_checksum_tree != make_conf_checksum_db:
859 + print('make_conf_checksum_tree', make_conf_checksum_tree)
860 + if make_conf_checksum_tree != make_conf_checksum_db[0]:
861 return "2"
862 # Check if we can open the file and close it
863 # Check if we have some error in the file (portage.util.getconfig)
864 @@ -75,8 +79,9 @@ def check_make_conf_guest(connection, config_profile):
865 return "3"
866 return "4"
867
868 -def check_configure_guest(connection, config_profile):
869 - pass_make_conf = check_make_conf_guest(connection, config_profile)
870 +def check_configure_guest(config_profile):
871 + conn=CM.getConnection()
872 + pass_make_conf = check_make_conf_guest(config_profile)
873 print(pass_make_conf)
874 if pass_make_conf == "1":
875 # profile not active or updatedb is runing
876 @@ -86,7 +91,7 @@ def check_configure_guest(connection, config_profile):
877 return False
878 elif pass_make_conf == "3":
879 # set the config as no working
880 - make_conf_error(connection,config_profile)
881 + make_conf_error(conn, config_profile)
882 return False
883 elif pass_make_conf == "4":
884 # make.conf check OK
885
886 diff --git a/gobs/pym/flags.py b/gobs/pym/flags.py
887 index e01fed3..ef63361 100644
888 --- a/gobs/pym/flags.py
889 +++ b/gobs/pym/flags.py
890 @@ -154,43 +154,6 @@ class gobs_use_flags(object):
891 final_flags = self.filter_flags(final_use, use_expand_hidden, usemasked, useforced)
892 return iuse_flags, final_flags
893
894 - def get_needed_dep_useflags(self, build_use_flags_list):
895 - cpv = self._cpv
896 - tmpcmdline = []
897 - tmpcmdline.append("-p")
898 - tmpcmdline.append("--autounmask")
899 - tmpcmdline.append("=" + self._cpv)
900 - print(tmpcmdline)
901 - myaction, myopts, myfiles = parse_opts(tmpcmdline, silent=False)
902 - print(myaction, myopts, myfiles)
903 - myparams = create_depgraph_params(myopts, myaction)
904 - print(myparams)
905 - settings, trees, mtimedb = load_emerge_config()
906 - try:
907 - success, mydepgraph, favorites = backtrack_depgraph(
908 - settings, trees, myopts, myparams, myaction, myfiles, spinner=None)
909 - print("success mydepgraph favorites", success, mydepgraph, favorites)
910 - except portage.exception.PackageSetNotFound as e:
911 - root_config = trees[settings["ROOT"]]["root_config"]
912 - display_missing_pkg_set(root_config, e.value)
913 - return 1
914 - use_changes = None
915 - mydepgraph._show_merge_list()
916 - mydepgraph.display_problems()
917 - if mydepgraph._dynamic_config._needed_use_config_changes:
918 - use_changes = {}
919 - for pkg, needed_use_config_changes in mydepgraph._dynamic_config._needed_use_config_changes.items():
920 - new_use, changes = needed_use_config_changes
921 - use_changes[pkg.cpv] = changes
922 - if use_changes is None:
923 - return None
924 - iteritems_packages = {}
925 - for k, v in use_changes.iteritems():
926 - k_package = portage.versions.cpv_getkey(k)
927 - iteritems_packages[ k_package ] = v
928 - print('iteritems_packages', iteritems_packages)
929 - return iteritems_packages
930 -
931 def comper_useflags(self, build_dict):
932 iuse_flags, use_enable = self.get_flags()
933 iuse = []
934
935 diff --git a/gobs/pym/pgsql.py b/gobs/pym/pgsql.py
936 index c66f205..9979b1b 100644
937 --- a/gobs/pym/pgsql.py
938 +++ b/gobs/pym/pgsql.py
939 @@ -414,7 +414,7 @@ def cp_all_old_db(connection, old_package_id_list):
940 def del_old_queue(connection, queue_id):
941 cursor = connection.cursor()
942 sqlQ1 = 'DELETE FROM ebuildqueuedwithuses WHERE queue_id = %s'
943 - sqlQ2 = 'DELETE FROM temp_errors_queue_qa WHERE queue_id = %s'
944 + sqlQ2 = 'DELETE FROM querue_retest WHERE querue_id = %s'
945 sqlQ3 = 'DELETE FROM buildqueue WHERE queue_id = %s'
946 cursor.execute(sqlQ1, (queue_id,))
947 cursor.execute(sqlQ2, (queue_id,))
948 @@ -568,28 +568,31 @@ def add_new_arch_db(connection, arch_list):
949 cursor.execute(sqlQ, (arch,))
950 connection.commit()
951
952 -def check_fail_times(connection, logDict):
953 - queue_id = logDict['queue_id']
954 - qa_error = logDict['qa_error_list'][0]
955 +def update_fail_times(connection, fail_querue_dict):
956 cursor = connection.cursor()
957 - sqlQ = 'SELECT errors FROM temp_errors_queue_qa WHERE queue_id = %s AND what_error = %s'
958 - cursor.execute(sqlQ, (queue_id, qa_error,))
959 - return cursor.fetchone()
960 + sqlQ1 = 'UPDATE querue_retest SET fail_times = %s WHERE querue_id = %s AND fail_type = %s'
961 + sqlQ2 = 'UPDATE buildqueue SET timestamp = NOW() WHERE queue_id = %s'
962 + cursor.execute(sqlQ1, (fail_querue_dict['fail_times'], fail_querue_dict['querue_id'], fail_querue_dict['fail_type'],))
963 + #cursor.execute(sqlQ2, (fail_querue_dict['querue_id'],))
964 + connection.commit()
965
966 -def add_fail_times(connection, logDict):
967 - queue_id = logDict['queue_id']
968 - qa_error = logDict['qa_error_list'][0]
969 +def get_fail_querue_dict(connection, build_dict):
970 cursor = connection.cursor()
971 - sqlQ = 'INSERT INTO temp_errors_queue_qa (queue_id, what_error) VALUES ( %s, %s)'
972 - cursor.execute(sqlQ, (queue_id, qa_error,))
973 - connection.commit()
974 + fail_querue_dict = {}
975 + sqlQ = 'SELECT fail_times FROM querue_retest WHERE querue_id = %s AND fail_type = %s'
976 + cursor.execute(sqlQ, (build_dict['queue_id'], build_dict['type_fail'],))
977 + entries = cursor.fetchone()
978 + if entries is None:
979 + return None
980 + fail_querue_dict['fail_times'] = entries
981 + return fail_querue_dict
982
983 -def update_fail_times(connection, logDict):
984 - queue_id = logDict['queue_id']
985 - qa_error = logDict['qa_error_list'][0]
986 +def add_fail_querue_dict(connection, fail_querue_dict):
987 cursor = connection.cursor()
988 - sqlQ1 = 'UPDATE buildqueue SET timestamp = NOW() WHERE queue_id = %s'
989 - cursor.execute(sqlQ1, (queue_id,))
990 + sqlQ1 = 'INSERT INTO querue_retest (querue_id, fail_type, fail_times) VALUES ( %s, %s, %s)'
991 + sqlQ2 = 'UPDATE buildqueue SET timestamp = NOW() WHERE queue_id = %s'
992 + cursor.execute(sqlQ1, (fail_querue_dict['querue_id'],fail_querue_dict['fail_type'], fail_querue_dict['fail_times']))
993 + #cursor.execute(sqlQ2, (fail_querue_dict['querue_id'],))
994 connection.commit()
995
996 def make_conf_error(connection,config_profile):