Skip to content
Snippets Groups Projects

:hammer: rewrote expanding to allow blacklisting

Merged Vincent Hatakeyama requested to merge topic/default/blacklisting into branch/default
+ 11
6
"""Functions to read configuration.
"""
from collections import defaultdict
import configparser
import logging
import os
@@ -4,4 +3,5 @@
import configparser
import logging
import os
import re
import sys
@@ -7,4 +7,5 @@
import sys
from collections import defaultdict
from glob import glob
from typing import List, Optional
@@ -60,6 +61,13 @@
_logger.error("Expansion without path for %s", name)
raise Exception("Expansion without path for %s" % name)
else:
if not blacklist or value["path"] not in glob(blacklist):
if blacklist and re.match(blacklist, value["path"]):
_logger.info(
"Ignoring directory '%s' due to blacklisting",
value["path"],
)
else:
if path:
value["path"] = os.path.join(path, value["path"])
# read expanded configurations
self._expanded_configuration[name] = Configuration(**value)
@@ -64,9 +72,5 @@
# read expanded configurations
self._expanded_configuration[name] = Configuration(**value)
else:
_logger.info(
"Ignoring %s due to blacklisting", value["path"]
)
def set_from_glob_values(
base: Optional[str], glob_values: List[str]
@@ -95,6 +99,7 @@
set_values.update(getattr(config, key))
# get the values from this configuration
values = section.get(key, "").split()
# XXX eventually add option to not include path
set_values.update(set_from_glob_values(path, values))
setattr(self, key, list(set_values))
Loading