| 1 | #! /usr/bin/env python |
|---|
| 2 | # -*- coding: utf8 -*- |
|---|
| 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 2 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, traceback |
|---|
| 26 | |
|---|
| 27 | validarguments = ('-h', '--help', '-v', '--version', '-r', '--revision', '-d', '--debug') |
|---|
| 28 | arguments = sys.argv |
|---|
| 29 | |
|---|
| 30 | # Only one option at a time |
|---|
| 31 | if len(arguments) >= 2 and ((arguments[-1] not in validarguments) or (arguments[-1] in (validarguments[0], validarguments[1]))): |
|---|
| 32 | print """Usage: |
|---|
| 33 | %s [OPTION...] |
|---|
| 34 | |
|---|
| 35 | Help Options: |
|---|
| 36 | -h, --help\t\t\t\tShow help options |
|---|
| 37 | -v, --version\t\t\t\tShow Itaka version |
|---|
| 38 | -r, --revision\t\t\tShow Itaka revision |
|---|
| 39 | |
|---|
| 40 | Application Options: |
|---|
| 41 | -d, --debug\t\t\t\tStart in debug mode""" % arguments[0] |
|---|
| 42 | sys.exit(1) |
|---|
| 43 | |
|---|
| 44 | # Itaka core modules |
|---|
| 45 | try: |
|---|
| 46 | # Initiate our Console and Configuration engines |
|---|
| 47 | import console |
|---|
| 48 | import config as itakaglobals |
|---|
| 49 | configinstance = itakaglobals.ConfigParser(arguments) |
|---|
| 50 | configinstance.load() |
|---|
| 51 | |
|---|
| 52 | try: |
|---|
| 53 | # Initiate console with a reference to our global configuration values |
|---|
| 54 | console = console.Console(itakaglobals) |
|---|
| 55 | except: |
|---|
| 56 | print "[*] ERROR: Could not initiate Console engine" |
|---|
| 57 | traceback.print_exc() |
|---|
| 58 | sys.exit(1) |
|---|
| 59 | |
|---|
| 60 | import uigtk as igui |
|---|
| 61 | except ImportError: |
|---|
| 62 | print "[*] ERROR: Failed to import Itaka modules" |
|---|
| 63 | if itakaglobals.output['debug']: |
|---|
| 64 | traceback.print_exc() |
|---|
| 65 | sys.exit(1) |
|---|
| 66 | |
|---|
| 67 | if __name__ == "__main__": |
|---|
| 68 | if len(arguments) >= 2: |
|---|
| 69 | if (arguments[-1] in (validarguments[2], validarguments[3])): |
|---|
| 70 | print itakaglobals.version |
|---|
| 71 | sys.exit(0) |
|---|
| 72 | if (arguments[-1] in (validarguments[4], validarguments[5])): |
|---|
| 73 | print itakaglobals.revision |
|---|
| 74 | sys.exit(0) |
|---|
| 75 | |
|---|
| 76 | try: |
|---|
| 77 | gui = igui.Gui(console, (itakaglobals, configinstance)) |
|---|
| 78 | gui.main() |
|---|
| 79 | except Exception, e: |
|---|
| 80 | console.failure(('Itaka', 'core'), "Could not initiate GUI: %s" % (e), 'ERROR') |
|---|
| 81 | if itakaglobals.output['debug']: |
|---|
| 82 | traceback.print_exc() |
|---|
| 83 | sys.exit(1) |
|---|