diff --git a/client/equo.py b/client/equo.py index 48bccd94c..decba53b3 100644 --- a/client/equo.py +++ b/client/equo.py @@ -30,6 +30,8 @@ from entropy.exceptions import * from entropy.const import * from entropy.output import * import entropy.tools as entropyTools +from entropy.core import SystemSettings +SysSettings = SystemSettings() try: from entropy.i18n import _ except ImportError: @@ -63,7 +65,7 @@ etpExitMessages = { myopts = [ None, - (0," ~ "+etpConst['systemname']+" ~ ",1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), + (0," ~ %s ~ " % (SysSettings['system']['name'],) ,1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), None, (0,_('Basic Options'),0,None), None, diff --git a/entropy-notification-applet/src/etp_applet_dialogs.py b/entropy-notification-applet/src/etp_applet_dialogs.py index f1b146f7f..6347af44d 100644 --- a/entropy-notification-applet/src/etp_applet_dialogs.py +++ b/entropy-notification-applet/src/etp_applet_dialogs.py @@ -16,7 +16,8 @@ import gtk import gtkhtml2 from entropy.const import etpConst from entropy.i18n import _ - +from entropy.core import SystemSettings +SysSettings = SystemSettings() class rhnGladeWindow: def __init__(self, filename, window_name): @@ -81,7 +82,7 @@ class rhnAppletNoticeWindow(rhnGladeWindow): sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_border_width(2) sw.add(html_view) - + tab_label = gtk.Label(_("Critical Information")) tab_label.show() @@ -139,11 +140,11 @@ class rhnRegistrationPromptDialog(rhnGladeWindow): def set_transient(self, papa): self.window.set_transient_for(papa.window) - + def on_rhnreg(self, button): self.parent.launch_rhnreg() self.close_dialog() - + def close_dialog(self, *rest): self.window.destroy() self.parent.rhnreg_dialog_closed() @@ -152,11 +153,14 @@ class rhnRegistrationPromptDialog(rhnGladeWindow): self.close_dialog() class rhnAppletAboutWindow: + def __init__(self, parent): - self.window = gnome.ui.About("%s Updates Applet" % (etpConst['systemname'],), - etpConst['entropyversion'], "Copyright (C) 2008, Sabayon Linux", - "Sabayon Linux. What else?", - [ "Sabayon Linux Team", "devel@sabayonlinux.org" ]) + self.window = gnome.ui.About("%s Updates Applet" % ( + SysSettings['system']['name'], + ), + etpConst['entropyversion'], "Copyright (C) 2009, Sabayon Linux", + "Sabayon Linux. What else?", + [ "Sabayon Linux Team", "devel@sabayonlinux.org" ]) self.window.connect("destroy", self.on_close) self.parent = parent self.window.show() diff --git a/libraries/entropy/client/interfaces/trigger.py b/libraries/entropy/client/interfaces/trigger.py index 661752009..2d1719f66 100644 --- a/libraries/entropy/client/interfaces/trigger.py +++ b/libraries/entropy/client/interfaces/trigger.py @@ -1337,8 +1337,8 @@ class Trigger: return 0 def __get_entropy_kernel_grub_line(self, kernel): - return "title=%s (%s)\n" % (etpConst['systemname'], - os.path.basename(kernel),) + sys_name = self.Entropy.SystemSettings['system']['name'] + return "title=%s (%s)\n" % (sys_name, os.path.basename(kernel),) ''' @description: append kernel entry to grub.conf diff --git a/libraries/entropy/const.py b/libraries/entropy/const.py index 14ff2fcb3..44fa23513 100644 --- a/libraries/entropy/const.py +++ b/libraries/entropy/const.py @@ -120,7 +120,6 @@ def initconfig_entropy_constants(rootdir): const_read_entropy_release() const_create_working_dirs() const_setup_entropy_pid() - const_read_entropy_settings() const_read_repo_settings() const_configure_lock_paths() initconfig_client_constants() @@ -356,13 +355,13 @@ def const_default_settings(rootdir): # by equo inside triggerTools 'triggername': "trigger", 'trigger_sh_interpreter': "/usr/sbin/entropy.sh", + # proxy configuration constants, used system wide 'proxy': { 'ftp': None, 'http': None, 'username': None, 'password': None - }, # proxy configuration information, used system wide - + }, # Entropy log level (default: 1 - see entropy.conf for more info) 'entropyloglevel': 1, # Entropy Socket Interface log level @@ -849,83 +848,6 @@ def const_read_repo_settings(): except (IndexError, ValueError, TypeError,): continue -def const_read_entropy_settings(): - - """ - Setup Entropy settings by reading them from the relative - config file specified in etpConst['entropyconf'] - - @return None - """ - - etp_conf = etpConst['entropyconf'] - if not os.path.isfile(etp_conf) and \ - os.access(etp_conf,os.R_OK): - return - - const_secure_config_file(etp_conf) - entropy_f = open(etp_conf,"r") - entropyconf = [x.strip() for x in entropy_f.readlines() if \ - x.strip() and not x.strip().startswith("#")] - entropy_f.close() - - for line in entropyconf: - - 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): - etpConst['entropyloglevel'] = loglevel - - elif line.startswith("ftp-proxy|") and \ - (len(line.split("|")) == 2): - - ftpproxy = line.split("|")[1].strip().split() - if ftpproxy: - etpConst['proxy']['ftp'] = ftpproxy[-1] - - elif line.startswith("http-proxy|") and \ - (len(line.split("|")) == 2): - - httpproxy = line.split("|")[1].strip().split() - if httpproxy: - etpConst['proxy']['http'] = httpproxy[-1] - - elif line.startswith("proxy-username|") and \ - (len(line.split("|")) == 2): - - httpproxy = line.split("|")[1].strip().split() - if httpproxy: - etpConst['proxy']['username'] = httpproxy[-1] - - elif line.startswith("proxy-password|") and \ - (len(line.split("|")) == 2): - - httpproxy = line.split("|")[1].strip().split() - if httpproxy: - etpConst['proxy']['password'] = httpproxy[-1] - - elif line.startswith("system-name|") and \ - (len(line.split("|")) == 2): - - etpConst['systemname'] = line.split("|")[1].strip() - - elif line.startswith("nice-level|") and \ - (len(line.split("|")) == 2): - - mylevel = line.split("|")[1].strip() - try: - mylevel = int(mylevel) - if (mylevel >= -19) and (mylevel <= 19): - const_set_nice_level(mylevel) - except (ValueError,): - pass - def const_read_entropy_release(): """ Read Entropy release file content and fill etpConst['entropyversion'] diff --git a/libraries/entropy/core.py b/libraries/entropy/core.py index fc2155b9a..f14c7f5b4 100644 --- a/libraries/entropy/core.py +++ b/libraries/entropy/core.py @@ -24,7 +24,7 @@ import os from entropy.exceptions import IncorrectParameter, SystemDatabaseError from entropy.const import etpConst, const_setup_perms, etpRepositories, \ - etpRepositoriesOrder + etpRepositoriesOrder, const_secure_config_file, const_set_nice_level from entropy.i18n import _ class Singleton(object): @@ -180,6 +180,7 @@ class SystemSettings(Singleton): 'system_dirs': etpConst['confdir']+"/fsdirs.conf", 'system_dirs_mask': etpConst['confdir']+"/fsdirsmask.conf", 'socket_service': etpConst['socketconf'], + 'system': etpConst['entropyconf'], }) ## XXX trunk support, for a while - exp. date 10/10/2009 @@ -874,6 +875,84 @@ class SystemSettings(Singleton): return data + def system_parser(self): + + data = {} + data['proxy'] = etpConst['proxy'].copy() + data['name'] = etpConst['systemname'] + data['log_level'] = etpConst['entropyloglevel'] + + etp_conf = self.__setting_files['system'] + if not os.path.isfile(etp_conf) and \ + os.access(etp_conf,os.R_OK): + return + + const_secure_config_file(etp_conf) + entropy_f = open(etp_conf,"r") + entropyconf = [x.strip() for x in entropy_f.readlines() if \ + x.strip() and not x.strip().startswith("#")] + entropy_f.close() + + for line in entropyconf: + + 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 \ + (len(line.split("|")) == 2): + + ftpproxy = line.split("|")[1].strip().split() + if ftpproxy: + data['proxy']['ftp'] = ftpproxy[-1] + + elif line.startswith("http-proxy|") and \ + (len(line.split("|")) == 2): + + httpproxy = line.split("|")[1].strip().split() + if httpproxy: + data['proxy']['http'] = httpproxy[-1] + + elif line.startswith("proxy-username|") and \ + (len(line.split("|")) == 2): + + httpproxy = line.split("|")[1].strip().split() + if httpproxy: + data['proxy']['username'] = httpproxy[-1] + + elif line.startswith("proxy-password|") and \ + (len(line.split("|")) == 2): + + httpproxy = line.split("|")[1].strip().split() + if httpproxy: + data['proxy']['password'] = httpproxy[-1] + + elif line.startswith("system-name|") and \ + (len(line.split("|")) == 2): + + data['name'] = line.split("|")[1].strip() + + elif line.startswith("nice-level|") and \ + (len(line.split("|")) == 2): + + mylevel = line.split("|")[1].strip() + try: + mylevel = int(mylevel) + if (mylevel >= -19) and (mylevel <= 19): + const_set_nice_level(mylevel) + except (ValueError,): + pass + + return data + + def __generic_parser(self, filepath): """ Internal method. This is the generic file parser here. diff --git a/libraries/entropy/misc.py b/libraries/entropy/misc.py index 56b69e39f..28731ab2a 100644 --- a/libraries/entropy/misc.py +++ b/libraries/entropy/misc.py @@ -27,6 +27,7 @@ import time import urllib2 import threading from entropy.const import etpConst, etpUi +from entropy.core import SystemSettings class Lifo: @@ -330,13 +331,14 @@ class rssFeed: import tools as entropyTools def __init__(self, filename, title, description, maxentries = 100): + self.__system_settings = SystemSettings() self.__feed_title = title self.__feed_title = self.__feed_title.strip() self.__feed_description = description self.__feed_language = "en-EN" self.__feed_editor = etpConst['rss-managing-editor'] self.__feed_copyright = "%s - (C) %s" % ( - etpConst['systemname'], + self.__system_settings['system']['name'], self.entropyTools.get_year(), ) @@ -446,7 +448,7 @@ class rssFeed: if link: self.__items[self.__itemscounter]['guid'] = link else: - myguid = etpConst['systemname'].lower() + myguid = self.__system_settings['system']['name'].lower() myguid = myguid.replace(" ", "") self.__items[self.__itemscounter]['guid'] = myguid+"~" + \ description + str(self.__itemscounter) diff --git a/libraries/entropy/qa.py b/libraries/entropy/qa.py index 675aebf4f..1b93e2328 100644 --- a/libraries/entropy/qa.py +++ b/libraries/entropy/qa.py @@ -445,20 +445,23 @@ class ErrorReportInterface: import entropy.tools as entropyTools def __init__(self, post_url = etpConst['handlers']['errorsend']): from entropy.misc import MultipartPostHandler + from entropy.core import SystemSettings import urllib2 self.url = post_url self.opener = urllib2.build_opener(MultipartPostHandler) self.generated = False self.params = {} + sys_settings = SystemSettings() + proxy_settings = sys_settings['system']['proxy'] mydict = {} - if etpConst['proxy']['ftp']: - mydict['ftp'] = etpConst['proxy']['ftp'] - if etpConst['proxy']['http']: - mydict['http'] = etpConst['proxy']['http'] + if proxy_settings['ftp']: + mydict['ftp'] = proxy_settings['ftp'] + if proxy_settings['http']: + mydict['http'] = proxy_settings['http'] if mydict: - mydict['username'] = etpConst['proxy']['username'] - mydict['password'] = etpConst['proxy']['password'] + mydict['username'] = proxy_settings['username'] + mydict['password'] = proxy_settings['password'] self.entropyTools.add_proxy_opener(urllib2,mydict) else: # unset diff --git a/libraries/entropy/server/interfaces/main.py b/libraries/entropy/server/interfaces/main.py index 5394af1e2..fe23791d3 100644 --- a/libraries/entropy/server/interfaces/main.py +++ b/libraries/entropy/server/interfaces/main.py @@ -31,6 +31,7 @@ from entropy.output import TextInterface, purple, red, darkgreen, \ bold, brown, blue, darkred, darkblue from entropy.server.interfaces.mirrors import Server as MirrorsServer from entropy.i18n import _ +from entropy.core import SystemSettings class Server(Singleton,TextInterface): @@ -42,8 +43,9 @@ class Server(Singleton,TextInterface): raise PermissionDenied("PermissionDenied: %s" % (mytxt,)) from entropy.misc import LogFile + sys_settings = SystemSettings() self.serverLog = LogFile( - level = etpConst['entropyloglevel'], + level = sys_settings['system']['log_level'], filename = etpConst['entropylogfile'], header = "[server]" ) @@ -2046,16 +2048,16 @@ class Server(Singleton,TextInterface): request = os.path.join(url,etpConst['handlers']['md5sum']) request += filename+"&branch="+branch - # now pray the server + proxy_settings = self.SystemSettings['system']['proxy'] try: mydict = {} - if etpConst['proxy']['ftp']: - mydict['ftp'] = etpConst['proxy']['ftp'] - if etpConst['proxy']['http']: - mydict['http'] = etpConst['proxy']['http'] + if proxy_settings['ftp']: + mydict['ftp'] = proxy_settings['ftp'] + if proxy_settings['http']: + mydict['http'] = proxy_settings['http'] if mydict: - mydict['username'] = etpConst['proxy']['username'] - mydict['password'] = etpConst['proxy']['password'] + mydict['username'] = proxy_settings['username'] + mydict['password'] = proxy_settings['password'] self.entropyTools.add_proxy_opener(urllib2, mydict) else: # unset diff --git a/libraries/entropy/server/interfaces/mirrors.py b/libraries/entropy/server/interfaces/mirrors.py index c5ef4b027..97f5c52ea 100644 --- a/libraries/entropy/server/interfaces/mirrors.py +++ b/libraries/entropy/server/interfaces/mirrors.py @@ -771,7 +771,8 @@ class Server: def update_notice_board(self, title, notice_text, link = None, repo = None): - rss_title = "%s Notice Board" % (etpConst['systemname'],) + sys_settings = self.Entropy.SystemSettings + rss_title = "%s Notice Board" % (sys_settings['system']['name'],) rss_description = "Inform about important distribution activities." rss_path = self.Entropy.get_local_database_notice_board_file(repo) if not link: link = etpConst['rss-website-url'] @@ -794,8 +795,9 @@ class Server: def remove_from_notice_board(self, identifier, repo = None): + sys_settings = self.Entropy.SystemSettings rss_path = self.Entropy.get_local_database_notice_board_file(repo) - rss_title = "%s Notice Board" % (etpConst['systemname'],) + rss_title = "%s Notice Board" % (sys_settings['system']['name'],) rss_description = "Inform about important distribution activities." if not (os.path.isfile(rss_path) and os.access(rss_path,os.R_OK)): return 0 @@ -806,14 +808,17 @@ class Server: def update_rss_feed(self, repo = None): + sys_settings = self.Entropy.SystemSettings #db_dir = self.Entropy.get_local_database_dir(repo) rss_path = self.Entropy.get_local_database_rss_file(repo) rss_light_path = self.Entropy.get_local_database_rsslight_file(repo) rss_dump_name = etpConst['rss-dump-name'] db_revision_path = self.Entropy.get_local_database_revision_file(repo) - rss_title = "%s Online Repository Status" % (etpConst['systemname'],) - rss_description = "Keep you updated on what's going on in the %s Repository." % (etpConst['systemname'],) + rss_title = "%s Online Repository Status" % ( + sys_settings['system']['name'],) + rss_description = "Keep you updated on what's going on in the %s Repository." % ( + sys_settings['system']['name'],) Rss = self.rssFeed(rss_path, rss_title, rss_description, maxentries = etpConst['rss-max-entries']) # load dump db_actions = self.Cacher.pop(rss_dump_name) @@ -827,7 +832,12 @@ class Server: commitmessage = '' if self.Entropy.rssMessages['commitmessage']: commitmessage = ' :: '+self.Entropy.rssMessages['commitmessage'] - title = ": "+etpConst['systemname']+" "+etpConst['product'][0].upper()+etpConst['product'][1:]+" "+etpConst['branch']+" :: Revision: "+revision+commitmessage + + title = ": " + sys_settings['system']['name'] + " " + \ + etpConst['product'][0].upper() + etpConst['product'][1:] + \ + " " + etpConst['branch'] + " :: Revision: " + revision + \ + commitmessage + link = etpConst['rss-base-url'] # create description added_items = db_actions.get("added") diff --git a/libraries/entropy/services/interfaces.py b/libraries/entropy/services/interfaces.py index 0f146b877..68c11d5ab 100644 --- a/libraries/entropy/services/interfaces.py +++ b/libraries/entropy/services/interfaces.py @@ -1307,6 +1307,8 @@ class SocketHost: def docmd_hello(self, transmitter): from entropy.tools import getstatusoutput + from entropy.core import SystemSettings + sys_settings = SystemSettings() uname = os.uname() kern_string = uname[2] running_host = uname[1] @@ -1315,7 +1317,7 @@ class SocketHost: text = "Entropy Server %s, connections: %s ~ running on: %s ~ host: %s ~ arch: %s, kernel: %s, stats: %s\n" % ( etpConst['entropyversion'], self.HostInterface.connections, - etpConst['systemname'], + sys_settings['system']['name'], running_host, running_arch, kern_string, diff --git a/libraries/entropy/services/ugc/interfaces.py b/libraries/entropy/services/ugc/interfaces.py index ba479c69f..ead6e4621 100644 --- a/libraries/entropy/services/ugc/interfaces.py +++ b/libraries/entropy/services/ugc/interfaces.py @@ -186,7 +186,9 @@ class Server(RemoteDatabase): self.initialize_tables() self.initialize_doctypes() self.setup_store_path(store_path) - self.system_name = etpConst['systemname'] + from entropy.core import SystemSettings + self.__system_settings = SystemSettings() + self.system_name = self.__system_settings['system']['name'] from datetime import datetime self.datetime = datetime try: diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index acb170683..5919aba91 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -151,15 +151,18 @@ def get_remote_data(url): import urllib2 socket.setdefaulttimeout(60) # now pray the server + from entropy.core import SystemSettings + sys_settings = SystemSettings() + proxy_settings = sys_settings['system']['proxy'] try: mydict = {} - if etpConst['proxy']['ftp']: - mydict['ftp'] = etpConst['proxy']['ftp'] - if etpConst['proxy']['http']: - mydict['http'] = etpConst['proxy']['http'] + if proxy_settings['ftp']: + mydict['ftp'] = proxy_settings['ftp'] + if proxy_settings['http']: + mydict['http'] = proxy_settings['http'] if mydict: - mydict['username'] = etpConst['proxy']['username'] - mydict['password'] = etpConst['proxy']['password'] + mydict['username'] = proxy_settings['username'] + mydict['password'] = proxy_settings['password'] add_proxy_opener(urllib2, mydict) else: # unset diff --git a/libraries/entropy/transceivers.py b/libraries/entropy/transceivers.py index d77dbe90a..52773adb2 100644 --- a/libraries/entropy/transceivers.py +++ b/libraries/entropy/transceivers.py @@ -24,11 +24,12 @@ import os import urllib2 import time from entropy.const import etpConst -from entropy.output import TextInterface, darkblue, darkred, purple, blue, brown, darkgreen, red, bold +from entropy.output import TextInterface, darkblue, darkred, purple, blue, \ + brown, darkgreen, red, bold from entropy.exceptions import * from entropy.i18n import _ from entropy.misc import TimeScheduled, ParallelTask - +from entropy.core import SystemSettings class urlFetcher: @@ -38,6 +39,7 @@ class urlFetcher: thread_stop_func = None, speed_limit = etpConst['downloadspeedlimit'], OutputInterface = None): + self.__system_settings = SystemSettings() self.progress = None import entropy.tools as entropyTools import socket @@ -135,13 +137,14 @@ class urlFetcher: def _setup_proxy(self): # setup proxy, doing here because config is dynamic mydict = {} - if etpConst['proxy']['ftp']: - mydict['ftp'] = etpConst['proxy']['ftp'] - if etpConst['proxy']['http']: - mydict['http'] = etpConst['proxy']['http'] + proxy_data = self.__system_settings['system']['proxy'] + if proxy_data['ftp']: + mydict['ftp'] = proxy_data['ftp'] + if proxy_data['http']: + mydict['http'] = proxy_data['http'] if mydict: - mydict['username'] = etpConst['proxy']['username'] - mydict['password'] = etpConst['proxy']['password'] + mydict['username'] = proxy_data['username'] + mydict['password'] = proxy_data['password'] self.entropyTools.add_proxy_opener(urllib2, mydict) else: # unset diff --git a/server/activator.py b/server/activator.py index 8fae22771..691cb077e 100644 --- a/server/activator.py +++ b/server/activator.py @@ -31,10 +31,12 @@ from entropy.i18n import _ import entropy.tools as entropyTools from entropy.output import * from entropy.const import * +from entropy.core import SystemSettings +SysSettings = SystemSettings() myopts = [ None, - (0," ~ "+etpConst['systemname']+" ~ "+sys.argv[0]+" ~ ",1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), + (0," ~ "+SysSettings['system']['name']+" ~ "+sys.argv[0]+" ~ ",1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), None, (0,_('Basic Options'),0,None), None, diff --git a/server/reagent.py b/server/reagent.py index fdf716fee..697dbf661 100644 --- a/server/reagent.py +++ b/server/reagent.py @@ -32,10 +32,12 @@ from entropy.i18n import _ import entropy.tools as entropyTools from entropy.output import * from entropy.const import * +from entropy.core import SystemSettings +SysSettings = SystemSettings() myopts = [ None, - (0," ~ "+etpConst['systemname']+" ~ "+sys.argv[0]+" ~ ",1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), + (0," ~ "+SysSettings['system']['name']+" ~ "+sys.argv[0]+" ~ ",1,'Entropy Package Manager - (C) %s' % (entropyTools.get_year(),) ), None, (0,_('Basic Options'),0,None), None, diff --git a/spritz/src/spritz.py b/spritz/src/spritz.py index 40e23e505..0257710a4 100644 --- a/spritz/src/spritz.py +++ b/spritz/src/spritz.py @@ -957,7 +957,7 @@ class SpritzApplication(Controller): etpConst['entropyconf']: [ ( 'ftp-proxy', - etpConst['proxy']['ftp'], + self.Equo.SystemSettings['system']['proxy']['ftp'], basestring, fillSetting, saveSetting, @@ -966,7 +966,7 @@ class SpritzApplication(Controller): ), ( 'http-proxy', - etpConst['proxy']['http'], + self.Equo.SystemSettings['system']['proxy']['http'], basestring, fillSetting, saveSetting, @@ -975,7 +975,7 @@ class SpritzApplication(Controller): ), ( 'proxy-username', - etpConst['proxy']['username'], + self.Equo.SystemSettings['system']['proxy']['username'], basestring, fillSetting, saveSetting, @@ -984,7 +984,7 @@ class SpritzApplication(Controller): ), ( 'proxy-password', - etpConst['proxy']['password'], + self.Equo.SystemSettings['system']['proxy']['password'], basestring, fillSetting, saveSetting,