diff --git a/yum/config.py b/yum/config.py index 3e91735..5ff13a6 100644 --- a/yum/config.py +++ b/yum/config.py @@ -40,7 +40,7 @@ if not _use_iniparse: import rpmUtils.transaction import Errors import types -from misc import get_uuid +from misc import get_uuid, read_in_items_from_dot_dir # Alter/patch these to change the default checking... __pkgs_gpgcheck_default__ = False @@ -161,7 +161,8 @@ class ListOption(Option): super(ListOption, self).__init__(default) def parse(self, s): - """Converts a string from the config file to a workable list + """Converts a string from the config file to a workable list, parses + globdir: paths as foo.d-style dirs Commas and spaces are used as separators for the list """ @@ -169,7 +170,15 @@ class ListOption(Option): # to sub the \n with a space and then read the lines s = s.replace('\n', ' ') s = s.replace(',', ' ') - return s.split() + results = [] + for item in s.split(): + if item.startswith('globdir:'): + globdir = item.replace('globdir:', '') + results.extend(read_in_items_from_dot_dir(globdir)) + continue + results.append(item) + + return results def tostring(self, value): return '\n '.join(value) @@ -228,8 +237,15 @@ class UrlListOption(ListOption): s = s.replace('\n', ' ') s = s.replace(',', ' ') items = [ item.replace(' ', '%20') for item in shlex.split(s) ] - s = ' '.join(items) - for url in super(UrlListOption, self).parse(s): + tmp = [] + for item in items: + if item.startswith('globdir:'): + globdir = item.replace('globdir:', '') + tmp.extend(read_in_items_from_dot_dir(globdir)) + continue + tmp.append(item) + + for url in super(UrlListOption, self).parse(' '.join(tmp)): out.append(self._urloption.parse(url)) return out diff --git a/yum/misc.py b/yum/misc.py index faccf5f..ebce8e1 100644 --- a/yum/misc.py +++ b/yum/misc.py @@ -1005,4 +1005,27 @@ def decompress(filename): return out - +def read_in_items_from_dot_dir(thisglob, line_as_list=True): + """takes a glob of a dir (like /etc/foo.d/*.foo) + returns a list of all the lines in all the files matching + that glob, ignores comments and blank lines, + optional paramater 'line_as_list tells whether to + treat each line as a space or comma-separated list, defaults to True""" + results = [] + for fname in glob.glob(thisglob): + for line in open(fname): + if re.match('\s*(#|$)', line): + continue + line = line.rstrip() # no more trailing \n's + line = line.lstrip() # be nice + if not line: + continue + if line_as_list: + line = line.replace('\n', ' ') + line = line.replace(',', ' ') + results.extend(line.split()) + continue + results.append(line) + return results + +