From b35ad4587f640e0b1b8298562f879935c8d1e293 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 6 Apr 2009 13:34:12 +0200 Subject: [PATCH] entropy.const, entropy.core, entropy.server.interfaces.main: move server-side settings to SystemSettings. Server interface is not making use of it yet. --- libraries/entropy/const.py | 168 ------------------ libraries/entropy/core.py | 181 +++++++++++++++++++- libraries/entropy/server/interfaces/main.py | 4 +- 3 files changed, 182 insertions(+), 171 deletions(-) diff --git a/libraries/entropy/const.py b/libraries/entropy/const.py index 94aff3ca8..d35257109 100644 --- a/libraries/entropy/const.py +++ b/libraries/entropy/const.py @@ -122,8 +122,6 @@ def initconfig_entropy_constants(rootdir): const_setup_entropy_pid() const_read_repo_settings() const_configure_lock_paths() - # server stuff - const_read_srv_settings() # reflow back settings etpConst.update(backed_up_settings) @@ -1041,123 +1039,6 @@ def const_configure_lock_paths(): } -def const_read_srv_settings(): - - """ - Setup Entropy Server settings reading them from - the relative config. file (server.conf) specified in - etpConst['serverconf'] - - @return None - """ - - if not os.access(etpConst['serverconf'], os.R_OK): - return - - etpConst['server_repositories'].clear() - - with open(etpConst['serverconf'],"r") as server_f: - serverconf = [x.strip() for x in server_f.readlines() if x.strip()] - - for line in serverconf: - - if line.startswith("branches|") and (len(line.split("branches|")) == 2): - - branches = line.split("branches|")[1] - etpConst['branches'] = [] - for branch in branches.split(): - etpConst['branches'].append(branch) - if etpConst['branch'] not in etpConst['branches']: - etpConst['branches'].append(etpConst['branch']) - etpConst['branches'] = sorted(etpConst['branches']) - - elif (line.find("officialserverrepositoryid|") != -1) and \ - (not line.startswith("#")) and (len(line.split("|")) == 2): - - etpConst['officialserverrepositoryid'] = line.split("|")[1].strip() - - elif (line.find("expiration-days|") != -1) and \ - (not line.startswith("#")) and (len(line.split("|")) == 2): - - mydays = line.split("|")[1].strip() - try: - mydays = int(mydays) - etpConst['packagesexpirationdays'] = mydays - except ValueError: - continue - - elif line.startswith("repository|") and \ - (len(line.split("|")) in [5, 6]): - - repoid, repodata = const_extract_srv_repo_params(line) - if repoid in etpConst['server_repositories']: - # just update mirrors - etpConst['server_repositories'][repoid]['mirrors'].extend( - repodata['mirrors']) - else: - etpConst['server_repositories'][repoid] = repodata.copy() - - elif line.startswith("database-format|") and \ - (len(line.split("database-format|")) == 2): - - fmt = line.split("database-format|")[1] - if fmt in etpConst['etpdatabasesupportedcformats']: - etpConst['etpdatabasefileformat'] = fmt - - elif line.startswith("rss-feed|") and \ - (len(line.split("rss-feed|")) == 2): - - feed = line.split("rss-feed|")[1] - if feed in ("enable", "enabled", "true", "1"): - etpConst['rss-feed'] = True - elif feed in ("disable", "disabled", "false", "0", "no",): - etpConst['rss-feed'] = False - - elif line.startswith("rss-name|") and \ - (len(line.split("rss-name|")) == 2): - - feedname = line.split("rss-name|")[1].strip() - etpConst['rss-name'] = feedname - - elif line.startswith("rss-base-url|") and \ - (len(line.split("rss-base-url|")) == 2): - - etpConst['rss-base-url'] = line.split("rss-base-url|")[1].strip() - if not etpConst['rss-base-url'][-1] == "/": - etpConst['rss-base-url'] += "/" - - elif line.startswith("rss-website-url|") and \ - (len(line.split("rss-website-url|")) == 2): - - etpConst['rss-website-url'] = \ - line.split("rss-website-url|")[1].strip() - - elif line.startswith("managing-editor|") and \ - (len(line.split("managing-editor|")) == 2): - - etpConst['rss-managing-editor'] = \ - line.split("managing-editor|")[1].strip() - - elif line.startswith("max-rss-entries|") and \ - (len(line.split("max-rss-entries|")) == 2): - - try: - entries = int(line.split("max-rss-entries|")[1].strip()) - etpConst['rss-max-entries'] = entries - except (ValueError, IndexError,): - continue - - elif line.startswith("max-rss-light-entries|") and \ - (len(line.split("max-rss-light-entries|")) == 2): - - try: - entries = int(line.split("max-rss-light-entries|")[1].strip()) - etpConst['rss-light-max-entries'] = entries - except (ValueError, IndexError,): - continue - - const_config_server_repo_paths() - def const_extract_srv_repo_params(repostring): """ Analyze a server repository string (usually contained in server.conf), @@ -1209,55 +1090,6 @@ def const_extract_srv_repo_params(repostring): return repoid, mydata -def const_config_server_repo_paths(): - """ - Configure Entropy Server repository paths. - - @return None - """ - for repoid in etpConst['server_repositories']: - etpConst['server_repositories'][repoid]['packages_dir'] = \ - os.path.join( etpConst['entropyworkdir'], - "server", - repoid, - "packages", - etpSys['arch'] - ) - etpConst['server_repositories'][repoid]['store_dir'] = \ - os.path.join( etpConst['entropyworkdir'], - "server", - repoid, - "store", - etpSys['arch'] - ) - etpConst['server_repositories'][repoid]['upload_dir'] = \ - os.path.join( etpConst['entropyworkdir'], - "server", - repoid, - "upload", - etpSys['arch'] - ) - etpConst['server_repositories'][repoid]['database_dir'] = \ - os.path.join( etpConst['entropyworkdir'], - "server", - repoid, - "database", - etpSys['arch'] - ) - etpConst['server_repositories'][repoid]['packages_relative_path'] = \ - os.path.join( etpConst['product'], - repoid, - "packages", - etpSys['arch'] - )+"/" - etpConst['server_repositories'][repoid]['database_relative_path'] = \ - os.path.join( etpConst['product'], - repoid, - "database", - etpSys['arch'] - )+"/" - - def const_setup_environment(): """ Read environment variables and updates entropy settings. diff --git a/libraries/entropy/core.py b/libraries/entropy/core.py index e7f70df01..ba9b48fb4 100644 --- a/libraries/entropy/core.py +++ b/libraries/entropy/core.py @@ -182,6 +182,7 @@ class SystemSettings(Singleton): 'socket_service': etpConst['socketconf'], 'system': etpConst['entropyconf'], 'client': etpConst['clientconf'], + 'server': etpConst['serverconf'], }) ## XXX trunk support, for a while - exp. date 10/10/2009 @@ -224,7 +225,7 @@ class SystemSettings(Singleton): 'live_packagemasking': { 'unmask_matches': set(), 'mask_matches': set(), - } + }, } ) @@ -881,6 +882,12 @@ class SystemSettings(Singleton): def system_parser(self): + """ + Parses Entropy system configuration file. + + @return dict data + """ + data = {} data['proxy'] = etpConst['proxy'].copy() data['name'] = etpConst['systemname'] @@ -961,6 +968,12 @@ class SystemSettings(Singleton): def client_parser(self): + """ + Parses Entropy client system configuration file. + + @return dict data + """ + data = { 'filesbackup': etpConst['filesbackup'], 'ignore_spm_downgrades': etpConst['spm']['ignore-spm-downgrades'], @@ -1028,6 +1041,172 @@ class SystemSettings(Singleton): return data + def server_parser(self): + + """ + Parses Entropy server system configuration file. + + @return dict data + """ + + data = { + 'repositories': etpConst['server_repositories'].copy(), + 'branches': etpConst['branches'][:], + 'default_repository_id': etpConst['officialserverrepositoryid'], + 'packages_expiration_days': etpConst['packagesexpirationdays'], + 'database_file_format': etpConst['etpdatabasefileformat'], + 'rss': { + 'enabled': etpConst['rss-feed'], + 'name': etpConst['rss-name'], + 'base_url': etpConst['rss-base-url'], + 'website_url': etpConst['rss-website-url'], + 'editor': etpConst['rss-managing-editor'], + 'max_entries': etpConst['rss-max-entries'], + 'light_max_entries': etpConst['rss-light-max-entries'], + }, + } + + if not os.access(etpConst['serverconf'], os.R_OK): + return data + + with open(etpConst['serverconf'],"r") as server_f: + serverconf = [x.strip() for x in server_f.readlines() if x.strip()] + + for line in serverconf: + + split_line = line.split("|") + split_line_len = len(split_line) + + if line.startswith("branches|") and (split_line_len == 2): + + branches = split_line[1] + data['branches'] = [] + for branch in branches.split(): + data['branches'].append(branch) + if etpConst['branch'] not in data['branches']: + data['branches'].append(etpConst['branch']) + data['branches'] = sorted(data['branches']) + + elif (line.find("officialserverrepositoryid|") != -1) and \ + (not line.startswith("#")) and (split_line_len == 2): + + data['default_repository_id'] = split_line[1].strip() + + elif (line.find("expiration-days|") != -1) and \ + (not line.startswith("#")) 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("repository|") and (split_line_len in [5, 6]): + + repoid, repodata = const_extract_srv_repo_params(line) + if repoid in data['repositories']: + # just update mirrors + data['repositories'][repoid]['mirrors'].extend( + repodata['mirrors']) + else: + data['repositories'][repoid] = repodata.copy() + + 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("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 + + # now setup paths properly + for repoid in data['repositories']: + data['repositories'][repoid]['packages_dir'] = \ + os.path.join( etpConst['entropyworkdir'], + "server", + repoid, + "packages", + etpSys['arch'] + ) + data['repositories'][repoid]['store_dir'] = \ + os.path.join( etpConst['entropyworkdir'], + "server", + repoid, + "store", + etpSys['arch'] + ) + data['repositories'][repoid]['upload_dir'] = \ + os.path.join( etpConst['entropyworkdir'], + "server", + repoid, + "upload", + etpSys['arch'] + ) + data['repositories'][repoid]['database_dir'] = \ + os.path.join( etpConst['entropyworkdir'], + "server", + repoid, + "database", + etpSys['arch'] + ) + data['repositories'][repoid]['packages_relative_path'] = \ + os.path.join( etpConst['product'], + repoid, + "packages", + etpSys['arch'] + )+"/" + data['repositories'][repoid]['database_relative_path'] = \ + os.path.join( etpConst['product'], + repoid, + "database", + etpSys['arch'] + )+"/" + + return data + def __generic_parser(self, filepath): """ diff --git a/libraries/entropy/server/interfaces/main.py b/libraries/entropy/server/interfaces/main.py index 481dfa216..6b7cff5ec 100644 --- a/libraries/entropy/server/interfaces/main.py +++ b/libraries/entropy/server/interfaces/main.py @@ -26,7 +26,7 @@ import shutil from entropy.core import Singleton from entropy.exceptions import * from entropy.const import etpConst, etpSys, const_setup_perms, \ - const_create_working_dirs, const_read_srv_settings + const_create_working_dirs from entropy.output import TextInterface, purple, red, darkgreen, \ bold, brown, blue, darkred, darkblue from entropy.server.interfaces.mirrors import Server as MirrorsServer @@ -406,7 +406,7 @@ class Server(Singleton,TextInterface): shutil.move(tmpfile,etpConst['serverconf']) if status: self.close_server_databases() - const_read_srv_settings() + self.SystemSettings.clear() self.setup_services() self.show_interface_status() return status