File: activity-log-manager

package info (click to toggle)
activity-log-manager 0.8.0-1.2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 160 kB
  • sloc: python: 735; makefile: 2
file content (88 lines) | stat: -rwxr-xr-x 3,281 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /usr/bin/env python
# -.- coding: utf-8 -.-
#
# Activity Log Manager for Zeitgeist
#
# Copyright © 2011 Stefano Candori <stefano.candori@gmail.com>
# Copyright © 2011 Collabora Ltd.
#             By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
# Copyright © 2010 Markus Korn <thekorn@gmx.de>
# Copyright © 2010 Siegfried Gevatter <siegfried@gevatter.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import gtk
import logging
import gettext
import optparse

# Where this file lives
our_dir = os.path.abspath(os.path.dirname(__file__))

# If this is a system-wide installation, as indicated by this file
# residing in $prefix/bin, we expect to find the remaining code
# in $prefix/share/gnome-activity-journal/.
BASE_PATH = our_dir if os.path.basename(our_dir) != 'bin' else \
    os.path.join(os.path.dirname(our_dir), 'share/activity-log-manager')
sys.path.insert(0, os.path.join(BASE_PATH, 'src'))

VERSION = "0.8.0"

logging.basicConfig(level=logging.DEBUG)

class Options(optparse.Option):
    TYPES = optparse.Option.TYPES + ("log_levels",)
    TYPE_CHECKER = optparse.Option.TYPE_CHECKER.copy()
    log_levels = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL")

    def check_loglevel(option, opt, value):
        value = value.upper()
        if value in Options.log_levels:
            return value
        raise optparse.OptionValueError(
            _("option %s: invalid value: %s") % (opt, value))
    TYPE_CHECKER["log_levels"] = check_loglevel

def parse_commandline():
    parser = optparse.OptionParser(version = VERSION, option_class=Options)
    parser.add_option(
        "--log-level",
        action="store", type="log_levels", default="DEBUG", dest="log_level",
        help=_("how much information should be printed; possible values:") + \
            " %s" % ", ".join(Options.log_levels))
    return parser

if __name__ == '__main__':
    # Import zeitgeist.datamodel before running gettext.install, so that it
    # doesn't override the location we set (ie., "build/mo").
    from zeitgeist import datamodel

    gettext_path = os.path.join(BASE_PATH, "build/mo")
    if not os.path.isdir(gettext_path):
        gettext_path = os.path.join(BASE_PATH, "../locale")

    gettext.bindtextdomain('activity-log-manager', gettext_path)
    gettext.textdomain('activity-log-manager')
    gettext.install('activity-log-manager', gettext_path, unicode=True)

    options, arguments = parse_commandline().parse_args()
    logging.getLogger().setLevel(getattr(logging, options.log_level))
    
    # We can't import any UI until after setting up gettext
    from window import Window
    
    window = Window()
    gtk.main()