summaryrefslogtreecommitdiffstats
path: root/BuildManager/package.py
diff options
context:
space:
mode:
Diffstat (limited to 'BuildManager/package.py')
-rw-r--r--BuildManager/package.py44
1 files changed, 20 insertions, 24 deletions
diff --git a/BuildManager/package.py b/BuildManager/package.py
index 0adfc10..140562d 100644
--- a/BuildManager/package.py
+++ b/BuildManager/package.py
@@ -1,7 +1,7 @@
from BuildManager import *
from BuildManager.rpmver import rpmVersionCompare
-from UserList import UserList
-import commands
+from collections import UserList
+import subprocess
import string
import os
import re
@@ -22,17 +22,17 @@ def subst(s, vars):
return str(vars[name])
try:
return re.sub(r'\$([a-zA-Z]+)', _subst, s)
- except KeyError, var:
- raise Error, "variable $%s not declared" % var
+ except KeyError as var:
+ raise Error("variable $%s not declared" % var)
class Package:
def __init__(self, file, log=None):
self._package = None
ext = self._filename_extension(file)
if not ext:
- raise Error, "unknown file extension of "+file
- if not globals().has_key("_package_"+ext):
- raise Error, "unknown package extension of "+file
+ raise Error("unknown file extension of "+file)
+ if "_package_"+ext not in globals():
+ raise Error("unknown package extension of "+file)
self._package = globals()["_package_"+ext](file, log)
def __getattr__(self, name):
@@ -88,7 +88,7 @@ class _package_spec(_package):
ret.append(str[start:])
break
varname = str[start+2:end]
- if vars.has_key(varname):
+ if varname in vars:
ret.append(vars[varname])
else:
ret.append(str[start:end+1])
@@ -100,9 +100,8 @@ class _package_spec(_package):
ret = os.system("mkdir -p %s/{SOURCES,SPECS,BUILD,SRPMS,RPMS,BUILDROOT}" % self.builddir)
try:
f = open(self.spec,"r")
- except IOError, e:
- raise BuildManagerFileError, \
- "couldn't open spec file %s" % self.absfile
+ except IOError as e:
+ raise BuildManagerFileError("couldn't open spec file %s" % self.absfile)
defines = {}
for line in f.readlines():
lowerline = string.lower(line)
@@ -119,8 +118,8 @@ class _package_spec(_package):
if self.name and self.version and self.release:
break
else:
- raise Error, "spec file %s doesn't define name, " \
- "version or release" % self.file
+ raise Error("spec file %s doesn't define name, " \
+ "version or release" % self.file)
self.type = "spec"
self._expand_log()
@@ -128,16 +127,14 @@ class _package_rpm(_package):
def _init(self):
if not rpm:
cmd = "rpm -qp --queryformat='%%{NAME} %%{EPOCH} %%{VERSION} %%{RELEASE} %%{SOURCERPM}' %s"%self.file
- status, output = commands.getstatusoutput(cmd)
+ status, output = subprocess.getstatusoutput(cmd)
if status != 0:
- raise BuildManagerPackageError, \
- "error querying rpm file %s" % self.file
+ raise BuildManagerPackageError("error querying rpm file %s" % self.file)
else:
tokens = string.split(output, " ")
if len(tokens) != 5:
- raise Error, \
- "unexpected output querying rpm file %s: %s" % \
- (self.file, output)
+ raise Error("unexpected output querying rpm file %s: %s" % \
+ (self.file, output))
else:
self.name, self.epoch, self.version, self.release, srpm = tokens
if self.epoch == "(none)":
@@ -176,16 +173,15 @@ class _package_rpm(_package):
builddir = "%s/%s-%s-%s-topdir" % (unpackdir, self.name, self.version, self.release)
ret = os.system("mkdir -p %s/{SOURCES,SPECS,BUILD,SRPMS,RPMS,BUILDROOT}" % builddir)
if ret != 0:
- raise BuildManagerPackageError, \
- "error creating builddir at %s" % builddir
+ raise BuildManagerPackageError("error creating builddir at %s" % builddir)
else:
return builddir
def _install_srpm(self):
cmd = "rpm -i --define '_topdir %s' %s &> %s"%(self.builddir,self.file,self.log)
- status, output = commands.getstatusoutput(cmd)
+ status, output = subprocess.getstatusoutput(cmd)
if status != 0:
- raise Error, "error installing package "+self.file
+ raise Error("error installing package "+self.file)
else:
spec = self.builddir+"/SPECS/"+self.name+".spec"
if not os.path.isfile(spec):
@@ -194,7 +190,7 @@ class _package_rpm(_package):
if file[-5:] != ".spec":
listdir.remove(file)
if len(listdir) != 1:
- raise Error, "can't guess spec file for "+self.file
+ raise Error("can't guess spec file for "+self.file)
else:
self.spec = self.builddir+"/SPECS/"+listdir[0]
return 1