From 9dded9b45bfd08168c960112d0f26db740c2ed23 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Thu, 7 May 2020 10:38:20 +0200 Subject: SpecFile: make it aware of the real cwd, plus a typo fix elsewhere --- mgagnome | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/mgagnome b/mgagnome index e041f51..4440a2e 100755 --- a/mgagnome +++ b/mgagnome @@ -350,7 +350,14 @@ class SpecFile(): self._package = package self.module = package.name if package else module - self.cwd = package.path if package else os.path.dirname(path) + if package: + self.cwd = package.path + else: + self.cwd = os.path.dirname(path) + # If spec file is located in SPECS directory, cwd should be 1 + # directory higher + if os.path.basename(self.cwd) == 'SPECS': + self.cwd = os.path.dirname(self.cwd) self._changes = collections.OrderedDict() self._should_rebuild = False self._changed_spec_file = False @@ -370,8 +377,7 @@ class SpecFile(): @property def version(self): """Provide the version as parsed by rpm""" - topdir = self._package.path if self._package else os.path.join(self.cwd, "..") - cmd = ["rpm", "--define", "_topdir %s" % topdir, "--specfile", self.path, + cmd = ["rpm", "--define", "_topdir %s" % self.cwd, "--specfile", self.path, "--queryformat", "%{VERSION}\n"] return subprocess.check_output(cmd).decode("utf-8").splitlines()[0] @@ -383,16 +389,14 @@ class SpecFile(): @property def release(self): """Provide the release as parsed by rpm""" - topdir = self._package.path if self._package else os.path.join(self.cwd, "..") - cmd = ["rpm", "--define", "%dist %nil", "--define", "_topdir %s" % topdir, + cmd = ["rpm", "--define", "%dist %nil", "--define", "_topdir %s" % self.cwd, "--specfile", self.path, "--queryformat", "%{RELEASE}\n"] return subprocess.check_output(cmd).decode("utf-8").splitlines()[0] def _sources_and_patches(self, flag=None): os.chdir(self.cwd) - topdir = self._package.path if self._package else os.path.join(self.cwd, "..") rpm.delMacro("_topdir") - rpm.addMacro("_topdir", topdir) + rpm.addMacro("_topdir", self.cwd) trans_set = rpm.ts() spec = trans_set.parseSpec(self.path) try: @@ -947,9 +951,8 @@ class SpecFile(): Parses the spec file to do this, so any macros are expanded""" - topdir = self._package.path if self._package else os.path.join(self.cwd, "..") rpm.delMacro("_topdir") - rpm.addMacro("_topdir", topdir) + rpm.addMacro("_topdir", self.cwd) trans_set = rpm.ts() try: spec = trans_set.parseSpec(self.path) @@ -990,7 +993,7 @@ class SpecFile(): def _revert_changes(self): """Revert uncommited changes made to spec file""" self._changes.clear() - subprocess.check_call(["svn", "revert", "-R", os.path.join(self.cwd, '..')]) + subprocess.check_call(["svn", "revert", "-R", self.cwd]) def remove_patch(self, patchnr, info_patchname=None): """Remove a patch from the spec file""" @@ -1037,7 +1040,10 @@ class SpecFile(): # Check patches still apply subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) except subprocess.CalledProcessError: - logfile = os.path.join(self.cwd, 'log.%s' % os.path.splitext(os.path.basename(self.path))[0]) + logfile = os.path.join( + os.path.dirname(self.path), + 'log.%s' % os.path.splitext(os.path.basename(self.path))[0] + ) failed_patch = None cmd = None @@ -1115,7 +1121,7 @@ class SpecFile(): return False finally: # bm command doesn't cleanup after itself and the option it has to do that removes spec file + sources! - buildpath = os.path.join(self.cwd, '..', 'BUILD', '%s-%s' % (self.module, self.version)) + buildpath = os.path.join(self.cwd, 'BUILD', '%s-%s' % (self.module, self.version)) if os.path.exists(buildpath): shutil.rmtree(buildpath, ignore_errors=True) @@ -1180,8 +1186,7 @@ class SpecFile(): Can optionally force a clean checkout (by reverting any local changes). This should possibily be moved to Downstream class, or move this into a new Package class""" - # XXX - os.path.join is hackish - cmd = ["svn", "diff", os.path.normpath(os.path.join(self.cwd, '..'))] + cmd = ["svn", "diff", self.cwd] svn_diff_output = subprocess.check_output(cmd).decode('utf-8') if svn_diff_output != '': print(svn_diff_output) @@ -1574,7 +1579,7 @@ class Downstream(): ) # - now really get the right packages - matches = [package for package_name in packages if packages[package_name] == latest_version] + matches = [package_name for package_name in packages if packages[package_name] == latest_version] if matches: return matches @@ -1630,8 +1635,8 @@ class Package: if downstream.DISTRO: cmd.extend(('-d', downstream.DISTRO)) if spec_only: - downstream.append('-s') - downstream.append(self.name) + cmd.append('-s') + cmd.append(self.name) return subprocess.check_call(cmd, stdin=subprocess.DEVNULL, cwd=cwd) @retry(subprocess.CalledProcessError) -- cgit v1.2.1