~verterok/ubuntuone-client/faster-startup

« back to all changes in this revision

Viewing changes to bin/ubuntuone-syncdaemon

  • Committer: guillermo.gonzalez at canonical
  • Date: 2009-08-12 04:15:42 UTC
  • mfrom: (92.1.43 trunk)
  • Revision ID: guillermo.gonzalez@canonical.com-20090812041542-ool1svt9qwak5hok
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import dbus
26
26
import dbus.mainloop.glib
27
27
import gobject
 
28
import logging
28
29
import os
29
30
import signal
30
31
import sys
54
55
    return os.path.join(xdg_cache_home, value)
55
56
 
56
57
 
 
58
def log_level_parser(value):
 
59
    level = getattr(logging, value, None)
 
60
    if level is None:
 
61
        # if level don't exists in our custom levels, fallback to DEBUG
 
62
        level = logger.levels.get(value, 'DEBUG')
 
63
    return level
 
64
 
 
65
 
57
66
def get_config_file():
58
67
    """ return the path to the config file or None.
59
68
    The search path is based on the paths returned by xdg_config_dirs.
73
82
def is_already_running(): 
74
83
    """ check if there is another instance registered in DBus """
75
84
    bus = dbus.SessionBus()
76
 
    request = bus.request_name(dbus_interface.DBUS_IFACE_NAME, dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
 
85
    request = bus.request_name(dbus_interface.DBUS_IFACE_NAME, 
 
86
                               dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
77
87
    return request == dbus.bus.REQUEST_NAME_REPLY_EXISTS
78
88
 
 
89
 
79
90
def die(msg):
80
91
    logger.root_logger.warning(msg)
81
92
    sys.stderr.write(msg + '\n')
82
93
    sys.exit(1)
83
94
 
84
95
 
85
 
 
86
96
def main(argv):
87
97
    """ client entry point. """
88
98
    args = argv[1:]
95
105
    (parser, options, argv) = configglue(file(configs[0]), *configs[1:], 
96
106
                               args=args, usage=usage,
97
107
                               extra_parsers=[('home_dir', home_dir_parser),
98
 
                                              ('cache_dir', cache_dir_parser)])
 
108
                                              ('cache_dir', cache_dir_parser),
 
109
                                              ('log_level', log_level_parser)])
99
110
 
100
111
    if options.debug:
101
112
        logger.set_debug('stdout file')
102
113
 
 
114
    logger.set_level(options.log_level)
 
115
 
103
116
    # check we're not running as root, or have explicitely and in
104
117
    # length expressed our desire to do so
105
118
    if not (os.geteuid()
127
140
                host=options.host, port=int(options.port), 
128
141
                dns_srv=options.dns_srv, ssl=True,
129
142
                disable_ssl_verify=options.disable_ssl_verify,
130
 
                realm=options.realm, mark_interval=options.mark_interval)
 
143
                realm=options.realm, mark_interval=options.mark_interval,
 
144
                fsync_md=not options.disable_fsync_md, 
 
145
                dbus_events=options.send_events_over_dbus)
131
146
    if options.oauth:
132
147
        try:
133
148
            (key, secret) = options.oauth.split(':', 2)
135
150
            parser.error("--oauth requires a key and secret together in the "
136
151
                         " form KEY:SECRET")
137
152
        main.set_oauth_token(key, secret)
138
 
    main.start()
139
153
    
140
154
    # override the reactor default signal handlers in order to 
141
155
    # shutdown properly
152
166
    reactor.callWhenRunning(install_handlers)
153
167
    # set the application name
154
168
    gobject.set_application_name('ubuntuone-syncdaemon')
155
 
    reactor.run()
 
169
 
 
170
    # check if we should start the heapy monitor
 
171
    if options.debug_heapy_monitor:
 
172
        try:
 
173
            import guppy.heapy.RM
 
174
        except ImportError:
 
175
            logger.root_logger.warning('guppy-pe/heapy not available, remote '
 
176
                                       'monitor thread not started')
 
177
    main.start()
 
178
    if options.debug_lsprof_file:
 
179
        try:
 
180
            from bzrlib.lsprof import profile
 
181
            ret, stats = profile(reactor.run)
 
182
            stats.save(options.debug_lsprof_file)
 
183
        except ImportError:
 
184
            logger.root_logger.warning('bzrlib.lsprof not available')
 
185
            reactor.run()
 
186
    else:
 
187
        reactor.run()
156
188
 
157
189
 
158
190
if __name__ == '__main__':