~nimit-svnit/gtg/self-subtask-update

« back to all changes in this revision

Viewing changes to gtg

  • Committer: Izidor Matušov
  • Date: 2012-04-23 17:51:43 UTC
  • Revision ID: izidor.matusov@gmail.com-20120423175143-ghz6402600xd1op9
Start working on pylint: for the cleaner code\!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# -*- coding:utf-8 -*-
3
 
 
4
3
# -----------------------------------------------------------------------------
5
4
# Getting Things Gnome! - A personal organizer for the GNOME desktop
6
 
# Copyright (c) 2008,2009,2010 Lionel Dricot & Bertrand Rousseau
 
5
# Copyright (c) 2008-2012 Lionel Dricot & Bertrand Rousseau
7
6
#
8
7
# This program is free software: you can redistribute it and/or modify it under
9
8
# the terms of the GNU General Public License as published by the Free Software
19
18
# this program.  If not, see <http://www.gnu.org/licenses/>.
20
19
# -----------------------------------------------------------------------------
21
20
 
22
 
"""
23
 
Getting Things Gnome! - A personal organizer for the GNOME desktop
24
 
==================================================================
25
 
 
26
 
:copyright: 2008,2009,2010 Lionel Dricot & Bertrand Rousseau
27
 
:license: GNU General Public License, version 3 or later
28
 
"""
 
21
""" Main script which parse arguments and launch GTG """
29
22
 
30
23
import sys
 
24
 
31
25
from optparse import OptionParser
 
26
from gtk.gdk import Screen
32
27
 
 
28
from GTG import gtg
 
29
from GTG import info
33
30
from GTG.tools.import_liblarch import import_liblarch
34
31
 
35
32
 
36
 
def X_is_running():
37
 
    from gtk.gdk import Screen
 
33
def x_is_running():
 
34
    """ Return True if GTG could be displayed on the current XServer """
38
35
    try:
39
36
        if Screen().get_display():
40
37
            return True
41
38
    except RuntimeError:
42
39
        pass
43
40
    return False
44
 
    
45
 
 
46
 
try:
 
41
 
 
42
 
 
43
def main():
 
44
    """ Parse arguments and run GTG """
47
45
    parser = OptionParser()
48
 
    parser.add_option('-b', '--boot-test', action='store_true', dest='boot_test',
49
 
      help="Exit immediately after completing boot-up actions", default=False)
50
 
    parser.add_option('-c', '--no-crash-handler', action='store_true', dest='no_crash_handler',
51
 
      help="Disable the automatic crash handler", default=False)
 
46
    parser.add_option('-b', '--boot-test', action='store_true',
 
47
      dest='boot_test', help="Exit after completing boot-up actions",
 
48
      default=False)
 
49
    parser.add_option('-c', '--no-crash-handler', action='store_true',
 
50
      dest='no_crash_handler', help="Disable the automatic crash handler",
 
51
      default=False)
52
52
    parser.add_option('-d', '--debug', action='store_true', dest='debug',
53
53
      help="Enable debug output", default=False)
54
 
    parser.add_option('-v', '--version', action='store_true', dest='version_and_exit',
55
 
      help="Print GTG's version number", default=False)
 
54
    parser.add_option('-v', '--version', action='store_true',
 
55
      dest='print_version', help="Print GTG's version number", default=False)
56
56
    (options, args) = parser.parse_args()
57
57
 
58
 
    if options.version_and_exit:
59
 
        from GTG import info
60
 
        print "GTG (Getting Things Gnome!) %s" %(info.VERSION)
 
58
    if options.print_version:
 
59
        print "GTG (Getting Things Gnome!)", info.VERSION
61
60
        print
62
 
        print "For more information: %s" %(info.URL)
 
61
        print "For more information:", info.URL
63
62
        sys.exit(0)
64
63
 
65
 
    elif not X_is_running():
 
64
    elif not x_is_running():
66
65
        print "Could not open X display"
67
66
        sys.exit(1)
68
67
 
69
68
    elif import_liblarch():
70
 
        import GTG.gtg
71
 
        sys.exit(GTG.gtg.main(options, args))
 
69
        sys.exit(gtg.main(options, args))
72
70
 
73
 
except KeyboardInterrupt:
74
 
    sys.exit(1)
 
71
if __name__ == "__main__":
 
72
    try:
 
73
        main()
 
74
    except KeyboardInterrupt:
 
75
        sys.exit(1)