From 042010b840bd920cece9ef00d06db392f142a7b3 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 7 Jun 2020 01:15:09 +0000 Subject: tool: Refactor repodir handling * Use given repodir in config if not blank * Ditch ~/gentoo-x86 default (it's ancient) and error out if it doesn't exist * If no repodir given, guess: * /var/db/repos/gentoo, and then * /usr/portage Now that we use nattka, we need a working repodir. Try some sensible defaults if the given one doesn't work. tatt: Support file-only jobs via Nattka Signed-off-by: Sam James --- scripts/tatt | 8 ++++---- tatt/dot-tatt-spec | 2 +- tatt/tool.py | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/scripts/tatt b/scripts/tatt index 9936006..27e9b61 100755 --- a/scripts/tatt +++ b/scripts/tatt @@ -19,6 +19,7 @@ from tatt.scriptwriter import writecommitscript as writeCommit from tatt.scriptwriter import writeCleanUpScript as writeCleanup from tatt.tattConfig import tattConfig as tattConfig from tatt.job import job as job +from tatt.tool import get_repo_dir ##### Generate a global config obj, reading from ~/.tatt ##### config = tattConfig() @@ -142,7 +143,6 @@ if options.infile: myJob.type="stable" myJob.packageList = packageFinder.findPackages(packraw, targetarch) - ## -b and a bugnumber was given ? if options.bugnum: print("Bugnumber: " + options.bugnum) @@ -166,9 +166,9 @@ if options.bugnum: sys.exit(1) if myJob.packageList==None: if response["cf_stabilisation_atoms"]: - myJob.packageList = packageFinder.findPackages(response["cf_stabilisation_atoms"], config['arch'], config['repodir'], options.bugnum) + myJob.packageList = packageFinder.findPackages(response["cf_stabilisation_atoms"], config['arch'], get_repo_dir(config['repodir']), options.bugnum) if len(myJob.packageList) == 0 and ("KEYWORDREQ" in response["keywords"] or response["component"] == "Keywording"): - myJob.packageList = packageFinder.findPackages(response["cf_stabilisation_atoms"], '~' + config['arch'], config['repodir'], options.bugnum) + myJob.packageList = packageFinder.findPackages(response["cf_stabilisation_atoms"], '~' + config['arch'], get_repo_dir(config['repodir']), options.bugnum) else: response = session.get(config["bugzilla-url"] + "/rest/bug/{}/attachment".format(options.bugnum), params=params).json()["bugs"][str(options.bugnum)] for attachment in response: @@ -176,7 +176,7 @@ if options.bugnum: continue for flag in attachment['flags']: if flag["name"] == "stabilization-list" and flag["status"] == '+': - myJob.packageList = packageFinder.findPackages(base64.b64decode(attachment["data"]).decode("utf8"), config['arch'], config['repodir'], options.bugnum) + myJob.packageList = packageFinder.findPackages(base64.b64decode(attachment["data"]).decode("utf8"), config['arch'], get_repo_dir(config['repodir']), options.bugnum) # joint code for -f and -b diff --git a/tatt/dot-tatt-spec b/tatt/dot-tatt-spec index 1d9fe9d..33aff95 100644 --- a/tatt/dot-tatt-spec +++ b/tatt/dot-tatt-spec @@ -7,7 +7,7 @@ defaultopts=string(default="") emergeopts=string(default="") rdeps=integer(0,512,default=10) usecombis=integer(0,512,default=12) -repodir=string(default="./gentoo-x86") +repodir=string(default="") tinderbox-url=string(default="https://qa-reports.gentoo.org/output/genrdeps/rindex/") safedir=string(default="") bugzilla-url=string(default="https://bugs.gentoo.org") diff --git a/tatt/tool.py b/tatt/tool.py index 450ed6a..1322315 100644 --- a/tatt/tool.py +++ b/tatt/tool.py @@ -1,3 +1,5 @@ +import os + """ Helper functions used in tatt""" ## Getting unique elements of a list ## @@ -17,3 +19,21 @@ def unique(seq, idfun=None): seen[marker] = 1 result.append(item) return result + +def get_repo_dir(repodir): + # Prefer the repo dir in the config + if repodir: + if os.path.isdir(repodir): + return repodir + else: + raise ValueError("Repo dir does not seem to be a directory") + + # No path given in config + if os.path.isdir("/var/db/repos/gentoo/"): + print("Using /var/db/repos/gentoo/ as fallback") + return "/var/db/repos/gentoo" + elif os.path.isdir("/usr/portage/"): + print("Using /usr/portage/ as fallback") + return "/usr/portage/" + + raise ValueError("Repo dir not given and fallbacks failed") -- cgit v1.2.3-65-gdbad