diff options
author | Olav Vitters <olav@vitters.nl> | 2020-05-06 15:43:03 +0200 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2020-05-06 15:43:03 +0200 |
commit | 834a2b921846e5644872ba03a7f95bb12b867f01 (patch) | |
tree | 183efa32a22503a2052d7853b38765cad878b40f | |
parent | 38085480c9422826e55a2d9f4d465b36bbfee436 (diff) | |
download | mgagnome-834a2b921846e5644872ba03a7f95bb12b867f01.tar mgagnome-834a2b921846e5644872ba03a7f95bb12b867f01.tar.gz mgagnome-834a2b921846e5644872ba03a7f95bb12b867f01.tar.bz2 mgagnome-834a2b921846e5644872ba03a7f95bb12b867f01.tar.xz mgagnome-834a2b921846e5644872ba03a7f95bb12b867f01.zip |
SpecFile: optionally store the Package it belongs to
-rwxr-xr-x | mgagnome | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -368,10 +368,12 @@ class SpecFile(): re.MULTILINE + re.IGNORECASE ) - def __init__(self, path, module=None): + def __init__(self, path, package=None, module=None): self.path = path - self.cwd = os.path.dirname(path) - self.module = module + self._package = package + self.module = package.name if package else module + + self.cwd = package.path if package else os.path.dirname(path) self._changes = collections.OrderedDict() self._should_rebuild = False self._changed_spec_file = False @@ -391,7 +393,8 @@ class SpecFile(): @property def version(self): """Provide the version as parsed by rpm""" - cmd = ["rpm", "--define", "_topdir %s" % os.path.join(self.cwd, ".."), "--specfile", self.path, + topdir = self._package.path if self._package else os.path.join(self.cwd, "..") + cmd = ["rpm", "--define", "_topdir %s" % topdir, "--specfile", self.path, "--queryformat", "%{VERSION}\n"] return subprocess.check_output(cmd).decode("utf-8").splitlines()[0] @@ -403,14 +406,16 @@ class SpecFile(): @property def release(self): """Provide the release as parsed by rpm""" - cmd = ["rpm", "--define", "%dist %nil", "--define", "_topdir %s" % os.path.join(self.cwd, ".."), + topdir = self._package.path if self._package else os.path.join(self.cwd, "..") + cmd = ["rpm", "--define", "%dist %nil", "--define", "_topdir %s" % topdir, "--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", os.path.join(self.cwd, '..')) + rpm.addMacro("_topdir", topdir) trans_set = rpm.ts() spec = trans_set.parseSpec(self.path) try: @@ -783,8 +788,9 @@ 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", os.path.join(self.cwd, '..')) + rpm.addMacro("_topdir", topdir) trans_set = rpm.ts() try: spec = trans_set.parseSpec(self.path) @@ -1435,7 +1441,7 @@ class Package: """Return the SpecFile for a given package""" path = self.path - return SpecFile(os.path.join(path, "SPECS", "%s.spec" % self.name), module=self.name) + return SpecFile(os.path.join(path, "SPECS", "%s.spec" % self.name), package=self, module=self.name) @retry(subprocess.CalledProcessError) |