18
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
"""Common code for the credentials management."""
25
28
from twisted.internet import defer
27
from ubuntuone.clientdefs import GETTEXT_PACKAGE
30
from ubuntuone import clientdefs
28
31
from ubuntuone.logger import (
30
33
CustomRotatingFileHandler,
32
36
from ubuntuone.platform.xdg_base_directory import ubuntuone_log_dir
42
46
logger.addHandler(MAIN_HANDLER)
44
48
NO_OP = lambda *args, **kwargs: None
45
Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string)
49
Q_ = lambda string: gettext.dgettext(clientdefs.GETTEXT_PACKAGE, string)
46
50
APP_NAME = "Ubuntu One"
47
51
TC_URL = "https://one.ubuntu.com/terms/"
48
PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
53
"https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/{email}"
54
PLATFORM_DATA = {'platform': platform.system(),
55
'platform_version': platform.release(),
56
'platform_arch': platform.machine(),
57
'client_version': clientdefs.VERSION}
58
PING_URL = BASE_PING_URL + "?" + urllib.urlencode(PLATFORM_DATA)
49
59
DESCRIPTION = Q_('Ubuntu One requires an Ubuntu Single Sign On (SSO) account. '
50
60
'This process will allow you to create a new account, '
51
61
'if you do not yet have one.')
53
64
class CredentialsError(Exception):
54
65
"""A general exception when hadling credentilas."""
57
class CredentialsManagementToolRoot(object):
68
class CredentialsManagementTool(object):
58
69
"""Wrapper to CredentialsManagement.
60
The goal of this class is to abstract the caller from calling the DBus
71
The goal of this class is to abstract the caller from calling the IPC
61
72
service implemented in the class CredentialsManagement.
65
def __init__(self, get_proxy_fn):
66
77
self._cleanup_signals = []
67
self.get_proxy_fn = get_proxy_fn
69
79
def cleanup(self, _):
70
80
"""Disconnect all the DBus signals."""
78
88
def get_creds_proxy(self):
79
89
"""Call the get_proxy_fn, and perhaps wrap the result in a defer."""
80
return defer.maybeDeferred(self.get_proxy_fn)
90
if sys.platform == 'win32':
91
from ubuntuone.platform.credentials import windows
94
from ubuntuone.platform.credentials import linux
96
result = defer.maybeDeferred(source.get_creds_proxy)
99
@log_call(logger.debug)
82
100
@defer.inlineCallbacks
83
101
def find_credentials(self):
84
102
"""Find credentials for Ubuntu One.