~parinporecha/gtg/config_parser_bug

« back to all changes in this revision

Viewing changes to GTG/gtg.py

  • Committer: Izidor Matušov
  • Date: 2013-02-25 07:35:07 UTC
  • Revision ID: izidor.matusov@gmail.com-20130225073507-vgts69uthx7z2run
PEP8ification by Nimit

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
import logging
51
51
import dbus
52
52
 
53
 
#our own imports
54
 
from GTG.backends       import BackendFactory
55
 
from GTG                import _
56
 
from GTG.core           import CoreConfig
 
53
# our own imports
 
54
from GTG.backends import BackendFactory
 
55
from GTG import _
 
56
from GTG.core import CoreConfig
57
57
from GTG.core.datastore import DataStore
58
 
from GTG.gtk.manager    import Manager
59
 
from GTG.tools.logger   import Log
 
58
from GTG.gtk.manager import Manager
 
59
from GTG.tools.logger import Log
60
60
 
61
61
#=== OBJECTS ==================================================================
62
62
 
63
 
#code borrowed from Specto. Avoid having multiples instances of gtg
64
 
#reading the same tasks
65
 
#that's why we put the pid file in the data directory :
66
 
#we allow one instance of gtg by data directory.
67
 
 
68
 
def check_instance(directory, uri_list = []):
 
63
# code borrowed from Specto. Avoid having multiples instances of gtg
 
64
# reading the same tasks
 
65
# that's why we put the pid file in the data directory :
 
66
# we allow one instance of gtg by data directory.
 
67
 
 
68
 
 
69
def check_instance(directory, uri_list=[]):
69
70
    """
70
71
    Check if gtg is already running.
71
72
    If so, open the tasks whose ids are in the uri_list
75
76
        open(pidfile, "w").close()
76
77
        os.chmod(pidfile, 0600)
77
78
 
78
 
    #see if gtg is already running
 
79
    # see if gtg is already running
79
80
    pid = open(pidfile, "r").readline()
80
81
    if pid:
81
82
        p = os.system("/bin/ps %s >/dev/null" % pid)
83
84
        if p == 0 and "gtg" in p_name:
84
85
            print _("gtg is already running!")
85
86
            try:
86
 
                d=dbus.SessionBus().get_object(CoreConfig.BUSNAME,\
87
 
                                           CoreConfig.BUSINTERFACE)
 
87
                d = dbus.SessionBus().get_object(CoreConfig.BUSNAME,
 
88
                                                 CoreConfig.BUSINTERFACE)
88
89
                d.ShowTaskBrowser()
89
 
                #if the user has specified a task to open, do that
 
90
                # if the user has specified a task to open, do that
90
91
                for uri in uri_list:
91
92
                    if uri.startswith("gtg://"):
92
93
                        d.OpenTaskEditor(uri[6:])
96
97
                # between GTG versions), we won't do anything more
97
98
                raise SystemExit
98
99
 
99
 
    #write the pid file
 
100
    # write the pid file
100
101
    with open(pidfile, "w") as f:
101
 
        f.write(`os.getpid()`)
 
102
        f.write(repr(os.getpid()))
102
103
 
103
104
 
104
105
def remove_pidfile(directory):
112
113
 
113
114
#=== MAIN CLASS ===============================================================
114
115
 
 
116
 
115
117
def main(options=None, args=None):
116
118
    '''
117
119
    Calling this starts the full GTG experience  ( :-D )
119
121
    ds, req = core_main_init(options, args)
120
122
    # Launch task browser
121
123
    manager = Manager(req)
122
 
    #main loop
123
 
    #To be more user friendly and get the logs of crashes, we show an apport
 
124
    # main loop
 
125
    # To be more user friendly and get the logs of crashes, we show an apport
124
126
    # hooked window upon crashes
125
 
    if options.no_crash_handler == False:
 
127
    if not options.no_crash_handler:
126
128
        from GTG.gtk.crashhandler import signal_catcher
127
129
        with signal_catcher(manager.close_browser):
128
 
            manager.main(once_thru=options.boot_test, uri_list = args)
 
130
            manager.main(once_thru=options.boot_test, uri_list=args)
129
131
    else:
130
 
        manager.main(once_thru=options.boot_test, uri_list = args)
 
132
        manager.main(once_thru=options.boot_test, uri_list=args)
131
133
    core_main_quit(req, ds)
132
134
 
133
135
 
134
 
def core_main_init(options = None, args = None):
 
136
def core_main_init(options=None, args=None):
135
137
    '''
136
138
    Part of the main function prior to the UI initialization.
137
139
    '''
150
152
    # Register backends
151
153
    for backend_dic in backends_list:
152
154
        ds.register_backend(backend_dic)
153
 
    #save the backends directly to be sure projects.xml is written
154
 
    ds.save(quit = False)
 
155
    # save the backends directly to be sure projects.xml is written
 
156
    ds.save(quit=False)
155
157
 
156
158
    # Launch task browser
157
159
    req = ds.get_requester()
169
171
    #
170
172
    # Ending the application: we save configuration
171
173
    req.save_config()
172
 
    ds.save(quit = True)
 
174
    ds.save(quit=True)
173
175
    config = req.get_global_config()
174
176
    remove_pidfile(config.get_data_dir())
175
177
    sys.exit(0)