diff options
-rw-r--r-- | BuildManager/package.py | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/BuildManager/package.py b/BuildManager/package.py index c3c3efb..7bf578b 100644 --- a/BuildManager/package.py +++ b/BuildManager/package.py @@ -100,30 +100,16 @@ class _package_spec(_package): self.builddir = os.path.dirname(os.path.dirname(self.absfile)) ret = os.system("mkdir -p %s/{SOURCES,SPECS,BUILD,SRPMS,RPMS,BUILDROOT}" % self.builddir) try: - f = codecs.open(self.spec, "r", 'utf-8', errors = "replace") - except IOError as e: + f = rpm.spec(self.spec) + except ValueError as e: raise BuildManagerFileError("couldn't open spec file %s" % self.absfile) defines = {} - for line in f.readlines(): - lowerline = line.lower() - if not self.name and lowerline[:5] == "name:": - self.name = self._rpm_vars((line[5:]).strip(), defines) - elif not self.version and lowerline[:8] == "version:": - self.version = self._rpm_vars((line[8:]).strip(), defines) - elif not self.release and lowerline[:8] == "release:": - rel = self._rpm_vars((line[8:]).strip(), defines) - if rel.startswith("%mkrel"): - p = subprocess.run(["rpm", "--eval", rel], text=True, capture_output=True) - self.release = p.stdout - else: - self.release = rel - elif lowerline[:7] == "%define": - token = (line[7:]).split() - if len(token) == 2: - defines[token[0]] = self._rpm_vars(token[1], defines) - if self.name and self.version and self.release: - break - else: + + self.name = f.packages[0].header["name"] + self.version = f.packages[0].header["version"] + self.release = f.packages[0].header["release"] + + if not self.name or not self.version or not self.release: raise Error("spec file %s doesn't define name, " \ "version or release" % self.file) self.type = "spec" |