def setUp(self): yield super(BaseTwistedTestCase, self).setUp() self.__root = None # Patch the user home self.home_dir = self.mktemp("ubuntuonehacker") self.patch(platform, "user_home", self.home_dir) # use the config from the branch new_get_config_files = lambda: [os.path.join(os.environ["ROOTDIR"], "data", "syncdaemon.conf")] self.patch(config, "get_config_files", new_get_config_files) # fake a very basic config file with sane defaults for the tests config_dir = self.mktemp("config") self.config_file = os.path.join(config_dir, "syncdaemon.conf") with open(self.config_file, "w") as fp: fp.write("[bandwidth_throttling]\n") fp.write("on = False\n") fp.write("read_limit = -1\n") fp.write("write_limit = -1\n") # invalidate the current config config._user_config = None config.get_user_config(config_file=self.config_file) self.log = logging.getLogger("ubuntuone.SyncDaemon.TEST") self.log.info("starting test %s.%s", self.__class__.__name__, self._testMethodName) self.patch(action_queue.tunnel_runner, "TunnelRunner", self.tunnel_runner_class)
def __init__(self, fsm, vm, status_frontend): """Initialize this instance with the FSM and VM.""" self.fsm = fsm self.vm = vm self.status_frontend = status_frontend user_conf = config.get_user_config() self.show_all_notifications = user_conf.get_show_all_notifications()
def set_throttling_limits(self, download, upload, reply_handler=None, error_handler=None): """Set the read and write limits. The expected values are bytes/sec.""" logger.debug("called set_throttling_limits") try: # modify and save the config file user_config = config.get_user_config() user_config.set_throttling_read_limit(download) user_config.set_throttling_write_limit(upload) user_config.save() # modify AQ settings aq = self.action_queue if download == -1: download = None if upload == -1: upload = None aq.readLimit = download aq.writeLimit = upload if reply_handler: reply_handler() # pylint: disable-msg=W0703 except Exception, e: if error_handler: error_handler(e) else: raise
def _set_throttling_enabled(self, enabled): """Set throttling enabled value and save the config""" # modify and save the config file user_config = config.get_user_config() user_config.set_throttling(enabled) user_config.save() # modify AQ settings if enabled: self.action_queue.enable_throttling() else: self.action_queue.disable_throttling()
def set_throttling_limits(self, download, upload): """Set the read and write limits. The expected values are bytes/sec.""" # modify and save the config file user_config = config.get_user_config() user_config.set_throttling_read_limit(download) user_config.set_throttling_write_limit(upload) user_config.save() # modify AQ settings if download == -1: download = None if upload == -1: upload = None self.action_queue.readLimit = download self.action_queue.writeLimit = upload
def enable_files_sync(self, enabled): """Enable/disable files sync.""" config = get_user_config() was_enabled = config.get_files_sync_enabled() self.log.debug('enable_files_sync: enable? %r was enabled? %r', enabled, was_enabled) if was_enabled: yield self.client.config.set_files_sync_enabled(enabled) config.set_files_sync_enabled(enabled) if not enabled: # User requested the service to be disabled self.quit() else: if enabled: config.set_files_sync_enabled(True) config.save() self.start()
def enable_files_sync(self, enabled): """Enable/disable files sync.""" config = get_user_config() was_enabled = config.get_files_sync_enabled() self.log.debug('enable_files_sync: enable? %r was enabled? %r', enabled, was_enabled) if was_enabled: d = defer.Deferred() config_client = DBusClient(self.bus, '/config', DBUS_IFACE_CONFIG_NAME) config_client.call_method('set_files_sync_enabled', enabled, reply_handler=d.callback, error_handler=d.errback) yield d config.set_files_sync_enabled(enabled) if not enabled: # User requested the service to be disabled self.quit() else: if enabled: config.set_files_sync_enabled(True) config.save() self.start()
def show_all_notifications_enabled(self): """Return the show_all_notifications config value.""" return config.get_user_config().get_show_all_notifications()
def set_autoconnect_enabled(self, enabled): """Enable syncdaemon autoconnect.""" user_config = config.get_user_config() user_config.set_autoconnect(enabled) user_config.save()
def autoconnect_enabled(self): """Return the autoconnect config value.""" return config.get_user_config().get_autoconnect()
def files_sync_enabled(self): """Return the files_sync_enabled config value.""" logger.debug('called files_sync_enabled') return config.get_user_config().get_files_sync_enabled()
def set_files_sync_enabled(self, enabled): """Enable/disable file sync service.""" logger.debug('called set_files_sync_enabled %d', enabled) user_config = config.get_user_config() user_config.set_files_sync_enabled(bool(int(enabled))) user_config.save()
def disable_share_autosubscribe(self): """Enable UDF autosubscribe.""" user_config = config.get_user_config() user_config.set_share_autosubscribe(False) user_config.save()
def files_sync_enabled(self): """Return the files_sync_enabled config value.""" return config.get_user_config().get_files_sync_enabled()
def enable_udf_autosubscribe(self): """Enable UDF autosubscribe.""" user_config = config.get_user_config() user_config.set_udf_autosubscribe(True) user_config.save()
def is_files_sync_enabled(self): """Check if files sync is enabled.""" self.log.debug('is_files_sync_enabled') return get_user_config().get_files_sync_enabled()
def disable_autoconnect(self): """Disable syncdaemon autoconnect.""" user_config = config.get_user_config() user_config.set_autoconnect(False) user_config.save()
def enable_autoconnect(self): """Enable syncdaemon autoconnect.""" user_config = config.get_user_config() user_config.set_autoconnect(True) user_config.save()
def disable_files_sync(self): """Disable file sync service.""" user_config = config.get_user_config() user_config.set_files_sync_enabled(False) user_config.save()
def enable_files_sync(self): """Enable file sync service.""" user_config = config.get_user_config() user_config.set_files_sync_enabled(True) user_config.save()
def enable_show_all_notifications(self): """Enable showing all notifications.""" user_config = config.get_user_config() user_config.set_show_all_notifications(True) user_config.save() self.main.status_listener.show_all_notifications = True
def share_autosubscribe_enabled(self): """Return the share_autosubscribe config value.""" return config.get_user_config().get_share_autosubscribe()
def disable_show_all_notifications(self): """Disable showing all notifications.""" user_config = config.get_user_config() user_config.set_show_all_notifications(False) user_config.save() self.main.status_listener.show_all_notifications = False
def __init__( self, root_dir, shares_dir, data_dir, partials_dir, host="fs-1.one.ubuntu.com", port=443, dns_srv=None, ssl=True, disable_ssl_verify=False, mark_interval=120, broadcast_events=False, handshake_timeout=30, shares_symlink_name="Shared With Me", read_limit=None, write_limit=None, throttling_enabled=False, ignore_files=None, auth_credentials=None, monitor_class=None, ): self.root_dir = root_dir self.shares_dir = shares_dir self.shares_dir_link = os.path.join(self.root_dir, shares_symlink_name) self.data_dir = data_dir self.partials_dir = partials_dir tritcask_dir = os.path.join(self.data_dir, "tritcask") self.logger = logging.getLogger("ubuntuone.SyncDaemon.Main") user_config = config.get_user_config() if read_limit is None: read_limit = user_config.get_throttling_read_limit() if write_limit is None: write_limit = user_config.get_throttling_write_limit() if not throttling_enabled: throttling_enabled = user_config.get_throttling() self.logger.info("Starting %s client version %s", clientdefs.NAME, clientdefs.VERSION) self.logger.info("Using %r as root dir", self.root_dir) self.logger.info("Using %r as data dir", self.data_dir) self.logger.info("Using %r as shares root dir", self.shares_dir) self.db = tritcask.Tritcask(tritcask_dir) self.vm = volume_manager.VolumeManager(self) self.fs = filesystem_manager.FileSystemManager(data_dir, partials_dir, self.vm, self.db) self.event_q = event_queue.EventQueue(self.fs, ignore_files, monitor_class=monitor_class) self.fs.register_eq(self.event_q) # subscribe VM to EQ, to be unsubscribed in shutdown self.event_q.subscribe(self.vm) self.vm.init_root() # we don't have the auth tokens yet, we 'll get them later self.action_q = action_queue.ActionQueue( self.event_q, self, host, port, dns_srv, ssl, disable_ssl_verify, read_limit, write_limit, throttling_enabled, ) self.hash_q = hash_queue.HashQueue(self.event_q) events_nanny.DownloadFinishedNanny(self.fs, self.event_q, self.hash_q) # call StateManager after having AQ self.state_manager = StateManager(self, handshake_timeout) self.sync = sync.Sync(self) self.lr = local_rescan.LocalRescan(self.vm, self.fs, self.event_q, self.action_q) self.external = SyncdaemonService(main=self, send_events=broadcast_events) self.external.auth_credentials = auth_credentials if user_config.get_autoconnect(): self.external.connect(autoconnecting=True) self.mark = task.LoopingCall(self.log_mark) self.mark.start(mark_interval)