1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Manuel de la Pena <manuel@canonical.com>
#
# Copyright 2011 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""Start the sso service on a windows machine."""
# disable the name warning and complains about twisted
# pylint: disable=C0103, E1101
import sys
# pylint: disable=F0401
from win32api import GetUserNameEx
from win32con import NameSamCompatible
# pylint: enable=F0401
# import the qt reactor so that the qt ui can be used
# pylint: disable=F0401
from txnamedpipes import threadedreactor
threadedreactor.install()
from txnamedpipes.qt import Interleaver
# pylint: enable=F0401
from PyQt4.QtGui import QApplication
from twisted.internet import reactor
from twisted.spread.pb import PBServerFactory
from twisted.internet.task import LoopingCall
from ubuntu_sso.main.windows import (
CredentialsManagement,
SSOCredentials,
SSOLogin,
UbuntuSSORoot,
NAMED_PIPE_URL)
# pylint: disable=W0702
def add_timeout(interval, callback, *args, **kwargs):
"""Add a timeout callback as a task."""
time_out_task = LoopingCall(callback, *args, **kwargs)
time_out_task.start(interval/1000, now=False)
def shutdown():
"""Shutdown all the running processes and threads."""
reactor.stop()
if __name__ == '__main__':
# check if the service is running by calling the named pipe, if not
# start it.
login = SSOLogin('ignored')
creds = SSOCredentials()
creds_management = CredentialsManagement(add_timeout, shutdown)
root = UbuntuSSORoot(login, creds, creds_management)
named_pipe = NAMED_PIPE_URL % GetUserNameEx(NameSamCompatible)
listener = reactor.listenPipe(named_pipe, PBServerFactory(root))
# instantiated an qapp so that we can show the ui
ii = Interleaver()
reactor.interleave(ii.toInterleave)
app = QApplication(sys.argv)
app.exec_()
|