diff -r 0b4e8c83e8a4 -r 4d853476701f autobuild/autobuild_main.py --- a/autobuild/autobuild_main.py Fri Feb 11 08:43:16 2011 -0500 +++ b/autobuild/autobuild_main.py Sun Feb 13 08:17:03 2011 -0500 @@ -26,6 +26,9 @@ import argparse import logging +## Environment variable name used for default log level verbosity +AUTOBUILD_LOGLEVEL = 'AUTOBUILD_LOGLEVEL' + class run_help(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): parser.parent.search_for_and_import_tools(parser.parent.tools_list) @@ -39,7 +42,7 @@ self.parser = argparse.ArgumentParser( description='Autobuild', prog='autobuild', add_help=False) - self.parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0') + self.parser.add_argument('-V', '--version', action='version', version='%(prog)s 1.0') self.subparsers = self.parser.add_subparsers(title='Sub Commands', description='Valid Sub Commands', @@ -86,10 +89,58 @@ instance = self.register_tool(possible_tool_module) return instance return -1 + + def get_default_loglevel_from_environment(self): + """ + Returns a default log level based on the AUTOBUILD_LOGLEVEL environment variable + + This may be used directly by the user, but in combination with the + set_recursive_loglevel method below also ensures + that any recursive invocation of autobuild inherits the same level as the + parent, even if intervening commands do not pass it through. + """ + try: + environment_level = os.environ[AUTOBUILD_LOGLEVEL] + except KeyError: + environment_level = '' + + if environment_level == '--quiet' or environment_level == '-q' : + return logging.ERROR + elif environment_level == '': + return logging.WARNING + elif environment_level == '--verbose' or environment_level == '-v' : + return logging.INFO + elif environment_level == '--debug' or environment_level == '-d' : + return logging.DEBUG + else: + raise AutobuildError("invalid %s value '%s'" % (AUTOBUILD_LOGLEVEL, environment_level)) + + def set_recursive_loglevel(self, logger, level): + """ + Sets the logger level, and also saves the equivalent option argument + in the AUTOBUILD_LOGLEVEL environment variable so that any recursive + invocation of autobuild uses the same level + """ + logger.setLevel(level) + + if level == logging.ERROR: + os.environ[AUTOBUILD_LOGLEVEL] = '--quiet' + elif level == logging.WARNING: + os.environ[AUTOBUILD_LOGLEVEL] = '' + elif level == logging.INFO: + os.environ[AUTOBUILD_LOGLEVEL] = '--verbose' + elif level == logging.DEBUG: + os.environ[AUTOBUILD_LOGLEVEL] = '--debug' + else: + raise common.AutobuildError("invalid effective log level %s" % logging.getLevelName(level)) def main(self, args_in): + logger = logging.getLogger('autobuild') + logger.addHandler(logging.StreamHandler()) + default_loglevel = self.get_default_loglevel_from_environment() + self.tools_list = [] self.parser.parent = self @@ -98,14 +149,18 @@ nargs='?', default=argparse.SUPPRESS) argdefs = ( - (('--dry-run',), + (('-n', '--dry-run',), dict(help='run tool in dry run mode if available', action='store_true')), - (('--quiet',), + + ## NOTE: if the mapping of verbosity controls (--{quiet,verbose,debug}) + ## is changed here, it must be changed to match in set_recursive_loglevel + ## and get_default_loglevel_from_environment methods above. + (('-q', '--quiet',), dict(help='minimal output', action='store_const', - const=logging.ERROR, dest='logging_level', default=logging.WARNING)), - (('--verbose',), + const=logging.ERROR, dest='logging_level', default=default_loglevel)), + (('-v', '--verbose',), dict(help='verbose output', action='store_const', const=logging.INFO, dest='logging_level')), - (('--debug',), + (('-d', '--debug',), dict(help='debug output', action='store_const', const=logging.DEBUG, dest='logging_level')), ) for args, kwds in argdefs: @@ -126,11 +181,9 @@ break args = self.parser.parse_args(args_in) - - logger = logging.getLogger('autobuild') - logger.setLevel(args.logging_level) - logger.addHandler(logging.StreamHandler()) - + + self.set_recursive_loglevel(logger, args.logging_level) + if tool_to_run != -1: tool_to_run.run(args) diff -r 0b4e8c83e8a4 -r 4d853476701f autobuild/autobuild_tool_install.py --- a/autobuild/autobuild_tool_install.py Fri Feb 11 08:43:16 2011 -0500 +++ b/autobuild/autobuild_tool_install.py Sun Feb 13 08:17:03 2011 -0500 @@ -243,6 +243,8 @@ # raise error if named package doesn't exist in autobuild.xml raise InstallError('unknown package: %s' % pname) + logger.warn("checking package %s" % pname) + # The --as-source command-line switch only affects the installation of # new packages. When we first install a package, we remember whether # it's --as-source. Every subsequent 'autobuild install' affecting @@ -260,16 +262,16 @@ # do not mess with it now. source_install = installed.as_source if source_install: - logger.info("%s previously installed --as-source, not updating" % pname) + logger.warn("%s previously installed --as-source, not updating" % pname) continue # Existing tarball install, or new package install of either kind if source_install: - logger.info("installing %s --as-source" % pname) + logger.warn("installing %s --as-source" % pname) if _install_source(package, installed_file, config_file, dry_run): installed_pkgs.append(pname) else: - logger.info("installing %s from archive" % pname) + logger.warn("installing %s from archive" % pname) if _install_binary(package, platform, config_file, install_dir, installed_file, dry_run): installed_pkgs.append(pname) return installed_pkgs @@ -302,7 +304,7 @@ except OSError, err: if err.errno != errno.EEXIST: raise - logger.info("checking out %s from %s to %s" % (package.name, package.source, sourcepath)) + logger.warn("checking out %s from %s to %s" % (package.name, package.source, sourcepath)) if package.sourcetype == 'svn': command = ['svn', 'checkout', package.source, sourcepath] logger.debug(' '.join(command)) @@ -356,9 +358,10 @@ # download the package, if it's not already in our cache if os.path.exists(cachefile): - logger.info("found in cache: " + cachefile) + logger.debug("found in cache: " + cachefile) else: # download the package to the cache + logger.warn("downloading %s archive from %s" % (package.name, archive.url)) if not common.download_package(archive.url): # Download failure has been observed to leave a zero-length file. common.remove_package(archive.url) @@ -380,13 +383,14 @@ # check that the install dir exists... if not os.path.exists(install_dir): - logger.info("creating " + install_dir) + logger.debug("creating " + install_dir) os.makedirs(install_dir) # extract the files from the package + logger.warn("extracting %s" % (package.name)) files = common.extract_package(archive.url, install_dir) for f in files: - logger.info("extracted: " + f) + logger.debug("extracted: " + f) # Update the installed-packages.xml file. The above uninstall() call # should have removed any existing entry in installed_file. Copy @@ -426,7 +430,7 @@ package = installed_config.installables.pop(package_name) except KeyError: # If the package has never yet been installed, we're good. - logger.info("%s not installed, no uninstall needed" % package_name) + logger.debug("%s not installed, no uninstall needed" % package_name) return if package.as_source: @@ -434,7 +438,8 @@ logger.warning("%s installed --as-source, not removing" % package_name) return - logger.info("uninstalling %s from %s" % (package_name, package.install_dir)) + logger.warn("uninstalling %s" % (package_name)) + logger.debug("uninstalling %s from %s" % (package_name, package.install_dir)) # The platforms attribute should contain exactly one PlatformDescription. # We don't especially care about its key name. _, platform = package.platforms.popitem() @@ -452,7 +457,7 @@ # traceback. But there are a couple different ways we could get # through this logic without actually deleting. So produce a # message only when we're sure we've actually deleted something. - logger.info(" removed " + f) + logger.debug(" removed " + f) except OSError, err: if err.errno == errno.ENOENT: # this file has already been deleted for some reason -- fine @@ -472,7 +477,7 @@ # Okay, it's a directory, remove it with rmdir(). try: os.rmdir(fn) - logger.info(" removed " + f) + logger.debug(" removed " + f) except OSError, err: # We try to remove directories named in the install # archive in case these directories were created solely @@ -482,7 +487,7 @@ # contains files. if err.errno != errno.ENOTEMPTY: raise - logger.info(" leaving " + f) + logger.debug(" leaving " + f) else: # no idea what this exception is, better let it propagate raise @@ -494,10 +499,10 @@ # write packages into 'packages' subdir of build directory by default if options.install_dir: - logger.info("specified install directory: " + options.install_dir) + logger.debug("specified install directory: " + options.install_dir) else: options.install_dir = os.path.join(config_file.make_build_directory(), 'packages') - logger.info("default install directory: " + options.install_dir) + logger.debug("default install directory: " + options.install_dir) # get the absolute paths to the install dir and installed-packages.xml file install_dir = os.path.realpath(options.install_dir) diff -r 0b4e8c83e8a4 -r 4d853476701f autobuild/autobuild_tool_source_environment.py --- a/autobuild/autobuild_tool_source_environment.py Fri Feb 11 08:43:16 2011 -0500 +++ b/autobuild/autobuild_tool_source_environment.py Sun Feb 13 08:17:03 2011 -0500 @@ -285,7 +285,7 @@ # called by autobuild to add help and options to the autobuild parser, and # by standalone code to set up argparse def register(self, parser): - parser.add_argument('-v', '--version', action='version', version='source_environment tool module 1.0') + parser.add_argument('-V', '--version', action='version', version='source_environment tool module 1.0') def run(self, args): do_source_environment(args) diff -r 0b4e8c83e8a4 -r 4d853476701f autobuild/common.py --- a/autobuild/common.py Fri Feb 11 08:43:16 2011 -0500 +++ b/autobuild/common.py Sun Feb 13 08:17:03 2011 -0500 @@ -263,7 +263,7 @@ return False # Attempt to extract the package from the install cache - logger.info("extracting %s to %s" % (cachename, install_dir)) + logger.debug("extracting from %s" % cachename) tar = tarfile.open(cachename, 'r') try: # try to call extractall in python 2.5. Phoenix 2008-01-28 diff -r 0b4e8c83e8a4 -r 4d853476701f autobuild/configfile.py --- a/autobuild/configfile.py Fri Feb 11 08:43:16 2011 -0500 +++ b/autobuild/configfile.py Sun Feb 13 08:17:03 2011 -0500 @@ -203,7 +203,7 @@ for (name, package) in installables.iteritems(): self.installables[name] = PackageDescription(package) self.update(saved_data) - logger.info("Configuration file '%s'" % self.path) + logger.debug("Configuration file '%s'" % self.path) else: if saved_data['version'] in update.updaters: update.updaters[saved_data['version']](saved_data, self)