[jhbuild] use Python logging module to log messages
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Subject: [jhbuild] use Python logging module to log messages
- Date: Sat, 2 May 2009 08:07:55 -0400 (EDT)
commit 5f74bd4117bc2570fd69c154e583794da31a5f4a
Author: Frederic Peters <fpeters 0d be>
Date: Sat May 2 14:06:09 2009 +0200
use Python logging module to log messages
---
jhbuild/commands/base.py | 17 +++++++++--------
jhbuild/commands/bootstrap.py | 5 +++--
jhbuild/commands/checkmodulesets.py | 8 +++++---
jhbuild/config.py | 21 +++++++++++----------
jhbuild/main.py | 13 +++++++++++++
jhbuild/modtypes/tarball.py | 5 +++--
jhbuild/moduleset.py | 10 +++++-----
jhbuild/versioncontrol/git.py | 3 ++-
8 files changed, 51 insertions(+), 31 deletions(-)
diff --git a/jhbuild/commands/base.py b/jhbuild/commands/base.py
index 1d37925..50e53c0 100644
--- a/jhbuild/commands/base.py
+++ b/jhbuild/commands/base.py
@@ -23,6 +23,7 @@ import stat
import sys
import time
from optparse import make_option
+import logging
import jhbuild.moduleset
import jhbuild.frontends
@@ -157,8 +158,8 @@ class cmd_cleanone(Command):
self.parser.error(_('This command requires a module parameter.'))
if not config.makeclean:
- print >> sys.stderr, uencode(
- _('I: clean command called while makeclean is set to False, skipped.'))
+ logging.info(
+ _('clean command called while makeclean is set to False, skipped.'))
return 0
build = jhbuild.frontends.get_buildscript(config, module_list)
@@ -200,14 +201,14 @@ def check_bootstrap_updateness(config):
if max_install_date <= bootstrap_mtime:
# general note, to cover added modules
- print >> sys.stderr, uencode(
- _('I: bootstrap moduleset has been updated since the last time '\
+ logging.info(
+ _('bootstrap moduleset has been updated since the last time '\
'you used it, perhaps you should run jhbuild bootstrap.'))
if updated_modules:
# note about updated modules
- print >> sys.stderr, uencode(
- _('I: some bootstrap modules have been updated, '\
+ logging.info(
+ _('some bootstrap modules have been updated, '\
'perhaps you should update them: %s.') % \
', '.join(updated_modules))
@@ -325,8 +326,8 @@ class cmd_build(Command):
raise FatalError(_('%s not in module list') % options.startat)
if len(module_list) == 0 and modules[0] in (config.skip or []):
- print >> sys.stderr, uencode(
- _('I: requested module is in the ignore list, nothing to do.'))
+ logging.info(
+ _('requested module is in the ignore list, nothing to do.'))
return 0
build = jhbuild.frontends.get_buildscript(config, module_list)
diff --git a/jhbuild/commands/bootstrap.py b/jhbuild/commands/bootstrap.py
index 42e88f4..358ea83 100644
--- a/jhbuild/commands/bootstrap.py
+++ b/jhbuild/commands/bootstrap.py
@@ -21,6 +21,7 @@ import os
import sys
import urllib
from optparse import make_option
+import logging
import jhbuild.moduleset
import jhbuild.frontends
@@ -80,8 +81,8 @@ class cmd_bootstrap(cmd_build):
rc = cmd_build.run(self, config, options, args)
if ignored_modules:
- print >> sys.stderr, uencode(
- _('I: some modules (%s) were automatically ignored as a '
+ logging.info(
+ _('some modules (%s) were automatically ignored as a '
'sufficient enough version was found installed on '
'your system. Use --ignore-system if you want to build '
'them nevertheless.' % ', '.join(ignored_modules)))
diff --git a/jhbuild/commands/checkmodulesets.py b/jhbuild/commands/checkmodulesets.py
index 1a3620c..c0b27ff 100644
--- a/jhbuild/commands/checkmodulesets.py
+++ b/jhbuild/commands/checkmodulesets.py
@@ -21,6 +21,7 @@
import urllib2
from optparse import make_option
+import logging
import jhbuild.moduleset
from jhbuild.commands import Command, register_command
@@ -38,9 +39,10 @@ class cmd_checkmodulesets(Command):
try:
if not mod.branch.exists():
- uprint(_('E: %(module)s is unreachable (%(href)s)') % {'module': mod.name, 'href': mod.branch.module})
+ logging.error(_('%(module)s is unreachable (%(href)s)') % {
+ 'module': mod.name, 'href': mod.branch.module})
except NotImplementedError:
- if False:
- uprint(_('W: Cannot check %(module)s (%(href)s)') % {'module': mod.name, 'href': mod.branch.module})
+ logging.warning((_('Cannot check %(module)s (%(href)s)') % {
+ 'module': mod.name, 'href': mod.branch.module})
register_command(cmd_checkmodulesets)
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 94c43c4..3a966d5 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -22,6 +22,7 @@ import os
import sys
import traceback
import types
+import logging
from jhbuild.errors import UsageError, FatalError, CommandError
from jhbuild.utils.cmds import get_output
@@ -146,25 +147,25 @@ class Config:
continue
unknown_keys.append(k)
if unknown_keys:
- print >> sys.stderr, uencode(
- _('I: unknown keys defined in configuration file: %s') % \
+ logging.info(
+ _('unknown keys defined in configuration file: %s') % \
', '.join(unknown_keys))
# backward compatibility, from the days when jhbuild only
# supported Gnome.org CVS.
if config.get('cvsroot'):
- print >> sys.stderr, uencode(
- _('W: the "%s" configuration variable is deprecated, '
+ logging.warning(
+ _('the "%s" configuration variable is deprecated, '
'you should use "repos[\'gnome.org\']".') % 'cvsroot')
config['repos'].update({'gnome.org': config['cvsroot']})
if config.get('cvsroots'):
- print >> sys.stderr, uencode(
- _('W: the "%s" configuration variable is deprecated, '
+ logging.warning(
+ _('the "%s" configuration variable is deprecated, '
'you should use "repos".') % 'cvsroots')
config['repos'].update(config['cvsroots'])
if config.get('svnroots'):
- print >> sys.stderr, uencode(
- _('W: the "%s" configuration variable is deprecated, '
+ logging.warning(
+ _('the "%s" configuration variable is deprecated, '
'you should use "repos".') % 'svnroots')
config['repos'].update(config['svnroots'])
@@ -336,8 +337,8 @@ class Config:
try:
import curses
except ImportError:
- print >> sys.stderr, uencode(
- _('W: quiet mode has been disabled because the Python curses module is missing.'))
+ logging.warning(
+ _('quiet mode has been disabled because the Python curses module is missing.'))
v = False
self.__dict__[k] = v
diff --git a/jhbuild/main.py b/jhbuild/main.py
index 02271eb..03039d1 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -21,6 +21,7 @@
import sys, os, errno
import optparse
import traceback
+import logging
import gettext
localedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../mo'))
@@ -69,6 +70,14 @@ def uprint(*args):
__builtin__.__dict__['uprint'] = uprint
__builtin__.__dict__['uencode'] = uencode
+class LoggingFormatter(logging.Formatter):
+ def __init__(self):
+ logging.Formatter.__init__(self, '%(level_name_initial)s: %(message)s')
+
+ def format(self, record):
+ record.level_name_initial = record.levelname[0]
+ return logging.Formatter.format(self, record)
+
def help_commands(option, opt_str, value, parser):
thisdir = os.path.abspath(os.path.dirname(__file__))
@@ -92,6 +101,10 @@ def help_commands(option, opt_str, value, parser):
parser.exit()
def main(args):
+ logging.getLogger().setLevel(logging.INFO)
+ logging_handler = logging.StreamHandler()
+ logging_handler.setFormatter(LoggingFormatter())
+ logging.getLogger().addHandler(logging_handler)
parser = optparse.OptionParser(
usage=_('%prog [ -f config ] command [ options ... ]'),
description=_('Build a set of modules from diverse repositories in correct dependency order (such as GNOME).'))
diff --git a/jhbuild/modtypes/tarball.py b/jhbuild/modtypes/tarball.py
index d883498..bd0e96b 100644
--- a/jhbuild/modtypes/tarball.py
+++ b/jhbuild/modtypes/tarball.py
@@ -20,6 +20,7 @@
__metaclass__ = type
import sys
+import logging
from jhbuild.modtypes import register_module_type, get_dependencies
@@ -58,8 +59,8 @@ def parse_tarball(node, config, uri, repositories, default_repo):
try:
source_size = int(childnode.getAttribute('size'))
except ValueError:
- print >> sys.stderr, uencode(
- _('W: module \'%s\' has invalid size attribute (\'%s\')') % (
+ logging.warning(
+ _('module \'%s\' has invalid size attribute (\'%s\')') % (
name, childnode.getAttribute('size')))
if childnode.hasAttribute('md5sum'):
source_md5 = childnode.getAttribute('md5sum')
diff --git a/jhbuild/moduleset.py b/jhbuild/moduleset.py
index 7d6afe2..2022698 100644
--- a/jhbuild/moduleset.py
+++ b/jhbuild/moduleset.py
@@ -22,6 +22,7 @@ from __future__ import generators
import os
import sys
import urlparse
+import logging
from jhbuild.errors import UsageError, FatalError, DependencyCycleError, CommandError
@@ -52,8 +53,7 @@ class ModuleSet:
for module in self.modules.keys():
if module.lower() == module_name:
if self.config is None or not self.config.quiet_mode:
- print >> sys.stderr, uencode(
- _('I: fixed case of module \'%(orig)s\' to \'%(new)s\'') % {
+ logging.info(_('fixed case of module \'%(orig)s\' to \'%(new)s\'') % {
'orig': module_name, 'new': module})
return self.modules[module]
raise KeyError(module_name)
@@ -227,7 +227,7 @@ class ModuleSet:
try:
mod = self.modules[modname]
except KeyError:
- print >> sys.stderr, _('W: Unknown module:'), modname
+ logging.warning(_('Unknown module:') + ' '+ modname)
del modules[0]
continue
if isinstance(mod, MetaModule):
@@ -438,8 +438,8 @@ def warn_local_modulesets(config):
# no locally modified moduleset
return
- print >> sys.stderr, uencode(
- _('I: modulesets were edited locally but jhbuild is configured '\
+ logging.info(
+ _('modulesets were edited locally but jhbuild is configured '\
'to get them from subversion, perhaps you need to add '\
'use_local_modulesets = True to your .jhbuildrc.'))
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index b23d3bd..40f39e7 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -28,6 +28,7 @@ import subprocess
import re
import urllib
import sys
+import logging
from jhbuild.errors import FatalError, CommandError
from jhbuild.utils.cmds import get_output, check_version
@@ -84,7 +85,7 @@ class GitRepository(Repository):
try:
new_module, revision = self.config.branches.get(name)
except (ValueError, TypeError):
- print >> sys.stderr, _('W: ignored bad branch redefinition for module:'), name
+ logging.warning(_('ignored bad branch redefinition for module:') + ' ' + name)
else:
if new_module:
module = new_module
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]