diff --git a/WebappConfig/config.py b/WebappConfig/config.py index 1c09488..227fd33 100644 --- a/WebappConfig/config.py +++ b/WebappConfig/config.py @@ -188,7 +188,7 @@ class BashConfigParser(configparser_ConfigParser): # allow empty values if optval == '""': optval = '' - if optval[0] == '"' and optval[-1] == '"' : + elif optval[0] == '"' and optval[-1] == '"' : optval = optval[1:-1] optname = self.optionxform(optname.rstrip()) cursect[optname] = optval @@ -311,7 +311,7 @@ class Config: def set_configprotect(self): self.config.set('USER', 'config_protect', - wrapper.config_protect(self.maybe_get('cat'), + wrapper.config_protect(self, self.maybe_get('cat'), self.config.get('USER', 'pn'), self.config.get('USER', 'pvr'), self.config.get('USER', 'package_manager') )) @@ -822,7 +822,6 @@ class Config: + self.config.get('USER', 'my_etcconfig') + ' needs updating!') - OUT.debug('Successfully parsed configuration file options', 7) # Parse the command line @@ -1520,7 +1519,7 @@ class Config: 'dotconfig' : self.create_dotconfig(), 'ebuild' : self.create_ebuild(), 'db' : self.create_webapp_db(category, package, version), - 'protect' : Protection(category,package,version, + 'protect' : Protection(self, category,package,version, self.config.get('USER','package_manager')), 'content' : content} diff --git a/WebappConfig/protect.py b/WebappConfig/protect.py index 4a24d55..e38f66f 100644 --- a/WebappConfig/protect.py +++ b/WebappConfig/protect.py @@ -23,6 +23,7 @@ import re, os, os.path import WebappConfig.wrapper +from WebappConfig.config import Config from WebappConfig.debug import OUT @@ -35,12 +36,13 @@ class Protection: A small helper class to handle config protection. ''' - def __init__(self, cat, pn, pvr, pm): + def __init__(self, config, cat, pn, pvr, pm): ''' This is distribution specific so the information is provided by wrapper.py ''' - self.config_protect = WebappConfig.wrapper.config_protect(cat, pn, pvr, pm) + self.config = config + self.config_protect = WebappConfig.wrapper.config_protect(self.config, cat, pn, pvr, pm) self.protect_prefix = WebappConfig.wrapper.protect_prefix self.update_command = WebappConfig.wrapper.update_command @@ -70,7 +72,9 @@ class Protection: >>> import os.path >>> here = os.path.dirname(os.path.realpath(__file__)) - >>> a = Protection('','horde','3.0.5','portage') + >>> import WebappConfig + >>> config = WebappConfig.config.Config() + >>> a = Protection(config,'','horde','3.0.5','portage') >>> a.get_protectedname(here + '/tests/testfiles/protect/empty', ... 'test')#doctest: +ELLIPSIS '.../tests/testfiles/protect/empty//._cfg0000_test' @@ -117,8 +121,10 @@ class Protection: Traverses the path of parent directories for the given install dir and checks if any matches the list of config protected files. - - >>> a = Protection('','horde','3.0.5','portage') + + >>> import WebappConfig + >>> config = WebappConfig.config.Config() + >>> a = Protection(config,'','horde','3.0.5','portage') Add a virtual config protected directory: @@ -177,8 +183,10 @@ class Protection: ''' Instruct the user how to update the application. + >>> import WebappConfig + >>> config = WebappConfig.config.Config() >>> OUT.color_off() - >>> a = Protection('','horde','3.0.5','portage') + >>> a = Protection(config, '','horde','3.0.5','portage') >>> a.how_to_update(['/my/strange/htdocs/where/i/installed/x']) * One or more files have been config protected diff --git a/WebappConfig/wrapper.py b/WebappConfig/wrapper.py index a9e2a3b..16346ec 100644 --- a/WebappConfig/wrapper.py +++ b/WebappConfig/wrapper.py @@ -41,7 +41,14 @@ update_command = 'etc-update' # Link for bug reporting bugs_link = 'http://bugs.gentoo.org/' -def config_protect(cat, pn, pvr, pm): +def config_protect(config, cat, pn, pvr, pm): + def safe_join(a, b): + if a and b: + return a + ' ' + b + if a: + return a + return b + '''Return CONFIG_PROTECT (used by protect.py)''' if pm == "portage": try: @@ -49,7 +56,7 @@ def config_protect(cat, pn, pvr, pm): except ImportError as e: OUT.die("Portage libraries not found, quitting:\n%s" % e) - return portage.settings['CONFIG_PROTECT'] + return safe_join(config.maybe_get("config_protect"),portage.settings['CONFIG_PROTECT']) elif pm == "paludis": cmd="cave print-id-environment-variable -b --format '%%v\n' --variable-name CONFIG_PROTECT %s/%s" % (cat,pn) @@ -60,7 +67,7 @@ def config_protect(cat, pn, pvr, pm): fo.close() fe.close() - return ' '.join(result_lines).strip() + return safe_join(config.maybe_get("config_protect"), ' '.join(result_lines).strip()) else: OUT.die("Unknown package manager: " + pm)