~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to bin/windows-ubuntu-sso-login

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2011-05-23 16:31:26 UTC
  • mfrom: (711.2.2 cannot_shutdown_windows)
  • Revision ID: tarmac-20110523163126-txc271yj04h31dhj
Updated the way in which the service shutsdowns. The implementation uses a LoopingCallback from twisted and does perform a correct exit which was missing in the previous code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from PyQt4.QtGui import QApplication
37
37
from twisted.internet import reactor
38
38
from twisted.spread.pb import PBServerFactory
 
39
from twisted.internet.task import LoopingCall
39
40
 
40
41
from ubuntu_sso.main.windows import (
41
42
    CredentialsManagement,
46
47
    UbuntuSSORoot)
47
48
 
48
49
 
 
50
def add_timeout(interval, callback, *args, **kwargs):
 
51
    """Add a timeout callback as a task."""
 
52
    time_out_task = LoopingCall(callback, *args, **kwargs)
 
53
    time_out_task.start(interval/1000, now=False)
 
54
 
 
55
 
 
56
def shutdown(pipe_service):
 
57
    """Shutdown all the running processes and threads."""
 
58
    pipe_service.stop()
 
59
    reactor.stop()
 
60
 
 
61
 
49
62
if __name__ == '__main__':
50
63
    # check if the service is running by calling the named pipe, if not
51
64
    # start it.
53
66
    if port is None:
54
67
        login = SSOLogin('ignored')
55
68
        creds = SSOCredentials()
56
 
        creds_management = CredentialsManagement(lambda:None, sys.exit)
 
69
        username = GetUserNameEx(NameSamCompatible)
 
70
        named_pipe_service = ListeningPortPipeService(username,
 
71
                                                      0)
 
72
        creds_management = CredentialsManagement(add_timeout,
 
73
                                        lambda: shutdown(named_pipe_service))
57
74
        root = UbuntuSSORoot(login, creds, creds_management)
58
75
        listener = reactor.listenTCP(0, PBServerFactory(root))
59
 
        username = GetUserNameEx(NameSamCompatible)
60
 
        named_pipe_service = ListeningPortPipeService(username,
61
 
                                                      listener.getHost().port)
 
76
        named_pipe_service.port = listener.getHost().port
62
77
        service_thread = Thread(name='Ubuntu SSO Port Broadcaster',
63
78
                                target=named_pipe_service.start)
64
79
        service_thread.start()