~nataliabidart/ubuntuone-client/credentials-shutdown

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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Author: Natalia B. Bidart <natalia.bidart@canonical.com>
#
# Copyright 2010 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/>.

"""The script tu ron the Ubuntu One Login D-Bus service."""

# Invalid name "ubuntuone-login"
# pylint: disable=C0103

import sys

import dbus.mainloop.glib
import dbus.service
import glib

from ubuntuone.credentials import (DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,
    CredentialsManagement, logger)

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)


if __name__ == "__main__":
    # Register DBus service for making sure we run only one instance
    bus = dbus.SessionBus()
    name = bus.request_name(DBUS_BUS_NAME,
                            dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
    if name == dbus.bus.REQUEST_NAME_REPLY_EXISTS:
        logger.error("Ubuntu One login manager already running, quitting.")
        sys.exit(0)

    logger.info("Starting Ubuntu One login manager for bus %r.", DBUS_BUS_NAME)
    mainloop = glib.MainLoop()
    bus_name = dbus.service.BusName(DBUS_BUS_NAME, bus=dbus.SessionBus())
    CredentialsManagement(timeout_func=glib.timeout_add,
                          shutdown_func=mainloop.quit,
                          bus_name=bus_name, object_path=DBUS_CREDENTIALS_PATH)

    mainloop.run()