summaryrefslogtreecommitdiffstats
path: root/py/mock
diff options
context:
space:
mode:
authorMichael E Brown <mebrown@michaels-house.net>2007-12-01 13:25:11 -0600
committerMichael E Brown <mebrown@michaels-house.net>2007-12-01 13:25:11 -0600
commit315fd0b88b0c263e83bcc47fbeb242c38ed01d02 (patch)
treef3fd41047a82137defea5899e74a7f8962804033 /py/mock
parent42b1c5f9a0b81d0d0c10a07e23c446ac78e8f98b (diff)
downloadmock-315fd0b88b0c263e83bcc47fbeb242c38ed01d02.tar.gz
mock-315fd0b88b0c263e83bcc47fbeb242c38ed01d02.tar.xz
mock-315fd0b88b0c263e83bcc47fbeb242c38ed01d02.zip
convert @decorator-syntax to use python-2.3 compatible peak decoratortools syntax.
Diffstat (limited to 'py/mock')
-rw-r--r--py/mock/backend.py41
-rw-r--r--py/mock/uid.py17
-rw-r--r--py/mock/util.py27
3 files changed, 44 insertions, 41 deletions
diff --git a/py/mock/backend.py b/py/mock/backend.py
index 06932c9..463f69c 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -14,6 +14,7 @@ import os
import shutil
import stat
import time
+from peak.util.decorators import decorate
# our imports
import mock.util
@@ -26,7 +27,7 @@ moduleLog = logging.getLogger("mock")
# classes
class Root(object):
"""controls setup of chroot environment"""
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def __init__(self, config, uidManager):
self._state = 'unstarted'
self.uidManager = uidManager
@@ -108,14 +109,14 @@ class Root(object):
# =============
# 'Public' API
# =============
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def addHook(self, stage, function):
hooks = self._hooks.get(stage, [])
if function not in hooks:
hooks.append(function)
self._hooks[stage] = hooks
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def state(self, newState = None):
if newState is not None:
self._state = newState
@@ -123,7 +124,7 @@ class Root(object):
return self._state
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def clean(self):
"""clean out chroot with extreme prejudice :)"""
self.tryLockBuildRoot()
@@ -131,7 +132,7 @@ class Root(object):
mock.util.rmtree(self.basedir)
self.chrootWasCleaned = True
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def tryLockBuildRoot(self):
self.state("lock buildroot")
try:
@@ -146,7 +147,7 @@ class Root(object):
return 1
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def init(self):
self.state("init")
@@ -256,7 +257,7 @@ class Root(object):
# done with init
self._callHooks('postinit')
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _setupDev(self):
# files in /dev
mock.util.rmtree(os.path.join(self.rootdir, "dev"))
@@ -293,12 +294,12 @@ class Root(object):
if mntCmd not in self.mountCmds:
self.mountCmds.append(mntCmd)
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def doChroot(self, command, env="", *args, **kargs):
"""execute given command in root"""
return mock.util.do( command, personality=self.personality, chrootPath=self.rootdir, *args, **kargs )
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def yumInstall(self, *srpms):
"""figure out deps from srpm. call yum to install them"""
# pass build reqs (as strings) to installer
@@ -308,7 +309,7 @@ class Root(object):
finally:
self._umountall()
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def installSrpmDeps(self, *srpms):
"""figure out deps from srpm. call yum to install them"""
arg_string = self.preExistingDeps
@@ -344,7 +345,7 @@ class Root(object):
# Everything in this function runs as the build user
# -> except hooks. :)
#
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def build(self, srpm, timeout):
"""build an srpm into binary rpms, capture log"""
@@ -425,13 +426,13 @@ class Root(object):
# =============
# 'Private' API
# =============
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _callHooks(self, stage):
hooks = self._hooks.get(stage, [])
for hook in hooks:
hook()
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _initPlugins(self):
# Import plugins (simplified copy of what yum does). Can add yum
# features later when we prove we need them.
@@ -448,21 +449,21 @@ class Root(object):
module.init(self, self.pluginConf["%s_opts" % modname])
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _mountall(self):
"""mount 'normal' fs like /dev/ /proc/ /sys"""
for cmd in self.mountCmds:
self.root_log.debug(cmd)
mock.util.do(cmd)
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _umountall(self):
"""umount all mounted chroot fs."""
for cmd in self.umountCmds:
self.root_log.debug(cmd)
mock.util.do(cmd, raiseExc=0)
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _yum(self, cmd, returnOutput=0):
"""use yum to install packages/package groups into the chroot"""
# mock-helper yum --installroot=rootdir cmd
@@ -481,7 +482,7 @@ class Root(object):
except mock.exception.Error, e:
raise mock.exception.YumError, str(e)
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _makeBuildUser(self):
if not os.path.exists(os.path.join(self.rootdir, 'usr/sbin/useradd')):
raise mock.exception.RootError, "Could not find useradd in chroot, maybe the install failed?"
@@ -497,7 +498,7 @@ class Root(object):
self.doChroot(self.useradd % dets)
self.doChroot("perl -p -i -e 's/^(%s:)!!/$1/;' /etc/passwd" % (self.chrootuser), raiseExc=True)
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _resetLogging(self):
# ensure we dont attach the handlers multiple times.
if getattr(self, "logging_initialized", None):
@@ -522,7 +523,7 @@ class Root(object):
# UNPRIVLEGED:
# Everything in this function runs as the build user
#
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _buildDirSetup(self):
# create all dirs as the user who will be dropping things there.
self.uidManager.becomeUser(self.chrootuid, self.chrootgid)
@@ -551,7 +552,7 @@ class Root(object):
# UNPRIVLEGED:
# Everything in this function runs as the build user
#
- @traceLog(moduleLog)
+ decorate(traceLog(moduleLog))
def _copySrpmIntoChroot(self, srpm):
srpmFilename = os.path.basename(srpm)
dest = self.rootdir + '/' + self.builddir + '/' + 'originals'
diff --git a/py/mock/uid.py b/py/mock/uid.py
index 5b7b866..241f77a 100644
--- a/py/mock/uid.py
+++ b/py/mock/uid.py
@@ -6,6 +6,7 @@
# python library imports
import logging
import os
+from peak.util.decorators import decorate
# our imports
from mock.trace_decorator import traceLog
@@ -15,25 +16,25 @@ log = logging.getLogger("mock.uid")
# class
class uidManager(object):
- @traceLog(log)
+ decorate(traceLog(log))
def __init__(self, unprivUid=-1, unprivGid=-1):
self.privStack = []
self.unprivUid = unprivUid
self.unprivGid = unprivGid
- @traceLog(log)
+ decorate(traceLog(log))
def becomeUser(self, uid, gid=-1):
# save current ruid, euid, rgid, egid
self._push()
self._becomeUser(uid, gid)
- @traceLog(log)
+ decorate(traceLog(log))
def dropPrivsTemp(self):
# save current ruid, euid, rgid, egid
self._push()
self._becomeUser(self.unprivUid, self.unprivGid)
- @traceLog(log)
+ decorate(traceLog(log))
def restorePrivs(self):
# back to root first
self._elevatePrivs()
@@ -43,13 +44,13 @@ class uidManager(object):
os.setregid(privs['rgid'], privs['egid'])
setresuid(privs['ruid'], privs['euid'])
- @traceLog(log)
+ decorate(traceLog(log))
def dropPrivsForever(self):
self._elevatePrivs()
os.setregid(self.unprivGid, self.unprivGid)
os.setreuid(self.unprivUid, self.unprivUid)
- @traceLog(log)
+ decorate(traceLog(log))
def _push(self):
# save current ruid, euid, rgid, egid
self.privStack.append({
@@ -59,12 +60,12 @@ class uidManager(object):
"egid": os.getegid(),
})
- @traceLog(log)
+ decorate(traceLog(log))
def _elevatePrivs(self):
setresuid(0, 0, 0)
os.setregid(0, 0)
- @traceLog(log)
+ decorate(traceLog(log))
def _becomeUser(self, uid, gid=None):
self._elevatePrivs()
if gid is not None:
diff --git a/py/mock/util.py b/py/mock/util.py
index b47f57c..4c5dbb6 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -16,6 +16,7 @@ import rpmUtils.transaction
import shutil
import signal
import time
+from peak.util.decorators import decorate
# our imports
import mock.exception
@@ -32,7 +33,7 @@ class commandTimeoutExpired(mock.exception.Error):
self.resultcode = 10
# functions
-@traceLog(log)
+decorate(traceLog(log))
def mkdirIfAbsent(*args):
for dir in args:
log.debug("ensuring that dir exists: %s" % dir)
@@ -44,13 +45,13 @@ def mkdirIfAbsent(*args):
log.exception("Could not create dir %s. Error: %s" % (dir, e))
raise mock.exception.Error, "Could not create dir %s. Error: %s" % (dir, e)
-@traceLog(log)
+decorate(traceLog(log))
def touch(fileName):
log.debug("touching file: %s" % fileName)
fo = open(fileName, 'w')
fo.close()
-@traceLog(log)
+decorate(traceLog(log))
def rmtree(path, *args, **kargs):
"""version os shutil.rmtree that ignores no-such-file-or-directory errors,
and tries harder if it finds immutable files"""
@@ -72,7 +73,7 @@ def rmtree(path, *args, **kargs):
else:
raise
-@traceLog(log)
+decorate(traceLog(log))
def orphansKill(rootToKill):
"""kill off anything that is still chrooted."""
for fn in os.listdir("/proc"):
@@ -85,7 +86,7 @@ def orphansKill(rootToKill):
pass
-@traceLog(log)
+decorate(traceLog(log))
def yieldSrpmHeaders(srpms, plainRpmOk=0):
ts = rpmUtils.transaction.initReadOnlyTransaction()
for srpm in srpms:
@@ -99,7 +100,7 @@ def yieldSrpmHeaders(srpms, plainRpmOk=0):
yield hdr
-@traceLog(log)
+decorate(traceLog(log))
def requiresTextFromHdr(hdr):
"""take a header and hand back a unique'd list of the requires as
strings"""
@@ -120,7 +121,7 @@ def requiresTextFromHdr(hdr):
return rpmUtils.miscutils.unique(reqlist)
-@traceLog(log)
+decorate(traceLog(log))
def getNEVRA(hdr):
name = hdr[rpm.RPMTAG_NAME]
ver = hdr[rpm.RPMTAG_VERSION]
@@ -130,7 +131,7 @@ def getNEVRA(hdr):
if epoch is None: epoch = 0
return (name, epoch, ver, rel, arch)
-@traceLog(log)
+decorate(traceLog(log))
def getAddtlReqs(hdr, conf):
# Add the 'more_buildreqs' for this SRPM (if defined in config file)
(name, epoch, ver, rel, arch) = getNEVRA(hdr)
@@ -148,14 +149,14 @@ def getAddtlReqs(hdr, conf):
return rpmUtils.miscutils.unique(reqlist)
-@traceLog(log)
+decorate(traceLog(log))
def uniqReqs(*args):
master = []
for l in args:
master.extend(l)
return rpmUtils.miscutils.unique(master)
-@traceLog(log)
+decorate(traceLog(log))
def condChroot(chrootPath, uidManager=None):
if chrootPath is not None:
if uidManager:
@@ -167,7 +168,7 @@ def condChroot(chrootPath, uidManager=None):
log.debug("back to other privs")
uidManager.restorePrivs()
-@traceLog(log)
+decorate(traceLog(log))
def condDropPrivs(uidManager, uid, gid):
if uidManager is not None:
log.debug("about to drop privs")
@@ -189,7 +190,7 @@ personality_defs['ppc64'] = 0x0000
personality_defs['i386'] = 0x0008
personality_defs['ppc'] = 0x0008
-@traceLog(log)
+decorate(traceLog(log))
def condPersonality(per=None):
if personality_defs.get(per,None) is None: return
import ctypes
@@ -204,7 +205,7 @@ def condPersonality(per=None):
#
# Warning: this is the function from hell. :(
#
-@traceLog(log)
+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"""