diff --git a/libraries/entropy/client/interfaces/client.py b/libraries/entropy/client/interfaces/client.py index 7f833a95d..f006b399a 100644 --- a/libraries/entropy/client/interfaces/client.py +++ b/libraries/entropy/client/interfaces/client.py @@ -458,128 +458,117 @@ class ClientSystemSettingsPlugin(SystemSettingsPlugin): if not (os.path.isfile(cli_conf) and os.access(cli_conf, os.R_OK)): return data + def _filesbackup(setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['filesbackup'] = bool_setting + + def _forcedupdates(setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['forcedupdates'] = bool_setting + + def _autoprune(setting): + int_setting = entropy.tools.setting_to_int(setting, 0, 365) + if int_setting is not None: + data['autoprune_days'] = int_setting + + def _packagehashes(setting): + setting = setting.lower().split() + hashes = set() + for opt in setting: + if opt in etpConst['packagehashes']: + hashes.add(opt) + if hashes: + data['packagehashes'] = tuple(sorted(hashes)) + + def _multifetch(setting): + int_setting = entropy.tools.setting_to_int(setting, None, None) + bool_setting = entropy.tools.setting_to_bool(setting) + if int_setting is not None: + if int_setting not in range(2, 11): + int_setting = 10 + data['multifetch'] = int_setting + if bool_setting is not None: + if bool_setting: + data['multifetch'] = 3 + + def _gpg(setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['gpg'] = bool_setting + + def _spm_downgrades(setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['ignore_spm_downgrades'] = bool_setting + + def _splitdebug(setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['splitdebug'] = bool_setting + + def _collisionprotect(setting): + int_setting = entropy.tools.setting_to_int(setting, 0, 2) + if int_setting is not None: + data['collisionprotect'] = int_setting + + def _configprotect(setting): + for opt in setting.split(): + data['configprotect'].append(const_convert_to_unicode(opt)) + + def _configprotectmask(setting): + for opt in setting.split(): + data['configprotectmask'].append(const_convert_to_unicode(opt)) + + def _configprotectskip(setting): + for opt in setting.split(): + data['configprotectskip'].append( + etpConst['systemroot'] + const_convert_to_unicode(opt)) + + settings_map = { + # backward compatibility + 'filesbackup': _filesbackup, + 'files-backup': _filesbackup, + # backward compatibility + 'forcedupdates': _forcedupdates, + 'forced-updates': _forcedupdates, + 'packages-autoprune-days': _autoprune, + # backward compatibility + 'packagehashes': _packagehashes, + 'package-hashes': _packagehashes, + 'multifetch': _multifetch, + 'gpg': _gpg, + 'ignore-spm-downgrades': _spm_downgrades, + 'splitdebug': _splitdebug, + # backward compatibility + 'collisionprotect': _collisionprotect, + 'collision-protect': _collisionprotect, + # backward compatibility + 'configprotect': _configprotect, + 'config-protect': _configprotect, + # backward compatibility + 'configprotectmask': _configprotectmask, + 'config-protect-mask': _configprotectmask, + # backward compatibility + 'configprotectskip': _configprotectskip, + 'config-protect-skip': _configprotectskip, + } + client_f = open(cli_conf, "r") clientconf = [x.strip() for x in client_f.readlines() if \ x.strip() and not x.strip().startswith("#")] client_f.close() for line in clientconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - if (line.startswith("filesbackup|") or \ - line.startswith("files-backup|")) and (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - if compatopt in ("disable", "disabled", "false", "0", "no",): - data['filesbackup'] = False - - elif (line.startswith("forcedupdates|") or \ - line.startswith("forced-updates|")) and (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - if compatopt in ("disable", "disabled", "false", "0", "no",): - data['forcedupdates'] = False - else: - data['forcedupdates'] = True - - elif line.startswith("packages-autoprune-days|") and \ - (split_line_len == 2): - - prune_opt = split_line[1].strip() - try: - autoprune_days = int(prune_opt) - if autoprune_days < 0: - raise ValueError() - if autoprune_days > 365: - raise ValueError() - data['autoprune_days'] = autoprune_days - except ValueError: - data['autoprune_days'] = None - - elif (line.startswith("packagehashes|") or \ - line.startswith("package-hashes|")) and (split_line_len == 2): - - opts = split_line[1].strip().lower().split() - hashes = [] - for opt in opts: - if opt in etpConst['packagehashes']: - hashes.append(opt) - if hashes: - data['packagehashes'] = tuple(hashes) - - elif line.startswith("multifetch|") and (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - try: - compatopt_int = int(compatopt) - except ValueError: - compatopt_int = None - if compatopt_int is not None: - if compatopt_int not in range(2, 11): - compatopt_int = 10 - data['multifetch'] = compatopt_int - elif compatopt in ("enable", "enabled", "true",): - data['multifetch'] = 3 - - elif line.startswith("gpg|") and (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - if compatopt in ("disable", "disabled", "false", "0", "no",): - data['gpg'] = False - else: - data['gpg'] = True - - elif line.startswith("ignore-spm-downgrades|") and \ - (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - if compatopt in ("enable", "enabled", "true", "1", "yes"): - data['ignore_spm_downgrades'] = True - - elif line.startswith("splitdebug|") and \ - (split_line_len == 2): - - compatopt = split_line[1].strip().lower() - if compatopt in ("enable", "enabled", "true", "1", "yes"): - data['splitdebug'] = True - else: - data['splitdebug'] = False - - elif (line.startswith("collisionprotect|") or \ - line.startswith("collision-protect|")) and \ - (split_line_len == 2): - - collopt = split_line[1].strip() - if collopt.lower() in ("0", "1", "2",): - data['collisionprotect'] = int(collopt) - - elif (line.startswith("configprotect|") or \ - line.startswith("config-protect|")) and (split_line_len == 2): - - configprotect = split_line[1].strip() - for myprot in configprotect.split(): - data['configprotect'].append( - const_convert_to_unicode(myprot)) - - elif (line.startswith("configprotectmask|") or \ - line.startswith("config-protect-mask|")) and \ - (split_line_len == 2): - - configprotect = split_line[1].strip() - for myprot in configprotect.split(): - data['configprotectmask'].append( - const_convert_to_unicode(myprot)) - - elif (line.startswith("configprotectskip|") or \ - line.startswith("config-protect-skip|")) and \ - (split_line_len == 2): - - configprotect = split_line[1].strip() - for myprot in configprotect.split(): - data['configprotectskip'].append( - etpConst['systemroot'] + \ - const_convert_to_unicode(myprot)) + func = settings_map.get(key) + if func is None: + continue + func(value) # completely disable GPG feature if not data['gpg'] and ("gpg" in data['packagehashes']): diff --git a/libraries/entropy/core/settings/base.py b/libraries/entropy/core/settings/base.py index 9253794e8..f7a4553fd 100644 --- a/libraries/entropy/core/settings/base.py +++ b/libraries/entropy/core/settings/base.py @@ -808,90 +808,75 @@ class SystemSettings(Singleton, EntropyPluginStore): x.strip() and not x.strip().startswith("#")] socket_f.close() + def _listen(setting): + data['hostname'] = setting + + def _listen_port(setting): + try: + data['port'] = int(setting) + except ValueError: + return + + def _listen_timeout(setting): + try: + data['timeout'] = int(setting) + except ValueError: + return + + def _listen_threads(setting): + try: + data['threads'] = int(setting) + except ValueError: + return + + def _session_ttl(setting): + try: + data['session_ttl'] = int(setting) + except ValueError: + return + + def _max_connections(setting): + try: + data['max_connections'] = int(setting) + except ValueError: + return + + def _ssl_port(setting): + try: + data['ssl_port'] = int(setting) + except ValueError: + return + + def _disabled_commands(setting): + for disabled_cmd in setting.split(): + data['disabled_cmds'].add(disabled_cmd) + + def _ip_blacklist(setting): + for ip_blacklist in setting.split(): + data['ip_blacklist'].add(ip_blacklist) + + settings_map = { + 'listen': _listen, + 'listen-port': _listen_port, + 'listen-timeout': _listen_timeout, + 'listen-threads': _listen_threads, + 'session-ttl': _session_ttl, + 'max-connections': _max_connections, + 'ssl-port': _ssl_port, + 'disabled-commands': _disabled_commands, + 'ip-blacklist': _ip_blacklist, + } + for line in socketconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - if line.startswith("listen|") and (split_line_len > 1): - - item = split_line[1].strip() - if item: - data['hostname'] = item - - elif line.startswith("listen-port|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['port'] = item - except ValueError: - continue - - elif line.startswith("listen-timeout|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['timeout'] = item - except ValueError: - continue - - elif line.startswith("listen-threads|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['threads'] = item - except ValueError: - continue - - elif line.startswith("session-ttl|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['session_ttl'] = item - except ValueError: - continue - - elif line.startswith("max-connections|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['max_connections'] = item - except ValueError: - continue - - elif line.startswith("ssl-port|") and \ - (split_line_len > 1): - - item = split_line[1].strip() - try: - item = int(item) - data['ssl_port'] = item - except ValueError: - continue - - elif line.startswith("disabled-commands|") and \ - (split_line_len > 1): - - disabled_cmds = split_line[1].strip().split() - for disabled_cmd in disabled_cmds: - data['disabled_cmds'].add(disabled_cmd) - - elif line.startswith("ip-blacklist|") and \ - (split_line_len > 1): - - ips_blacklist = split_line[1].strip().split() - for ip_blacklist in ips_blacklist: - data['ip_blacklist'].add(ip_blacklist) + func = settings_map.get(key) + if func is None: + continue + func(value) return data @@ -922,77 +907,76 @@ class SystemSettings(Singleton, EntropyPluginStore): x.strip() and not x.strip().startswith("#")] entropy_f.close() + def _loglevel(setting): + try: + loglevel = int(setting) + except ValueError: + return + if (loglevel > -1) and (loglevel < 3): + data['log_level'] = loglevel + + def _ftp_proxy(setting): + ftpproxy = setting.strip().split() + if ftpproxy: + data['proxy']['ftp'] = ftpproxy[-1] + + def _http_proxy(setting): + httpproxy = setting.strip().split() + if httpproxy: + data['proxy']['http'] = httpproxy[-1] + + def _rsync_proxy(setting): + rsyncproxy = setting.strip().split() + if rsyncproxy: + data['proxy']['rsync'] = rsyncproxy[-1] + + def _proxy_username(setting): + username = setting.strip().split() + if username: + data['proxy']['username'] = username[-1] + + def _proxy_password(setting): + password = setting.strip().split() + if password: + data['proxy']['password'] = password[-1] + + def _name(setting): + data['name'] = setting.strip() + + def _spm_backend(setting): + data['spm_backend'] = setting.strip() + + def _nice_level(setting): + mylevel = setting.strip() + try: + mylevel = int(mylevel) + if (mylevel >= -19) and (mylevel <= 19): + const_set_nice_level(mylevel) + except (ValueError,): + return + + settings_map = { + 'loglevel': _loglevel, + 'ftp-proxy': _ftp_proxy, + 'http-proxy': _http_proxy, + 'rsync-proxy': _rsync_proxy, + 'proxy-username': _proxy_username, + 'proxy-password': _proxy_password, + 'system-name': _name, + 'spm-backend': _spm_backend, + 'nice-level': _nice_level, + } + for line in entropyconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - if line.startswith("loglevel|") and \ - (len(line.split("loglevel|")) == 2): - - loglevel = line.split("loglevel|")[1] - try: - loglevel = int(loglevel) - except ValueError: - pass - if (loglevel > -1) and (loglevel < 3): - data['log_level'] = loglevel - - elif line.startswith("ftp-proxy|") and \ - (split_line_len == 2): - - ftpproxy = split_line[1].strip().split() - if ftpproxy: - data['proxy']['ftp'] = ftpproxy[-1] - - elif line.startswith("http-proxy|") and \ - (split_line_len == 2): - - httpproxy = split_line[1].strip().split() - if httpproxy: - data['proxy']['http'] = httpproxy[-1] - - elif line.startswith("rsync-proxy|") and \ - (split_line_len == 2): - - httpproxy = split_line[1].strip().split() - if httpproxy: - data['proxy']['rsync'] = httpproxy[-1] - - elif line.startswith("proxy-username|") and \ - (split_line_len == 2): - - httpproxy = split_line[1].strip().split() - if httpproxy: - data['proxy']['username'] = httpproxy[-1] - - elif line.startswith("proxy-password|") and \ - (split_line_len == 2): - - httpproxy = split_line[1].strip().split() - if httpproxy: - data['proxy']['password'] = httpproxy[-1] - - elif line.startswith("system-name|") and \ - (split_line_len == 2): - - data['name'] = split_line[1].strip() - - elif line.startswith("spm-backend|") and \ - (split_line_len == 2): - - data['spm_backend'] = split_line[1].strip() - - elif line.startswith("nice-level|") and \ - (split_line_len == 2): - - mylevel = split_line[1].strip() - try: - mylevel = int(mylevel) - if (mylevel >= -19) and (mylevel <= 19): - const_set_nice_level(mylevel) - except (ValueError,): - continue + func = settings_map.get(key) + if func is None: + continue + func(value) return data @@ -1175,133 +1159,137 @@ class SystemSettings(Singleton, EntropyPluginStore): repo_f = open(repo_conf, "r") repositoriesconf = [x.strip() for x in repo_f.readlines() if x.strip()] repo_f.close() + repoids = set() + + def _product_func(line, setting): + data['product'] = setting + + def _branch_func(line, setting): + data['branch'] = setting + + def _repository_func(line, setting): + + excluded = False + my_repodata = data['available'] + if line.startswith("##"): + return + + elif line.startswith("#"): + excluded = True + my_repodata = data['excluded'] + line = line[1:] + + reponame, repodata = self._analyze_client_repo_string(line, + data['branch'], data['product']) + if reponame == etpConst['clientdbid']: + # not allowed!!! + return + + repoids.add(reponame) + if reponame in my_repodata: + + my_repodata[reponame]['plain_packages'].extend( + repodata['plain_packages']) + my_repodata[reponame]['packages'].extend( + repodata['packages']) + + if (not my_repodata[reponame]['plain_database']) and \ + repodata['plain_database']: + + my_repodata[reponame]['plain_database'] = \ + repodata['plain_database'] + my_repodata[reponame]['database'] = \ + repodata['database'] + my_repodata[reponame]['dbrevision'] = \ + repodata['dbrevision'] + my_repodata[reponame]['dbcformat'] = \ + repodata['dbcformat'] + + my_repodata[reponame]['service_uri'] = \ + repodata['service_uri'] + my_repodata[reponame]['service_port'] = \ + repodata['service_port'] + my_repodata[reponame]['ssl_service_port'] = \ + repodata['ssl_service_port'] + + else: + my_repodata[reponame] = repodata.copy() + if not excluded: + data['order'].append(reponame) + + def _offrepoid(line, setting): + data['default_repository'] = setting + + def _developer_repo(line, setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['developer_repo'] = bool_setting + + def _differential_update(line, setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['differential_update'] = bool_setting + + def _down_speed_limit(line, setting): + data['transfer_limit'] = None + try: + myval = int(setting) + if myval > 0: + data['transfer_limit'] = myval + except ValueError: + data['transfer_limit'] = None + + def _down_timeout(line, setting): + try: + data['timeout'] = int(setting) + except ValueError: + return + + def _security_url(setting): + data['security_advisories_url'] = setting + + settings_map = { + 'product': _product_func, + 'branch': _branch_func, + 'repository': _repository_func, + # backward compatibility + 'officialrepositoryid': _offrepoid, + 'official-repository-id': _offrepoid, + 'developer-repo': _developer_repo, + 'differential-update': _differential_update, + # backward compatibility + 'downloadspeedlimit': _down_speed_limit, + 'download-speed-limit': _down_speed_limit, + # backward compatibility + 'downloadtimeout': _down_timeout, + 'download-timeout': _down_timeout, + # backward compatibility + 'securityurl': _security_url, + 'security-url': _security_url, + } # setup product and branch first for line in repositoriesconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - if (line.find("product|") != -1) and \ - (not line.startswith("#")) and (split_line_len == 2): + func = settings_map.get(key) + if func is None: + continue + func(line, value) - data['product'] = split_line[1] - - elif (line.find("branch|") != -1) and \ - (not line.startswith("#")) and (split_line_len == 2): - - branch = split_line[1].strip() - data['branch'] = branch - - repoids = set() for line in repositoriesconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - # populate data['available'] - if (line.find("repository|") != -1) and (split_line_len == 5): - - excluded = False - my_repodata = data['available'] - if line.startswith("##"): - continue - elif line.startswith("#"): - excluded = True - my_repodata = data['excluded'] - line = line[1:] - - reponame, repodata = self._analyze_client_repo_string(line, - data['branch'], data['product']) - if reponame == etpConst['clientdbid']: - # not allowed!!! - continue - - repoids.add(reponame) - if reponame in my_repodata: - - my_repodata[reponame]['plain_packages'].extend( - repodata['plain_packages']) - my_repodata[reponame]['packages'].extend( - repodata['packages']) - - if (not my_repodata[reponame]['plain_database']) and \ - repodata['plain_database']: - - my_repodata[reponame]['plain_database'] = \ - repodata['plain_database'] - my_repodata[reponame]['database'] = \ - repodata['database'] - my_repodata[reponame]['dbrevision'] = \ - repodata['dbrevision'] - my_repodata[reponame]['dbcformat'] = \ - repodata['dbcformat'] - - my_repodata[reponame]['service_uri'] = \ - repodata['service_uri'] - my_repodata[reponame]['service_port'] = \ - repodata['service_port'] - my_repodata[reponame]['ssl_service_port'] = \ - repodata['ssl_service_port'] - - else: - - my_repodata[reponame] = repodata.copy() - if not excluded: - data['order'].append(reponame) - - elif (line.startswith("officialrepositoryid|") or \ - line.startswith("official-repository-id|")) \ - and (split_line_len == 2): - - officialreponame = split_line[1] - data['default_repository'] = officialreponame - - elif (line.startswith("developer-repo|")) \ - and (split_line_len == 2): - - dev_repo = split_line[1] - if dev_repo in ("enable", "enabled", "true", "1", "yes",): - data['developer_repo'] = True - - elif (line.startswith("differential-update|")) \ - and (split_line_len == 2): - - dev_repo = split_line[1] - if dev_repo in ("disable", "disabled", "false", "0", "no",): - data['differential_update'] = False - - elif (line.startswith("downloadspeedlimit|") or \ - line.startswith("download-speed-limit|")) \ - and (split_line_len == 2): - - try: - myval = int(split_line[1]) - if myval > 0: - data['transfer_limit'] = myval - else: - data['transfer_limit'] = None - except (ValueError, IndexError,): - data['transfer_limit'] = None - - elif (line.startswith("downloadtimeout|") or \ - line.startswith("download-timeout|")) \ - and (split_line_len == 2): - - try: - myval = int(split_line[1]) - data['timeout'] = myval - except (ValueError, IndexError,): - continue - - elif (line.startswith("securityurl|") or \ - line.startswith("security-url|")) \ - and (split_line_len == 2): - - try: - data['security_advisories_url'] = split_line[1] - except (IndexError, ValueError, TypeError,): - continue + func = settings_map.get(key) + if func is None: + continue + func(line, value) try: tx_limit = int(os.getenv("ETP_DOWNLOAD_KB")) diff --git a/libraries/entropy/server/interfaces/main.py b/libraries/entropy/server/interfaces/main.py index 4e377af83..140b39b44 100644 --- a/libraries/entropy/server/interfaces/main.py +++ b/libraries/entropy/server/interfaces/main.py @@ -571,148 +571,143 @@ class ServerSystemSettingsPlugin(SystemSettingsPlugin): default_repo_changed = False + def _offservrepoid(line, setting): + # NOTE: remove this in future, supported for backward compat. + # NOTE: added for backward and mixed compat. + if default_repo_changed: + return + if not fake_instance: + data['default_repository_id'] = setting.strip() + + def _default_repo(line, setting): + if not fake_instance: + data['default_repository_id'] = setting.strip() + default_repo_changed = True + + def _exp_days(line, setting): + mydays = setting.strip() + try: + mydays = int(mydays) + data['packages_expiration_days'] = mydays + except ValueError: + return + + def _exp_based_scope(line, setting): + exp_opt = entropy.tools.setting_to_bool(setting) + if exp_opt is not None: + data['exp_based_scope'] = exp_opt + + def _nf_packages_dir_sup(line, setting): + opt = entropy.tools.setting_to_bool(setting) + if opt is not None: + data['nonfree_packages_dir_support'] = opt + + def _disabled_eapis(line, setting): + mydis = setting.strip().split(",") + try: + mydis = [int(x) for x in mydis] + mydis = set([x for x in mydis if x in (1, 2, 3,)]) + except ValueError: + return + if (len(mydis) < 3) and mydis: + data['disabled_eapis'] = mydis + + def _server_basic_lang(line, setting): + data['qa_langs'] = setting.strip().split() + + def _repository_func(line, setting): + repoid, repodata = \ + ServerSystemSettingsPlugin.analyze_server_repo_string( + line, product = sys_set['repositories']['product']) + if repoid in data['repositories']: + # just update mirrors + data['repositories'][repoid]['pkg_mirrors'].extend( + repodata['pkg_mirrors']) + data['repositories'][repoid]['repo_mirrors'].extend( + repodata['repo_mirrors']) + else: + data['repositories'][repoid] = repodata.copy() + + # base_repository_id support + if data['base_repository_id'] is None: + data['base_repository_id'] = repoid + + def _database_format(line, setting): + if setting in etpConst['etpdatabasesupportedcformats']: + data['database_file_format'] = setting + + def _syncspeedlimit(line, setting): + try: + speed_limit = int(setting) + except ValueError: + speed_limit = None + data['sync_speed_limit'] = speed_limit + + def _rss_feed(line, setting): + bool_setting = entropy.tools.setting_to_bool(setting) + if bool_setting is not None: + data['rss']['enabled'] = bool_setting + + def _rss_name(line, setting): + data['rss']['name'] = setting + + def _rss_base_url(line, setting): + if not setting.endswith("/"): + setting += "/" + data['rss']['base_url'] = setting + + def _rss_website_url(line, setting): + data['rss']['website_url'] = setting + + def _managing_editor(line, setting): + data['rss']['editor'] = setting + + def _max_rss_entries(line, setting): + try: + entries = int(setting) + data['rss']['max_entries'] = entries + except (ValueError, IndexError,): + return + + def _max_rss_light_entries(line, setting): + try: + entries = int(setting) + data['rss']['light_max_entries'] = entries + except (ValueError, IndexError,): + return + + settings_map = { + 'officialserverrepositoryid': _offservrepoid, + 'default-repository': _default_repo, + 'expiration-days': _exp_days, + 'expiration-based-scope': _exp_based_scope, + 'nonfree-packages-directory-support': _nf_packages_dir_sup, + 'disabled-eapis': _disabled_eapis, + 'server-basic-languages': _server_basic_lang, + 'repository': _repository_func, + 'database-format': _database_format, + # backward compatibility + 'sync-speed-limit': _syncspeedlimit, + 'syncspeedlimit': _syncspeedlimit, + 'rss-feed': _rss_feed, + 'rss-name': _rss_name, + 'rss-base-url': _rss_base_url, + 'rss-website-url': _rss_website_url, + 'managing-editor': _managing_editor, + 'max-rss-entries': _max_rss_entries, + 'max-rss-light-entries': _max_rss_light_entries, + } + for line in serverconf: - split_line = line.split("|") - split_line_len = len(split_line) + key, value = entropy.tools.extract_setting(line) + if key is None: + continue - # NOTE: remove this in future, supported for backward compat. - if (line.find("officialserverrepositoryid|") != -1) and \ - (not line.startswith("#")) and (split_line_len == 2): - - # NOTE: added for backward and mixed compat. - if default_repo_changed: - continue - - if not fake_instance: - data['default_repository_id'] = split_line[1].strip() - - elif (line.find("default-repository|") != -1) and \ - (not line.startswith("#")) and (split_line_len == 2): - - if not fake_instance: - data['default_repository_id'] = split_line[1].strip() - default_repo_changed = True - - elif line.startswith("expiration-days|") and (split_line_len == 2): - - mydays = split_line[1].strip() - try: - mydays = int(mydays) - data['packages_expiration_days'] = mydays - except ValueError: - continue - - elif line.startswith("expiration-based-scope|") and \ - (split_line_len == 2): - - exp_opt = split_line[1].strip().lower() - if exp_opt in ("enable", "enabled", "true", "1", "yes"): - data['exp_based_scope'] = True - else: - data['exp_based_scope'] = False - - elif line.startswith("nonfree-packages-directory-support|") and \ - (split_line_len == 2): - - exp_opt = split_line[1].strip().lower() - if exp_opt in ("enable", "enabled", "true", "1", "yes"): - data['nonfree_packages_dir_support'] = True - else: - data['nonfree_packages_dir_support'] = False - - elif line.startswith("disabled-eapis|") and (split_line_len == 2): - - mydis = split_line[1].strip().split(",") - try: - mydis = [int(x) for x in mydis] - mydis = set([x for x in mydis if x in (1, 2, 3,)]) - except ValueError: - continue - if (len(mydis) < 3) and mydis: - data['disabled_eapis'] = mydis - - elif line.startswith("server-basic-languages|") and \ - (split_line_len == 2): - data['qa_langs'] = split_line[1].strip().split() - - elif line.startswith("repository|") and (split_line_len in (5, 6)) \ - and (not fake_instance): - - repoid, repodata = \ - ServerSystemSettingsPlugin.analyze_server_repo_string(line, - product = sys_set['repositories']['product']) - if repoid in data['repositories']: - # just update mirrors - data['repositories'][repoid]['pkg_mirrors'].extend( - repodata['pkg_mirrors']) - data['repositories'][repoid]['repo_mirrors'].extend( - repodata['repo_mirrors']) - else: - data['repositories'][repoid] = repodata.copy() - - # base_repository_id support - if data['base_repository_id'] is None: - data['base_repository_id'] = repoid - - elif line.startswith("database-format|") and (split_line_len == 2): - - fmt = split_line[1] - if fmt in etpConst['etpdatabasesupportedcformats']: - data['database_file_format'] = fmt - - elif (line.startswith("sync-speed-limit|") or \ - line.startswith("syncspeedlimit|")) and (split_line_len == 2): - - try: - speed_limit = int(split_line[1]) - except ValueError: - speed_limit = None - data['sync_speed_limit'] = speed_limit - - elif line.startswith("rss-feed|") and (split_line_len == 2): - - feed = split_line[1] - if feed in ("enable", "enabled", "true", "1"): - data['rss']['enabled'] = True - elif feed in ("disable", "disabled", "false", "0", "no",): - data['rss']['enabled'] = False - - elif line.startswith("rss-name|") and (split_line_len == 2): - - feedname = line.split("rss-name|")[1].strip() - data['rss']['name'] = feedname - - elif line.startswith("rss-base-url|") and (split_line_len == 2): - - data['rss']['base_url'] = line.split("rss-base-url|")[1].strip() - if not data['rss']['base_url'][-1] == "/": - data['rss']['base_url'] += "/" - - elif line.startswith("rss-website-url|") and (split_line_len == 2): - - data['rss']['website_url'] = split_line[1].strip() - - elif line.startswith("managing-editor|") and (split_line_len == 2): - - data['rss']['editor'] = split_line[1].strip() - - elif line.startswith("max-rss-entries|") and (split_line_len == 2): - - try: - entries = int(split_line[1].strip()) - data['rss']['max_entries'] = entries - except (ValueError, IndexError,): - continue - - elif line.startswith("max-rss-light-entries|") and \ - (split_line_len == 2): - - try: - entries = int(split_line[1].strip()) - data['rss']['light_max_entries'] = entries - except (ValueError, IndexError,): - continue + func = settings_map.get(key) + if func is None: + continue + func(line, value) # add system database if community repository mode is enabled if self._helper.community_repo: