~jacseen/keryx/unstable

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
#!/usr/bin/python
# -*- coding: utf-8 -*-
### BEGIN LICENSE
# Author: Chris Oliver (excid3@gmail.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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
### END LICENSE

import locale
import gtk
import gettext
import sys
import os

# Check if we are working in the source tree or from the installed 
# package and mangle the python path accordingly
if os.path.dirname(sys.argv[0]) != ".": 
    if sys.argv[0][0] == "/":  # If they've given the full path...
        fullPath = os.path.dirname(sys.argv[0])
    else:
        fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0])
else:
    fullPath = os.getcwd()
sys.path.insert(0, os.path.dirname(fullPath))


if __name__ == "__main__":
    # Get translations working.
    gettext.install('keryx', unicode=True)

    from keryx import config, consts

    # Load config.
    config.fromFile(consts.file_config)

    # Get all the stuff we'll be needing.
    from keryx.GTKKeryx import NewKeryxWindow
    from keryx.CLIKeryx import CLIKeryx
    from keryx.keryxconfig import getdatapath

    #support for command line options
    import logging, optparse
    parser = optparse.OptionParser(version="%prog %ver")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", 
                      help=_("Show debug messages"))
    parser.add_option("-c", "--cli", action="store_true", dest="cli", 
                      help=_("Use the command line interface"))
    (options, args) = parser.parse_args()

    #set the logging level to show debug messages
    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)
        logging.debug('logging enabled')
    if options.cli:
        cli = CLIKeryx()
        cli.start()
    else:
        window = NewKeryxWindow()
        window.show()
        gtk.main()