source: trunk/itaka.py @ 276

Revision 276, 3.6 KB checked in by marc, 3 years ago (diff)

Better fallback to default locale

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
Line 
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Itaka is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# any later version.
8#
9# Itaka is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Itaka; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17#
18# Copyright 2003-2009 Marc E.
19# http://itaka.jardinpresente.com.ar
20#
21# $Id$
22
23""" Itaka core """
24
25import sys
26import os
27import traceback
28import gettext
29import locale
30import __builtin__
31
32
33__builtin__._ = gettext.gettext
34
35try:
36    locale.setlocale(locale.LC_ALL, '')
37except locale.Error, e:
38    print _('[*] WARNING: Selected locale not supported by your system. Using the fallback default locale')
39
40
41# Itaka modules
42try:
43    import console
44    import config as itaka_globals
45    import uigtk as igui
46except ImportError:
47    print '[*] ERROR: Failed to import Itaka modules'
48    traceback.print_exc()
49    sys.exit(1)
50
51#: Locales directory
52locale_dir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'locale/')
53
54#: To be changed on install to specify where the installed files actually are
55locale_prefix = "/usr/share/itaka/locale/"
56
57if os.path.exists(locale_prefix):
58    locale_dir = locale_prefix
59
60# See if our locales are there before starting
61if not os.path.exists(locale_dir):
62    print_warning(_('Could not find locale directory %s, not using locales.' % (locale_dir)))
63else:
64    gettext.bindtextdomain('itaka', locale_dir)
65    gettext.textdomain('itaka')
66
67validarguments = ('-h', '--help', '-v', '--version', '-r', '--revision', '-d', '--debug')
68arguments = sys.argv
69
70if len(arguments) >= 2 and ((arguments[-1] not in validarguments) or (arguments[-1] in (validarguments[0], validarguments[1]))):
71    print _("""Usage:
72  %s [OPTION...]
73
74  Help Options:
75  -h, --help\t\t\t\tShow help options
76  -v, --version\t\t\t\tShow Itaka version
77  -r, --revision\t\t\tShow Itaka revision
78
79  Application Options:
80  -d, --debug\t\t\t\tStart in debug mode""") % arguments[0]
81    sys.exit(1)
82
83try:
84    # Initiate our Console and Configuration engines
85    config_instance = itaka_globals.ConfigParser(arguments)
86    config_instance.load()
87
88    try:
89        # Initiate console with a reference to our global configuration values,
90        # not the user's configuration
91        console_instance = console.Console(itaka_globals)
92    except:
93        print_error(_('Could not initiate Console engine'))
94        traceback.print_exc()
95        sys.exit(1)
96except:
97    print_error(_('Could not initiate Configuration engine'))
98    traceback.print_exc()
99    sys.exit(1)
100
101if __name__ == "__main__":
102    if len(arguments) >= 2:
103        if (arguments[-1] in (validarguments[2], validarguments[3])):
104            print itaka_globals.__version__
105            sys.exit(0)
106        if (arguments[-1] in (validarguments[4], validarguments[5])):
107            print "r" + itaka_globals.__revision__.split()[1]
108            sys.exit(0)
109
110    try:
111        gui = igui.Gui(console_instance, (itaka_globals, config_instance))
112        gui.main()
113    except Exception, e:
114        console_instance.failure(('Itaka', 'core'), _('Could not initiate GUI: %s') % (e), 'ERROR')
115        if itaka_globals.console_verbosity['debug']:
116            traceback.print_exc()
117        sys.exit(1)
118
Note: See TracBrowser for help on using the repository browser.