diff options
| author | Michael E Brown <michael_e_brown@dell.com> | 2007-11-28 15:22:40 -0600 |
|---|---|---|
| committer | Michael E Brown <michael_e_brown@dell.com> | 2007-11-28 15:22:40 -0600 |
| commit | 104bdd6a23e0eb3d4d02255fd357a6ccb158773b (patch) | |
| tree | 8de126115fbc46750f1c1c3ea0e99cc5e3ae27f5 /src | |
| parent | 075a03dbee52860bc70f379fefc7de215906d93e (diff) | |
| download | mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.tar.gz mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.tar.xz mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.zip | |
first (untested) try at adding offline mode.
Diffstat (limited to 'src')
| -rwxr-xr-x | src/mock.py | 11 | ||||
| -rw-r--r-- | src/py-libs/backend.py | 11 | ||||
| -rw-r--r-- | src/py-libs/plugins/yum_cache.py | 36 |
3 files changed, 36 insertions, 22 deletions
diff --git a/src/mock.py b/src/mock.py index bee4d11..2eb3089 100755 --- a/src/mock.py +++ b/src/mock.py @@ -82,6 +82,9 @@ def command_parse(config_opts): help="chroot name/config file name default: %default", default='default') + parser.add_option("--offline", action="store_false", dest="online", default=True + help="activate 'offline' mode.") + parser.add_option("--no-clean", action ="store_false", dest="clean", help="do not clean chroot before building", default=True) parser.add_option("--cleanup-after", action ="store_true", dest="cleanup_after", @@ -149,7 +152,11 @@ def setup_default_config_opts(config_opts): 'ccache_enable': True, 'ccache_opts': {'max_cache_size': "4G", 'dir': "%(cache_topdir)s/%(root)s/ccache/"}, 'yum_cache_enable': True, - 'yum_cache_opts': {'max_age_days': 30, 'dir': "%(cache_topdir)s/%(root)s/yum_cache/"}, + 'yum_cache_opts': { + 'max_age_days': 30, + 'max_metadata_age_days': 30, + 'dir': "%(cache_topdir)s/%(root)s/yum_cache/", + 'online': True,}, 'root_cache_enable': True, 'root_cache_opts': {'max_age_days': 15, 'dir': "%(cache_topdir)s/%(root)s/root_cache/"}, 'bind_mount_enable': True, @@ -315,7 +322,7 @@ def main(retParams): chroot.clean() elif options.mode in ('chroot', 'shell'): - chroot.init() + chroot.tryLockBuildRoot() chroot._mountall() try: if config_opts['internal_setarch']: diff --git a/src/py-libs/backend.py b/src/py-libs/backend.py index 19ea723..ebb1624 100644 --- a/src/py-libs/backend.py +++ b/src/py-libs/backend.py @@ -74,6 +74,7 @@ class Root(object): self.cache_topdir = config['cache_topdir'] self.cachedir = os.path.join(self.cache_topdir, self.sharedRootName) self.useradd = config['useradd'] + self.online = config['online'] self.plugins = config['plugins'] self.pluginConf = config['plugin_conf'] @@ -451,7 +452,11 @@ class Root(object): def _yum(self, cmd, returnOutput=0): """use yum to install packages/package groups into the chroot""" # mock-helper yum --installroot=rootdir cmd - cmd = '%s --installroot %s %s' % (self.yum_path, self.rootdir, cmd) + cmdOpts = "" + if not self.online: + cmdOpts = "-C" + + cmd = '%s --installroot %s %s %s' % (self.yum_path, self.rootdir, cmdOpts, cmd) self.root_log.info(cmd) try: self._callHooks("preyum") @@ -506,7 +511,7 @@ class Root(object): @traceLog(moduleLog) def _buildDirSetup(self): # create all dirs as the user who will be dropping things there. - self.uidManager.becomeUser(self.chrootuid) + self.uidManager.becomeUser(self.chrootuid, self.chrootgid) try: # create dir structure for subdir in ["%s/%s/%s" % (self.rootdir, self.builddir, s) for s in ('RPMS', 'SRPMS', 'SOURCES', 'SPECS', 'BUILD', 'originals')]: @@ -534,7 +539,7 @@ class Root(object): # @traceLog(moduleLog) def _copySrpmIntoChroot(self, srpm): - self.uidManager.becomeUser(self.chrootuid) + self.uidManager.becomeUser(self.chrootuid, self.chrootgid) try: srpmFilename = os.path.basename(srpm) dest = self.rootdir + '/' + self.builddir + '/' + 'originals' diff --git a/src/py-libs/plugins/yum_cache.py b/src/py-libs/plugins/yum_cache.py index 230a1a2..72497ff 100644 --- a/src/py-libs/plugins/yum_cache.py +++ b/src/py-libs/plugins/yum_cache.py @@ -31,6 +31,7 @@ class YumCache(object): self.yumSharedCachePath = self.yum_cache_opts['dir'] % self.yum_cache_opts self.state = rootObj.state self.rootdir = rootObj.rootdir + self.online = rootObj.online rootObj.yum_cacheObj = self rootObj.addHook("preyum", self._yumCachePreYumHook) rootObj.addHook("postyum", self._yumCachePostYumHook) @@ -68,24 +69,25 @@ class YumCache(object): self.yumCacheLock = open(os.path.join(self.yumSharedCachePath, "yumcache.lock"), "a+") self._yumCachePreYumHook() - self.state("enabled yum cache, cleaning yum metadata") - for (dirpath, dirnames, filenames) in os.walk(self.yumSharedCachePath): - for filename in filenames: - fullPath = os.path.join(dirpath, filename) - statinfo = os.stat(fullPath) - file_age_days = (time.time() - statinfo.st_ctime) / (60 * 60 * 24) - # prune repodata so yum redownloads. - # prevents certain errors where yum gets stuck due to bad metadata - for ext in (".sqllite", ".xml", ".bz2", ".gz"): - if filename.endswith(ext) and file_age_days > 1: + if self.online: + self.state("enabled yum cache, cleaning yum metadata") + for (dirpath, dirnames, filenames) in os.walk(self.yumSharedCachePath): + for filename in filenames: + fullPath = os.path.join(dirpath, filename) + statinfo = os.stat(fullPath) + file_age_days = (time.time() - statinfo.st_ctime) / (60 * 60 * 24) + # prune repodata so yum redownloads. + # prevents certain errors where yum gets stuck due to bad metadata + for ext in (".sqllite", ".xml", ".bz2", ".gz"): + if filename.endswith(ext) and file_age_days > self.yum_cache_opts['max_metadata_age_days']: + os.unlink(fullPath) + fullPath = None + break + + if fullPath is None: continue + if file_age_days > self.yum_cache_opts['max_age_days']: os.unlink(fullPath) - fullPath = None - break - - if fullPath is None: continue - if file_age_days > self.yum_cache_opts['max_age_days']: - os.unlink(fullPath) - continue + continue self._yumCachePostYumHook() |
