示例#1
0
from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH,
    DBUS_PREFERENCES_IFACE)
from ubuntuone.controlpanel.backend import (
    ControlBackend, filter_field, UnauthorizedError,
    FILE_SYNC_DISABLED, FILE_SYNC_DISCONNECTED,
    FILE_SYNC_ERROR, FILE_SYNC_IDLE, FILE_SYNC_STARTING, FILE_SYNC_STOPPED,
    FILE_SYNC_SYNCING,
    MSG_KEY, STATUS_KEY,
)
from ubuntuone.controlpanel.logger import setup_logging, log_call
from ubuntuone.controlpanel.utils import (ERROR_TYPE, ERROR_MESSAGE,
    failure_to_error_dict, exception_to_error_dict)


logger = setup_logging('dbus_service')


def make_unicode(anything):
    """Transform 'anything' on an unicode."""
    if isinstance(anything, bool):
        anything = bool_str(anything)
    elif not isinstance(anything, unicode):
        anything = str(anything).decode('utf8', 'replace')

    return anything


def transform_info(f):
    """Decorator to apply to DBus success signals.
# 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/>.

"""Client to use replication services."""

from twisted.internet.defer import Deferred, inlineCallbacks, returnValue

from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging('replication_client')

CONTACTS = 'contacts'
# we should get this list from somewhere else
REPLICATIONS = set([CONTACTS])


class ReplicationError(Exception):
    """A replication error."""


class NoPairingRecord(ReplicationError):
    """There is no pairing record."""


class InvalidIdError(ReplicationError):
示例#3
0
# 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/>.

"""Client to use other DBus services."""

import dbus.service

from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging("sd_client")


def get_syncdaemon_proxy(object_path, dbus_interface):
    """Get a DBus proxy for syncdaemon at 'object_path':'dbus_interface'."""
    logger.debug("get_syncdaemon_proxy: object_path %r, dbus_interface %r", object_path, dbus_interface)
    bus = dbus.SessionBus()
    obj = bus.get_object(bus_name="com.ubuntuone.SyncDaemon", object_path=object_path, follow_name_owner_changes=True)
    proxy = dbus.Interface(object=obj, dbus_interface=dbus_interface)
    return proxy


def set_status_changed_handler(handler):
    """Connect 'handler' with syncdaemon's StatusChanged signal."""
    proxy = get_syncdaemon_proxy("/status", "com.ubuntuone.SyncDaemon.Status")
    sig = proxy.connect_to_signal("StatusChanged", handler)
示例#4
0
#
# 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 syncdaemon client."""

import sys
import warnings

# pylint: disable=E0611
from ubuntuone.platform import tools
# pylint: enable=E0611
from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging('sd_client')


class SyncDaemonClient(object):
    """An abstraction to SyncDaemonTool."""

    def __init__(self):
        """Get a proxy for the SyncDaemonTool."""
        self.status_changed_handler = None
        self.proxy = tools.SyncDaemonTool()

    def get_throttling_limits(self):
        """Get the speed limits from the syncdaemon."""
        return self.proxy.get_throttling_limits()

    def set_throttling_limits(self, limits):
示例#5
0
"""A backend for the Ubuntu One Control Panel."""

import operator
import os

from collections import defaultdict
from functools import wraps

from twisted.internet.defer import inlineCallbacks, returnValue
from ubuntuone.platform.credentials import CredentialsManagementTool

from ubuntuone.controlpanel import sd_client, replication_client
from ubuntuone.controlpanel.logger import setup_logging, log_call
from ubuntuone.controlpanel.web_client import UnauthorizedError, WebClient, WebClientError

logger = setup_logging("backend")

ACCOUNT_API = u"account/"
DEVICES_API = u"1.0/devices/"
DEVICE_REMOVE_API = u"1.0/devices/remove/%s/%s"
QUOTA_API = u"quota/"

DEVICE_TYPE_PHONE = u"Phone"
DEVICE_TYPE_COMPUTER = u"Computer"

AUTOCONNECT_KEY = u"autoconnect"
SHOW_ALL_NOTIFICATIONS_KEY = u"show_all_notifications"
SHARE_AUTOSUBSCRIBE_KEY = u"share_autosubscribe"
UDF_AUTOSUBSCRIBE_KEY = u"udf_autosubscribe"
LIMIT_BW_KEY = u"limit_bandwidth"
UPLOAD_KEY = u"max_upload_speed"
import aptdaemon.client
# pylint: disable=W0404
import aptdaemon.enums

try:
    # Unable to import 'defer', pylint: disable=F0401,E0611,W0404
    from aptdaemon.defer import inline_callbacks, return_value
except ImportError:
    # Unable to import 'defer', pylint: disable=F0401,E0611,W0404
    from defer import inline_callbacks, return_value
from aptdaemon.gtkwidgets import AptProgressBar

from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging('package_manager')


class PackageManagerProgressBar(AptProgressBar):
    """A progress bar for a transaction."""


class PackageManager(object):
    """Manage packages (check if is installed, install)."""

    def is_installed(self, package_name):
        """Return whether 'package_name' is installed in this system."""
        cache = apt.Cache()
        result = package_name in cache and cache[package_name].is_installed
        logger.debug('is %r installed? %r', package_name, result)
        return result
示例#7
0
import os
import sys

# Avoid pylint error on Linux
# pylint: disable=F0401
import win32api
import _winreg

from win32com.shell import shell, shellcon
# pylint: enable=F0401
from twisted.internet import defer
from twisted.internet.utils import getProcessValue

from ubuntuone.controlpanel.logger import setup_logging

logger = setup_logging('utils.windows')
AUTOUPDATE_EXE_NAME = 'autoupdate-windows.exe'
AUTORUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
UNINSTALL_EXE_NAME = 'uninstall.exe'


def get_exe_path(exe_name):
    """Return the path in which the autoupdate command is found."""
    if getattr(sys, 'frozen', False):
        exec_path = os.path.abspath(sys.executable)
    else:
        exec_path = os.path.dirname(__file__)

    result = None
    folder = os.path.dirname(os.path.dirname(exec_path))
    exe_path = os.path.join(folder, exe_name)
示例#8
0
from twisted.internet.defer import inlineCallbacks, returnValue
# No name 'is_link' in module 'ubuntuone.platform'
# pylint: disable=E0611, F0401
from ubuntuone.platform import is_link
from ubuntuone.platform.credentials import CredentialsManagementTool
# pylint: enable=E0611, F0401

from ubuntuone.controlpanel import sd_client, replication_client
from ubuntuone.controlpanel.logger import setup_logging, log_call
# pylint: disable=W0611
from ubuntuone.controlpanel.web_client import (UnauthorizedError,
    web_client_factory, WebClientError)
# pylint: enable=W0611

logger = setup_logging('backend')

ACCOUNT_API = "account/"
QUOTA_API = "quota/"
DEVICES_API = "1.0/devices/"
DEVICE_REMOVE_API = "1.0/devices/remove/%s/%s"
DEVICE_TYPE_PHONE = "Phone"
DEVICE_TYPE_COMPUTER = "Computer"
AUTOCONNECT_KEY = 'autoconnect'
SHOW_ALL_NOTIFICATIONS_KEY = 'show_all_notifications'
SHARE_AUTOSUBSCRIBE_KEY = 'share_autosubscribe'
UDF_AUTOSUBSCRIBE_KEY = 'udf_autosubscribe'
LIMIT_BW_KEY = 'limit_bandwidth'
UPLOAD_KEY = "max_upload_speed"
DOWNLOAD_KEY = "max_download_speed"
示例#9
0
# 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/>.

"""Miscellaneous utilities."""

import os
import sys

from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging('utils')

DATA_SUFFIX = 'data'

ERROR_TYPE = 'error_type'
ERROR_MESSAGE = 'error_msg'

# ignore issues with the name of the method
# pylint: disable=C0103

no_op = lambda *args, **kwargs: None

# import the platform dependent code.
if sys.platform == 'win32':
    from ubuntuone.controlpanel.utils import windows
    add_to_autostart = windows.add_to_autostart
示例#10
0
"""The control panel backend webservice client using twisted.web."""

import simplejson

from twisted.internet import defer, reactor
from twisted.web import client, error, http

from ubuntuone.controlpanel import WEBSERVICE_BASE_URL
from ubuntuone.controlpanel.web_client import (add_oauth_headers,
                                               WebClientError,
                                               UnauthorizedError)

from ubuntuone.controlpanel.logger import setup_logging

logger = setup_logging('webclient')


class WebClient(object):
    """A client for the u1 webservice."""

    def __init__(self, get_credentials, base_url=WEBSERVICE_BASE_URL):
        """Initialize the webclient."""
        self.base_url = base_url
        self.get_credentials = get_credentials
        self.running = True
        # pylint: disable=E1101
        self.trigger_id = reactor.addSystemEventTrigger("before", "shutdown",
                                                        self.shutdown)

    def _handle_response(self, result):
示例#11
0
# 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/>.

"""Miscelaneous functions and constants for linux."""

import codecs
import os

from dirspec.basedir import xdg_config_home
from ubuntuone.controlpanel.logger import setup_logging


logger = setup_logging('utils.linux')


def default_folders(user_home='', dirs_path=None):
    """Return a list of the folders to add by default."""
    result = []

    if dirs_path is None:
        dirs_path = os.path.join(xdg_config_home, u'user-dirs.dirs')

    if not os.path.exists(dirs_path):
        logger.warning('default_folders: dirs_path %r does not exist.',
                       dirs_path)
        return result

    # pylint: disable=W0702