From d0fe161bc4431689cfee6f8dc8243611c6a52347 Mon Sep 17 00:00:00 2001 From: Mads Kiilerich Date: Dec 01 2021 23:41:21 +0000 Subject: Improve how the .spec file is selected Fix the problem that "fedpkg local" in a clone of package X could use a.spec instead of X.spec . Prefer the spec file that matches the directory name, and issue a warning if there is any doubt. Signed-off-by: Mads Kiilerich --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index db64224..9884622 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -813,13 +813,22 @@ class Commands(object): if self.is_retired(): raise rpkgError('This package or module is retired. The action has stopped.') - # Get a list of files in the path we're looking at - files = os.listdir(self.layout.specdir) - # Search the files for the first one that ends with ".spec" - for f in files: - if f.endswith('.spec') and not f.startswith('.'): - self._spec = f - return + # Get a list of ".spec" files in the path we're looking at + specs = [ + f for f in os.listdir(self.layout.specdir) + if f.endswith('.spec') and not f.startswith('.') + ] + + if specs: + # Prefer the spec matching the directory name + self._spec = os.path.basename(self.layout.specdir) + '.spec' + if specs != [self._spec]: + if self._spec not in specs: + self._spec = specs[0] + # Warn if more or less than the spec matching the directory name was found + self.log.warning("Using {0}".format(self._spec)) + return + raise rpkgError('No spec file found.') @property