From 14ed75647fdd7aed4330ce1c973ca84073bc1c19 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Fri, 20 Jul 2012 14:38:22 +0000 Subject: Introduce --cache-only boolean option, propagate to modules Along the way, add basic support for handling boolean values in python and shell scripts in modules. [dsd: trivial tweaks: renamed to --cache-only, use variable presence in environment for boolean testing, add documentation] --- diff --git a/doc/README b/doc/README index ad79946..7a46796 100644 --- a/doc/README +++ b/doc/README @@ -54,7 +54,31 @@ release was made. Usage: - olpc-os-builder [path to build config...] + olpc-os-builder [options] [path to build config...] + + +Offline use: + +olpc-os-builder naturally involves a fair amount of downloading in its work. +These downloads are cached, meaning that while the first run will do a lot +of downloading, subsequent runs will reuse the locally cached content. + +However, those subsequent runs will still go online in order to check that +cached content is up-to-date. This can be time consuming, especially +on slow connections. + +If you want olpc-os-builder to trust its local caches, and not even go +online to check that they are current, you can provide the --cache-only +command-line option. + +For obvious reasons, cache-only mode requires you to have previously run +the same build configuration in "normal" mode beforehand (i.e. without +--cache-only specified), so that caches are populated. + +Be aware that less cache validation is performed during --cache-only runs. +This means that corrupt caches or truncated files could be treated as good +in cache-only mode, whereas such problems are generally detected and +corrected when connectivity is used. Configuration: diff --git a/lib/ooblib.py b/lib/ooblib.py index 8d6dd2d..13babbc 100644 --- a/lib/ooblib.py +++ b/lib/ooblib.py @@ -17,6 +17,8 @@ fsmount = os.environ['OOB__fsmount'] METADATA_NS = "http://linux.duke.edu/metadata/common" +cacheonly = 'OOB__cacheonly' in os.environ + def read_config(module, option): vname = "CFG_%s__%s" % (module, option) if not vname in os.environ: diff --git a/lib/shlib.sh b/lib/shlib.sh index 34982b0..11324c2 100644 --- a/lib/shlib.sh +++ b/lib/shlib.sh @@ -7,6 +7,7 @@ libdir=$OOB__libdir bindir=$OOB__bindir builddir=$OOB__builddir cachedir=$OOB__cachedir +cacheonly=$OOB__cacheonly intermediatesdir=$OOB__intermediatesdir outputdir=$OOB__outputdir statedir=$OOB__statedir @@ -78,4 +79,3 @@ install_sugar_bundle() { mkdir -p "$intermediatesdir/shared/sugar-bundles" ln_or_cp "$1" "$intermediatesdir/shared/sugar-bundles" } - diff --git a/osbuilder.py b/osbuilder.py index 0cddd94..ce8e723 100755 --- a/osbuilder.py +++ b/osbuilder.py @@ -71,6 +71,9 @@ class Stage(object): env['oob_config_dir'] = os.path.dirname(self.osb.build_configs[0]) + if self.osb.cacheonly: + env['OOB__cacheonly'] = 'True' + envpath = env['PATH'].split(':') for dir in ('/sbin', '/usr/sbin'): if envpath.count(dir) == 0: @@ -278,6 +281,9 @@ class OsBuilder(object): self.statedir = os.path.join(self.builddir, 'state') self.fsmount = os.path.join(self.builddir, 'mnt-fs') + # gets set in build() + self.cacheonly = False + # load config to find module list # and set interpolation default for oob_config_dir self.cfg = SafeConfigParser({'oob_config_dir': @@ -363,13 +369,17 @@ class OsBuilder(object): # cleanup stage not listed here as its a bit of a special case ) - def build(self, clean_output=True, clean_intermediates=True): + def build(self, clean_output=True, clean_intermediates=True, cacheonly=False): # cleanup from previous runs if clean_intermediates and os.path.exists(self.intermediatesdir): shutil.rmtree(self.intermediatesdir) if clean_output and os.path.exists(self.outputdir): shutil.rmtree(self.outputdir) + self.cacheonly = cacheonly + if cacheonly and not os.path.exists(self.cachedir): + raise OsBuilderException("Missing cache, cannot use --cache-only") + for dir in (self.builddir, self.cachedir, self.intermediatesdir, self.outputdir, self.statedir, self.fsmount): if not os.path.exists(dir): @@ -407,6 +417,10 @@ def main(): op.add_option('--no-clean-intermediates', dest="clean_intermediates", action="store_false", default=True, help="Don't clean intermediates directory on startup or exit") + op.add_option('--cache-only', dest="cacheonly", + action="store_true", default=False, + help="Run entirely from cache") + (options, args) = op.parse_args() if len(args) < 1: @@ -415,7 +429,8 @@ def main(): try: osb = OsBuilder(args) osb.build(clean_output=options.clean_output, - clean_intermediates=options.clean_intermediates) + clean_intermediates=options.clean_intermediates, + cacheonly=options.cacheonly) except OsBuilderException, e: print >>sys.stderr, "ERROR:", e sys.exit(1) -- cgit v0.9.1