~zeitgeist/zeitgeist/cleanup

« back to all changes in this revision

Viewing changes to zeitgeist-daemon.py

  • Committer: Siegfried-Angel Gevatter Pujals
  • Date: 2010-04-01 21:16:45 UTC
  • Revision ID: rainct@ubuntu.com-20100401211645-zavc9q5i1o2luq4v
zeitgeist-daemon: Add a --log-level switch (LP: #512115).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import gettext
27
27
import logging
28
28
import optparse
 
29
from copy import copy
29
30
 
30
31
from zeitgeist import _config
31
32
_config.setup_path()
32
33
 
33
34
gettext.install("zeitgeist", _config.localedir, unicode=1)
34
 
logging.basicConfig(level=logging.DEBUG)
35
 
 
36
 
parser = optparse.OptionParser(version = _config.VERSION)
 
35
 
 
36
def check_loglevel(option, opt, value):
 
37
        value = value.upper()
 
38
        if value in Options.log_levels:
 
39
                return value
 
40
        raise optparse.OptionValueError(
 
41
                "option %s: invalid value: %s" % (opt, value))
 
42
 
 
43
class Options(optparse.Option):
 
44
 
 
45
        TYPES = optparse.Option.TYPES + ("log_levels",)
 
46
        TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER)
 
47
        TYPE_CHECKER["log_levels"] = check_loglevel
 
48
 
 
49
        log_levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')
 
50
 
 
51
parser = optparse.OptionParser(version = _config.VERSION, option_class=Options)
37
52
parser.add_option(
38
53
        "-r", "--replace",
39
54
        action = "store_true", default=False, dest = "replace",
40
55
        help = _("if another Zeitgeist instance is already running, replace it"))
41
56
parser.add_option(
42
 
        "--no-datahub",
 
57
        "--no-datahub", "--no-passive-loggers",
43
58
        action = "store_false", default=True, dest = "start_datahub",
44
59
        help = _("do not start zeitgeist-datahub automatically"))
45
60
parser.add_option(
 
61
        "--log-level",
 
62
        action = "store", type="log_levels", default="DEBUG", dest="log_level",
 
63
        help = _("how much information should be printed; possible values:") + \
 
64
                " %s" % ', '.join(Options.log_levels))
 
65
parser.add_option(
46
66
        "--quit",
47
67
        action = "store_true", default=False, dest = "quit",
48
68
        help = _("if another Zeitgeist instance is already running, replace it"))
60
80
        print ' '.join(options)
61
81
        sys.exit(0)
62
82
 
 
83
logging.basicConfig(level=getattr(logging, _config.options.log_level))
 
84
 
63
85
from _zeitgeist.engine.remote import RemoteInterface
64
86
 
65
87
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)