Entropy: move entropy.conf parsing into SystemSettings Singleton
class. As announced, SystemSettings is going to host all the Entropy global variables. With this big commit, proxy config (and the rest of entropy.conf data) has been moved under SystemSettings['system']
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user