def from_file(klass, config_dir: Optional[str]) -> AuthProvider: if config_dir: configmanager.set_config_dir(config_dir) (username, password) = common.get_localhost_auth() return klass( host="localhost", username=username, password=password, )
def started_deluge_client(tmpdir): # Set Up standalone_client = Client() if len(component._ComponentRegistry.components) != 0: warnings.warn("The component._ComponentRegistry.components" " is not empty on test setup.\n" "This is probably caused by another test" " that did not clean up after finishing!:" f" {component._ComponentRegistry.components}") configmanager.set_config_dir(tmpdir) standalone_client.start_standalone() pytest_twisted.blockon(component.start()) yield standalone_client # Tear Down pytest_twisted.blockon(standalone_client.disconnect()) pytest_twisted.blockon(component.shutdown()) # There can be KeyErrors after pytest run about RPCServer # This errors are happening because of the next clear() # # It is so because plugins objects (that are based on CorePluginBase) # are still stored inside RPCServer's factory.methods # When RPCServer object is destroyed, it's dicts are cleared as well # That's when CorePluginBase.__del__ is called # And it tries to obtain RPCServer object from a list of components, # but this object already excluded from the list, so it fails to # deregister itself from RPCServer's dicts. # # Moreover, calling RPCServer's deregister_object is of no use, because: # def deregister_object(self, obj): # """ # Deregisters an objects exported rpc methods. # # :param obj: the object that was previously registered # # """ # > for key, value in self.factory.methods.items(): # if value.__self__ == obj: # del self.factory.methods[key] # E RuntimeError: dictionary changed size during iteration component._ComponentRegistry.components.clear() component._ComponentRegistry.dependents.clear()
plugins_location = get_env_or_default('PLUGINS_LOCATION', config_dir + '/deluge/plugins') move_completed_path = get_env_or_default('MOVE_COMPLETED_PATH', torrents_dir + '/completed') torrentfiles_location = get_env_or_default('TORRENTFILES_LOCATION', torrents_dir + '/.torrents') download_location = get_env_or_default('DOWNLOAD_LOCATION', torrents_dir + '/.downloading') autoadd_location = get_env_or_default('AUTOADD_LOCATION', torrents_dir + '/watch/deluge') if not os.path.exists(config_dir): os.makedirs(config_dir) set_config_dir(config_dir) config = ConfigManager(config_dir + '/core.conf') config['move_completed_path'] = move_completed_path config['torrentfiles_location'] = torrentfiles_location config['download_location'] = download_location config['autoadd_location'] = autoadd_location config['geoip_db_location'] = geoip_db_location config['plugins_location'] = plugins_location config['listen_ports'] = listen_ports config['daemon_port'] = daemon_port config['random_port'] = random_port config.save()
def _handle_ui_options(self, options): """Handle UI common and process group options. Args: options (argparse.Namespace): The parsed options. Returns: argparse.Namespace: The parsed options. """ if not self.common_setup: self.common_setup = True # Setup the logger if options.quiet: options.loglevel = 'none' if options.loglevel: options.loglevel = options.loglevel.lower() logfile_mode = 'w' logrotate = options.logrotate if options.logrotate: logfile_mode = 'a' logrotate = common.parse_human_size(options.logrotate) # Setup the logger deluge.log.setup_logger( level=options.loglevel, filename=options.logfile, filemode=logfile_mode, logrotate=logrotate, output_stream=self.log_stream, ) if options.config: if not set_config_dir(options.config): log = logging.getLogger(__name__) log.error( 'There was an error setting the config dir! Exiting..') sys.exit(1) else: if not os.path.exists(common.get_default_config_dir()): os.makedirs(common.get_default_config_dir()) if self.process_arg_group: self.process_arg_group = False # If donotdaemonize is set, skip process forking. if not (common.windows_check() or options.donotdaemonize): if os.fork(): os._exit(0) os.setsid() # Do second fork if os.fork(): os._exit(0) # Ensure process doesn't keep any directory in use that may prevent a filesystem unmount. os.chdir(get_config_dir()) # Write pid file before chuid if options.pidfile: with open(options.pidfile, 'w') as _file: _file.write('%d\n' % os.getpid()) if not common.windows_check(): if options.group: if not options.group.isdigit(): import grp options.group = grp.getgrnam(options.group)[2] os.setgid(options.group) if options.user: if not options.user.isdigit(): import pwd options.user = pwd.getpwnam(options.user)[2] os.setuid(options.user) return options
def _handle_ui_options(self, options): """Handle UI common and process group options. Args: options (argparse.Namespace): The parsed options. Returns: argparse.Namespace: The parsed options. """ if not self.common_setup: self.common_setup = True # Setup the logger if options.quiet: options.loglevel = 'none' if options.loglevel: options.loglevel = options.loglevel.lower() logfile_mode = 'w' logrotate = options.logrotate if options.logrotate: logfile_mode = 'a' logrotate = common.parse_human_size(options.logrotate) # Setup the logger deluge.log.setup_logger(level=options.loglevel, filename=options.logfile, filemode=logfile_mode, logrotate=logrotate, output_stream=self.log_stream) if options.config: if not set_config_dir(options.config): log = logging.getLogger(__name__) log.error('There was an error setting the config dir! Exiting..') sys.exit(1) else: if not os.path.exists(common.get_default_config_dir()): os.makedirs(common.get_default_config_dir()) if self.process_arg_group: self.process_arg_group = False # If donotdaemonize is set, skip process forking. if not (common.windows_check() or options.donotdaemonize): if os.fork(): os._exit(0) os.setsid() # Do second fork if os.fork(): os._exit(0) # Ensure process doesn't keep any directory in use that may prevent a filesystem unmount. os.chdir(get_config_dir()) # Write pid file before chuid if options.pidfile: with open(options.pidfile, 'wb') as _file: _file.write('%d\n' % os.getpid()) if not common.windows_check(): if options.user: if not options.user.isdigit(): import pwd options.user = pwd.getpwnam(options.user)[2] os.setuid(options.user) if options.group: if not options.group.isdigit(): import grp options.group = grp.getgrnam(options.group)[2] os.setuid(options.group) return options