| 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 | |
|---|
| 25 | import sys |
|---|
| 26 | import os |
|---|
| 27 | import traceback |
|---|
| 28 | import gettext |
|---|
| 29 | import locale |
|---|
| 30 | import __builtin__ |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | __builtin__._ = gettext.gettext |
|---|
| 34 | |
|---|
| 35 | try: |
|---|
| 36 | locale.setlocale(locale.LC_ALL, '') |
|---|
| 37 | except locale.Error, e: |
|---|
| 38 | print _('[*] WARNING: Selected locale not supported by your system. Using the fallback default locale') |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | # Itaka modules |
|---|
| 42 | try: |
|---|
| 43 | import console |
|---|
| 44 | import config as itaka_globals |
|---|
| 45 | import uigtk as igui |
|---|
| 46 | except ImportError: |
|---|
| 47 | print '[*] ERROR: Failed to import Itaka modules' |
|---|
| 48 | traceback.print_exc() |
|---|
| 49 | sys.exit(1) |
|---|
| 50 | |
|---|
| 51 | #: Locales directory |
|---|
| 52 | locale_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 |
|---|
| 55 | locale_prefix = "/usr/share/itaka/locale/" |
|---|
| 56 | |
|---|
| 57 | if os.path.exists(locale_prefix): |
|---|
| 58 | locale_dir = locale_prefix |
|---|
| 59 | |
|---|
| 60 | # See if our locales are there before starting |
|---|
| 61 | if not os.path.exists(locale_dir): |
|---|
| 62 | print_warning(_('Could not find locale directory %s, not using locales.' % (locale_dir))) |
|---|
| 63 | else: |
|---|
| 64 | gettext.bindtextdomain('itaka', locale_dir) |
|---|
| 65 | gettext.textdomain('itaka') |
|---|
| 66 | |
|---|
| 67 | validarguments = ('-h', '--help', '-v', '--version', '-r', '--revision', '-d', '--debug') |
|---|
| 68 | arguments = sys.argv |
|---|
| 69 | |
|---|
| 70 | if 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 | |
|---|
| 83 | try: |
|---|
| 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) |
|---|
| 96 | except: |
|---|
| 97 | print_error(_('Could not initiate Configuration engine')) |
|---|
| 98 | traceback.print_exc() |
|---|
| 99 | sys.exit(1) |
|---|
| 100 | |
|---|
| 101 | if __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 | |
|---|