1 |
commit: 3d7ed631ecc2f4f75beab3d6d17b75d6fc0ecd3c |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Mar 28 15:43:54 2021 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Mar 28 18:42:07 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3d7ed631 |
7 |
|
8 |
repoman: split up repoman_main |
9 |
|
10 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
11 |
|
12 |
repoman/lib/repoman/main.py | 39 ++++++++++++++++++++++++++++++++++++--- |
13 |
1 file changed, 36 insertions(+), 3 deletions(-) |
14 |
|
15 |
diff --git a/repoman/lib/repoman/main.py b/repoman/lib/repoman/main.py |
16 |
index dc791ad71..a694410d7 100755 |
17 |
--- a/repoman/lib/repoman/main.py |
18 |
+++ b/repoman/lib/repoman/main.py |
19 |
@@ -3,6 +3,7 @@ |
20 |
# Copyright 1999-2021 Gentoo Authors |
21 |
# Distributed under the terms of the GNU General Public License v2 |
22 |
|
23 |
+import collections |
24 |
import io |
25 |
import logging |
26 |
import sys |
27 |
@@ -47,7 +48,26 @@ portage.util.initialize_logger(LOGLEVEL) |
28 |
|
29 |
VALID_VERSIONS = [1,] |
30 |
|
31 |
+_repoman_main_vars = collections.namedtuple("_repoman_main_vars", ( |
32 |
+ "can_force", |
33 |
+ "exitcode", |
34 |
+ "options", |
35 |
+ "qadata", |
36 |
+ "repo_settings", |
37 |
+ "scanner", |
38 |
+ "vcs_settings", |
39 |
+)) |
40 |
+ |
41 |
+ |
42 |
def repoman_main(argv): |
43 |
+ repoman_vars = _repoman_init(argv) |
44 |
+ if repoman_vars.exitcode is not None: |
45 |
+ return repoman_vars.exitcode |
46 |
+ result = _repoman_scan(*repoman_vars) |
47 |
+ return _handle_result(*repoman_vars, result) |
48 |
+ |
49 |
+ |
50 |
+def _repoman_init(argv): |
51 |
config_root = os.environ.get("PORTAGE_CONFIGROOT") |
52 |
repoman_settings = portage.config(config_root=config_root, local_config=False) |
53 |
repoman_settings.valid_versions = VALID_VERSIONS |
54 |
@@ -62,7 +82,7 @@ def repoman_main(argv): |
55 |
|
56 |
if options.version: |
57 |
print("Repoman", VERSION, "(portage-%s)" % portage.VERSION) |
58 |
- sys.exit(0) |
59 |
+ return _repoman_main_vars(exitcode=0) |
60 |
|
61 |
logger = logging.getLogger() |
62 |
|
63 |
@@ -75,10 +95,15 @@ def repoman_main(argv): |
64 |
# something other than a QA issue) makes it impossible to |
65 |
# commit (like if Manifest generation fails). |
66 |
can_force = ExtendedFuture(True) |
67 |
+ repo_settings, vcs_settings, scanner, qadata = _create_scanner(options, can_force, config_root, repoman_settings) |
68 |
+ return _repoman_main_vars(can_force, None, options, qadata, repo_settings, scanner, vcs_settings) |
69 |
+ |
70 |
+ |
71 |
+def _create_scanner(options, can_force, config_root, repoman_settings): |
72 |
|
73 |
portdir, portdir_overlay, mydir = utilities.FindPortdir(repoman_settings) |
74 |
if portdir is None: |
75 |
- sys.exit(1) |
76 |
+ return (None, None, None, None) |
77 |
|
78 |
myreporoot = os.path.basename(portdir_overlay) |
79 |
myreporoot += mydir[len(portdir_overlay):] |
80 |
@@ -117,6 +142,10 @@ def repoman_main(argv): |
81 |
# Perform the main checks |
82 |
scanner = Scanner(repo_settings, myreporoot, config_root, options, |
83 |
vcs_settings, mydir, env) |
84 |
+ return repo_settings, vcs_settings, scanner, qadata |
85 |
+ |
86 |
+ |
87 |
+def _repoman_scan(can_force, exitcode, options, qadata, repo_settings, scanner, vcs_settings): |
88 |
scanner.scan_pkgs(can_force) |
89 |
|
90 |
if options.if_modified == "y" and len(scanner.effective_scanlist) < 1: |
91 |
@@ -142,6 +171,10 @@ def repoman_main(argv): |
92 |
(result['warn'] and not (options.quiet or options.mode == "scan")): |
93 |
result['full'] = 0 |
94 |
|
95 |
+ return result |
96 |
+ |
97 |
+ |
98 |
+def _handle_result(can_force, exitcode, options, qadata, repo_settings, scanner, vcs_settings, result): |
99 |
commitmessage = None |
100 |
if options.commitmsg: |
101 |
commitmessage = options.commitmsg |
102 |
@@ -190,4 +223,4 @@ def repoman_main(argv): |
103 |
# perform any other actions |
104 |
actions.perform(qa_output) |
105 |
|
106 |
- sys.exit(0) |
107 |
+ return 0 |