From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1265395-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id E08131382C5
	for <garchives@archives.gentoo.org>; Sun, 28 Mar 2021 18:48:05 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 22D6EE086B;
	Sun, 28 Mar 2021 18:48:05 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 06419E086B
	for <gentoo-commits@lists.gentoo.org>; Sun, 28 Mar 2021 18:48:04 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 11C34340E12
	for <gentoo-commits@lists.gentoo.org>; Sun, 28 Mar 2021 18:48:04 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 43DD1C3
	for <gentoo-commits@lists.gentoo.org>; Sun, 28 Mar 2021 18:48:02 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1616956927.3d7ed631ecc2f4f75beab3d6d17b75d6fc0ecd3c.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/
X-VCS-Repository: proj/portage
X-VCS-Files: repoman/lib/repoman/main.py
X-VCS-Directories: repoman/lib/repoman/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 3d7ed631ecc2f4f75beab3d6d17b75d6fc0ecd3c
X-VCS-Branch: master
Date: Sun, 28 Mar 2021 18:48:02 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 13afaa7a-93fd-4396-96af-6ce9401662ca
X-Archives-Hash: f55172a616bdc6d75460cc145fa52484

commit:     3d7ed631ecc2f4f75beab3d6d17b75d6fc0ecd3c
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 28 15:43:54 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar 28 18:42:07 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3d7ed631

repoman: split up repoman_main

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 repoman/lib/repoman/main.py | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/repoman/lib/repoman/main.py b/repoman/lib/repoman/main.py
index dc791ad71..a694410d7 100755
--- a/repoman/lib/repoman/main.py
+++ b/repoman/lib/repoman/main.py
@@ -3,6 +3,7 @@
 # Copyright 1999-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import collections
 import io
 import logging
 import sys
@@ -47,7 +48,26 @@ portage.util.initialize_logger(LOGLEVEL)
 
 VALID_VERSIONS = [1,]
 
+_repoman_main_vars = collections.namedtuple("_repoman_main_vars", (
+	"can_force",
+	"exitcode",
+	"options",
+	"qadata",
+	"repo_settings",
+	"scanner",
+	"vcs_settings",
+))
+
+
 def repoman_main(argv):
+	repoman_vars = _repoman_init(argv)
+	if repoman_vars.exitcode is not None:
+		return repoman_vars.exitcode
+	result = _repoman_scan(*repoman_vars)
+	return _handle_result(*repoman_vars, result)
+
+
+def _repoman_init(argv):
 	config_root = os.environ.get("PORTAGE_CONFIGROOT")
 	repoman_settings = portage.config(config_root=config_root, local_config=False)
 	repoman_settings.valid_versions = VALID_VERSIONS
@@ -62,7 +82,7 @@ def repoman_main(argv):
 
 	if options.version:
 		print("Repoman", VERSION, "(portage-%s)" % portage.VERSION)
-		sys.exit(0)
+		return _repoman_main_vars(exitcode=0)
 
 	logger = logging.getLogger()
 
@@ -75,10 +95,15 @@ def repoman_main(argv):
 	# something other than a QA issue) makes it impossible to
 	# commit (like if Manifest generation fails).
 	can_force = ExtendedFuture(True)
+	repo_settings, vcs_settings, scanner, qadata = _create_scanner(options, can_force, config_root, repoman_settings)
+	return _repoman_main_vars(can_force, None, options, qadata, repo_settings, scanner, vcs_settings)
+
+
+def _create_scanner(options, can_force, config_root, repoman_settings):
 
 	portdir, portdir_overlay, mydir = utilities.FindPortdir(repoman_settings)
 	if portdir is None:
-		sys.exit(1)
+		return (None, None, None, None)
 
 	myreporoot = os.path.basename(portdir_overlay)
 	myreporoot += mydir[len(portdir_overlay):]
@@ -117,6 +142,10 @@ def repoman_main(argv):
 	# Perform the main checks
 	scanner = Scanner(repo_settings, myreporoot, config_root, options,
 					vcs_settings, mydir, env)
+	return repo_settings, vcs_settings, scanner, qadata
+
+
+def _repoman_scan(can_force, exitcode, options, qadata, repo_settings, scanner, vcs_settings):
 	scanner.scan_pkgs(can_force)
 
 	if options.if_modified == "y" and len(scanner.effective_scanlist) < 1:
@@ -142,6 +171,10 @@ def repoman_main(argv):
 		(result['warn'] and not (options.quiet or options.mode == "scan")):
 		result['full'] = 0
 
+	return result
+
+
+def _handle_result(can_force, exitcode, options, qadata, repo_settings, scanner, vcs_settings, result):
 	commitmessage = None
 	if options.commitmsg:
 		commitmessage = options.commitmsg
@@ -190,4 +223,4 @@ def repoman_main(argv):
 		# perform any other actions
 		actions.perform(qa_output)
 
-	sys.exit(0)
+	return 0