summaryrefslogtreecommitdiffstats
path: root/py/mock
diff options
context:
space:
mode:
authorMichael E Brown <mebrown@michaels-house.net>2007-12-02 15:21:05 -0600
committerMichael E Brown <mebrown@michaels-house.net>2007-12-02 15:21:05 -0600
commit229ce9c838bc2d78dfd5dcbfbe97fce859694811 (patch)
tree2b3ac4fbf113199d9a09645c0ff91550013f35cb /py/mock
parent315fd0b88b0c263e83bcc47fbeb242c38ed01d02 (diff)
mostly whitespace fixes, plus a few other things to make pylint/pychecker happier. No significant code changes.
Diffstat (limited to 'py/mock')
-rw-r--r--py/mock/__init__.py1
-rw-r--r--py/mock/backend.py26
-rw-r--r--py/mock/exception.py14
-rwxr-xr-xpy/mock/trace_decorator.py10
-rw-r--r--py/mock/uid.py2
-rw-r--r--py/mock/util.py54
6 files changed, 58 insertions, 49 deletions
diff --git a/py/mock/__init__.py b/py/mock/__init__.py
index e69de29..e8150a0 100644
--- a/py/mock/__init__.py
+++ b/py/mock/__init__.py
@@ -0,0 +1 @@
+"""All of the mock utility classes."""
diff --git a/py/mock/backend.py b/py/mock/backend.py
index 463f69c..9ceace6 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -13,7 +13,6 @@ import logging
import os
import shutil
import stat
-import time
from peak.util.decorators import decorate
# our imports
@@ -34,6 +33,8 @@ class Root(object):
self._hooks = {}
self.chrootWasCleaned = False
self.preExistingDeps = ""
+ self.logging_initialized = False
+ self.buildrootLock = None
self.sharedRootName = config['root']
root = self.sharedRootName
@@ -51,10 +52,7 @@ class Root(object):
self.personality = config['target_arch']
# result dir
- if not config.has_key('resultdir'):
- self.resultdir = os.path.join(self.basedir, 'result')
- else:
- self.resultdir = config['resultdir'] % config
+ self.resultdir = config['resultdir'] % config
self.root_log = logging.getLogger("mock")
self.build_log = logging.getLogger("mock.Root.build")
@@ -277,7 +275,7 @@ class Root(object):
os.mknod( os.path.join(self.rootdir, i[2]), i[0], i[1] )
# set context. (only necessary if host running selinux enabled.)
# fails gracefully if chcon not installed.
- mock.util.do("chcon --reference=/%s %s" %
+ mock.util.do("chcon --reference=/%s %s" %
(i[2], os.path.join(self.rootdir, i[2])), raiseExc=0)
os.symlink("/proc/self/fd/0", os.path.join(self.rootdir, "dev/stdin"))
@@ -319,7 +317,7 @@ class Root(object):
# get text buildreqs
a = mock.util.requiresTextFromHdr(hdr)
b = mock.util.getAddtlReqs(hdr, self.more_buildreqs)
- for item in mock.util.uniqReqs(a,b):
+ for item in mock.util.uniqReqs(a, b):
arg_string = arg_string + " '%s'" % item
finally:
@@ -333,7 +331,7 @@ class Root(object):
if line.lower().find('No Package found for'.lower()) != -1:
raise mock.exception.BuildError, "Bad build req: %s. Exiting." % line
# nothing made us exit, so we continue
- self.uidManager.becomeUser(0,0)
+ self.uidManager.becomeUser(0, 0)
try:
self._yum('install %s' % arg_string, returnOutput=1)
finally:
@@ -361,7 +359,7 @@ class Root(object):
srpmBasename = os.path.basename(srpmChrootFilename)
# install srpm
- os.environ["HOME"] = self.homedir
+ os.environ["HOME"] = self.homedir
# Completely/Permanently drop privs while running the following:
self.doChroot(
"rpm -Uvh --nodeps %s" % (srpmChrootFilename,),
@@ -379,7 +377,7 @@ class Root(object):
chrootspec = spec.replace(self.rootdir, '') # get rid of rootdir prefix
# Completely/Permanently drop privs while running the following:
self.doChroot(
- "rpmbuild -bs --target %s --nodeps %s" % (self.target_arch, chrootspec),
+ "rpmbuild -bs --target %s --nodeps %s" % (self.target_arch, chrootspec),
logger=self.build_log, timeout=timeout,
uidManager=self.uidManager,
uid=self.chrootuid,
@@ -388,7 +386,7 @@ class Root(object):
rebuiltSrpmFile = glob.glob("%s/%s/SRPMS/*.src.rpm" % (self.rootdir, self.builddir))
if len(rebuiltSrpmFile) != 1:
- raise mock.exception.PkgError, "Didnt find single rebuilt srpm."
+ raise mock.exception.PkgError, "Didnt find single rebuilt srpm."
rebuiltSrpmFile = rebuiltSrpmFile[0]
self.installSrpmDeps(rebuiltSrpmFile)
@@ -400,7 +398,7 @@ class Root(object):
self._callHooks('prebuild')
self.doChroot(
- "rpmbuild -bb --target %s --nodeps %s" % (self.target_arch, chrootspec),
+ "rpmbuild -bb --target %s --nodeps %s" % (self.target_arch, chrootspec),
logger=self.build_log, timeout=timeout,
uidManager=self.uidManager,
uid=self.chrootuid,
@@ -501,9 +499,9 @@ class Root(object):
decorate(traceLog(moduleLog))
def _resetLogging(self):
# ensure we dont attach the handlers multiple times.
- if getattr(self, "logging_initialized", None):
+ if self.logging_initialized:
return
- self.logging_initialized = 1
+ self.logging_initialized = True
# attach logs to log files.
# This happens in addition to anything that
diff --git a/py/mock/exception.py b/py/mock/exception.py
index aee93b9..d93fcf3 100644
--- a/py/mock/exception.py
+++ b/py/mock/exception.py
@@ -4,14 +4,16 @@
# Sections taken from Mach by Thomas Vander Stichele
# Major reorganization and adaptation by Michael Brown
# Copyright (C) 2007 Michael E Brown <mebrown@michaels-house.net>
+"""define most of the exceptions used."""
# python library imports
-from exceptions import Exception
+#from exceptions import Exception
# our imports
# classes
class Error(Exception):
+ "base class for our errors."
def __init__(self, msg):
Exception.__init__(self)
self.msg = msg
@@ -32,36 +34,42 @@ class Error(Exception):
# 60 = buildroot locked
class BuildError(Error):
+ "rpmbuild failed."
def __init__(self, msg):
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 10
class RootError(Error):
+ "failed to set up chroot"
def __init__(self, msg):
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 20
-class YumError(Error):
+class YumError(RootError):
+ "yum failed."
def __init__(self, msg):
- Error.__init__(self, msg)
+ RootError.__init__(self, msg)
self.msg = msg
self.resultcode = 30
class PkgError(Error):
+ "error with the srpm given to us."
def __init__(self, msg):
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 40
class BuildRootLocked(Error):
+ "build root in use by another process."
def __init__(self, msg):
Error.__init__(self, msg)
self.msg = msg
self.resultcode = 60
class BadCmdline(Error):
+ "user gave bad/inconsistent command line."
def __init__(self, msg):
Error.__init__(self, msg)
self.msg = msg
diff --git a/py/mock/trace_decorator.py b/py/mock/trace_decorator.py
index 5529628..7ce0806 100755
--- a/py/mock/trace_decorator.py
+++ b/py/mock/trace_decorator.py
@@ -25,19 +25,19 @@ def traceLog(log = moduleLog):
# can override by passing logger=foo as function parameter.
# make sure this doesnt conflict with one of the parameters
# you are expecting
-
+
filename = os.path.normcase(func.func_code.co_filename)
func_name = func.func_code.co_name
lineno = func.func_code.co_firstlineno
-
+
l2 = kw.get('logger', log)
message = "ENTER %s(" % func_name
for arg in args:
message = message + repr(arg) + ", "
- for k,v in kw.items():
- message = message + "%s=%s" % (k,repr(v))
+ for k, v in kw.items():
+ message = message + "%s=%s" % (k, repr(v))
message = message + ")"
-
+
frame = sys._getframe(2)
doLog(l2, logging.DEBUG, os.path.normcase(frame.f_code.co_filename), frame.f_lineno, message, args=[], exc_info=None, func=frame.f_code.co_name)
try:
diff --git a/py/mock/uid.py b/py/mock/uid.py
index 241f77a..a9aca11 100644
--- a/py/mock/uid.py
+++ b/py/mock/uid.py
@@ -39,7 +39,7 @@ class uidManager(object):
# back to root first
self._elevatePrivs()
- # then set saved
+ # then set saved
privs = self.privStack.pop()
os.setregid(privs['rgid'], privs['egid'])
setresuid(privs['ruid'], privs['euid'])
diff --git a/py/mock/util.py b/py/mock/util.py
index 4c5dbb6..b54e5f3 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -35,15 +35,15 @@ class commandTimeoutExpired(mock.exception.Error):
# functions
decorate(traceLog(log))
def mkdirIfAbsent(*args):
- for dir in args:
- log.debug("ensuring that dir exists: %s" % dir)
- if not os.path.exists(dir):
+ for dirName in args:
+ log.debug("ensuring that dir exists: %s" % dirName)
+ if not os.path.exists(dirName):
try:
- log.debug("creating dir: %s" % dir)
- os.makedirs(dir)
+ log.debug("creating dir: %s" % dirName)
+ os.makedirs(dirName)
except OSError, e:
- log.exception("Could not create dir %s. Error: %s" % (dir, e))
- raise mock.exception.Error, "Could not create dir %s. Error: %s" % (dir, e)
+ log.exception("Could not create dir %s. Error: %s" % (dirName, e))
+ raise mock.exception.Error, "Could not create dir %s. Error: %s" % (dirName, e)
decorate(traceLog(log))
def touch(fileName):
@@ -53,7 +53,7 @@ def touch(fileName):
decorate(traceLog(log))
def rmtree(path, *args, **kargs):
- """version os shutil.rmtree that ignores no-such-file-or-directory errors,
+ """version os shutil.rmtree that ignores no-such-file-or-directory errors,
and tries harder if it finds immutable files"""
tryAgain = 1
failedFilename = None
@@ -81,10 +81,10 @@ def orphansKill(rootToKill):
root = os.readlink("/proc/%s/root" % fn)
if root == rootToKill:
log.warning("Process ID %s still running in chroot. Killing..." % fn)
- os.kill(int(fn,10), 15)
+ os.kill(int(fn, 10), 15)
except OSError, e:
pass
-
+
decorate(traceLog(log))
def yieldSrpmHeaders(srpms, plainRpmOk=0):
@@ -136,8 +136,8 @@ def getAddtlReqs(hdr, conf):
# Add the 'more_buildreqs' for this SRPM (if defined in config file)
(name, epoch, ver, rel, arch) = getNEVRA(hdr)
reqlist = []
- for this_srpm in ['-'.join([name,ver,rel]),
- '-'.join([name,ver]),
+ for this_srpm in ['-'.join([name, ver, rel]),
+ '-'.join([name, ver]),
'-'.join([name]),]:
if conf.has_key(this_srpm):
more_reqs = conf[this_srpm]
@@ -172,8 +172,10 @@ decorate(traceLog(log))
def condDropPrivs(uidManager, uid, gid):
if uidManager is not None:
log.debug("about to drop privs")
- if uid is not None: uidManager.unprivUid=uid
- if gid is not None: uidManager.unprivGid=gid
+ if uid is not None:
+ uidManager.unprivUid = uid
+ if gid is not None:
+ uidManager.unprivGid = gid
uidManager.dropPrivsForever()
# not traced...
@@ -192,7 +194,7 @@ personality_defs['ppc'] = 0x0008
decorate(traceLog(log))
def condPersonality(per=None):
- if personality_defs.get(per,None) is None: return
+ if personality_defs.get(per, None) is None: return
import ctypes
_libc = ctypes.cdll.LoadLibrary("libc.so.6")
_libc.personality.argtypes = [ctypes.c_ulong]
@@ -208,23 +210,23 @@ def condPersonality(per=None):
decorate(traceLog(log))
def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidManager=None, uid=None, gid=None, personality=None, *args, **kargs):
"""execute given command outside of chroot"""
-
+
logger = kargs.get("logger", log)
logger.debug("Run cmd: %s" % command)
- def alarmhandler(signum,stackframe):
+ def alarmhandler(signum, stackframe):
raise commandTimeoutExpired("Timeout(%s) exceeded for command: %s" % (timeout, command))
-
+
retval = 0
logger.debug("Executing timeout(%s): %s" % (timeout, command))
- output=""
- (r,w) = os.pipe()
+ output = ""
+ (r, w) = os.pipe()
pid = os.fork()
if pid: #parent
rpid = ret = 0
os.close(w)
- oldhandler=signal.signal(signal.SIGALRM,alarmhandler)
+ oldhandler = signal.signal(signal.SIGALRM, alarmhandler)
# timeout=0 means disable alarm signal. no timeout
signal.alarm(timeout)
@@ -241,7 +243,7 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa
r_fh.close()
(rpid, ret) = os.waitpid(pid, 0)
signal.alarm(0)
- signal.signal(signal.SIGALRM,oldhandler)
+ signal.signal(signal.SIGALRM, oldhandler)
# kill children for any exception...
finally:
@@ -251,7 +253,7 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa
os.kill(-pid, signal.SIGKILL)
except OSError:
pass
- signal.signal(signal.SIGALRM,oldhandler)
+ signal.signal(signal.SIGALRM, oldhandler)
# mask and return just return value, plus child output
if raiseExc and os.WEXITSTATUS(ret):
@@ -268,7 +270,7 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa
os.close(r)
# become process group leader so that our parent
# can kill our children
- os.setpgrp()
+ os.setpgrp()
condPersonality(personality)
condChroot(chrootPath, uidManager)
@@ -282,6 +284,6 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa
w.write(line)
w.flush()
w.close()
- retval=child.wait()
+ retval = child.wait()
finally:
- os._exit(os.WEXITSTATUS(retval))
+ os._exit(os.WEXITSTATUS(retval))