diff --git a/anvil/__main__.py b/anvil/__main__.py index 931954e2..8301fe6e 100644 --- a/anvil/__main__.py +++ b/anvil/__main__.py @@ -102,7 +102,7 @@ def run(args): # Load + verify the person try: persona_obj = persona.load(persona_fn) - persona_obj.verify(dist) + persona_obj.verify(dist, args['origins_fn']) except Exception as e: raise excp.OptionException("Error loading persona file: %s due to %s" % (persona_fn, e)) diff --git a/anvil/components/base_install.py b/anvil/components/base_install.py index abd1898d..0b387b7e 100644 --- a/anvil/components/base_install.py +++ b/anvil/components/base_install.py @@ -20,7 +20,6 @@ from anvil import settings from anvil import shell as sh from anvil import trace as tr from anvil import utils -import yaml from anvil.packaging.helpers import pip_helper @@ -144,8 +143,7 @@ class PythonInstallComponent(PkgInstallComponent): def download(self): """Download sources needed to build the component, if any.""" target_dir = self.get_option('app_dir') - with open(self._origins_fn, 'r') as fh: - download_cfg = yaml.safe_load(fh.read()).get(self.name, {}) + download_cfg = utils.load_yaml(self._origins_fn).get(self.name, {}) if not target_dir or not download_cfg: return [] diff --git a/anvil/distro.py b/anvil/distro.py index 55f0dfdf..8cf3e08c 100644 --- a/anvil/distro.py +++ b/anvil/distro.py @@ -22,13 +22,12 @@ import platform import re import shlex -import yaml - from anvil import colorizer from anvil import exceptions as excp from anvil import importer from anvil import log as logging from anvil import shell as sh +from anvil import utils LOG = logging.getLogger(__name__) @@ -145,12 +144,8 @@ def load(path): for fn in input_files: LOG.debug("Attempting to load distro definition from %r", fn) try: - # Don't use sh here so that we always - # read this (even if dry-run) - with open(fn, 'r') as fh: - contents = fh.read() - cls_kvs = yaml.safe_load(contents) - distro_possibles.append(Distro(**cls_kvs)) - except (IOError, yaml.YAMLError) as err: + cls_kvs = utils.load_yaml(fn) + except Exception as err: LOG.warning('Could not load distro definition from %r: %s', fn, err) + distro_possibles.append(Distro(**cls_kvs)) return _match_distro(distro_possibles) diff --git a/anvil/persona.py b/anvil/persona.py index 4ab67928..e25d8d13 100644 --- a/anvil/persona.py +++ b/anvil/persona.py @@ -14,9 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -import yaml - from anvil import log as logging +from anvil import utils LOG = logging.getLogger(__name__) @@ -25,12 +24,18 @@ class Persona(object): def __init__(self, supports, components, **kargs): self.distro_support = supports or [] - self.wanted_components = components or [] self.source = kargs.get('source') + self.wanted_components = components or [] self.wanted_subsystems = kargs.get('subsystems') or {} self.component_options = kargs.get('options') or {} - def verify(self, distro): + def verify(self, distro, origins_fn): + # Filter components out that are not in origins file + available_components = set(utils.load_yaml(origins_fn).iterkeys()) + available_components.add('general') + self.wanted_components = [c for c in self.wanted_components + if c in available_components] + # Some sanity checks against the given distro/persona d_name = distro.name if d_name not in self.distro_support: @@ -41,11 +46,7 @@ class Persona(object): def load(fn): - # Don't use sh here so that we always - # read this (even if dry-run) - with open(fn, 'r') as fh: - contents = fh.read() - cls_kvs = yaml.safe_load(contents) + cls_kvs = utils.load_yaml(fn) cls_kvs['source'] = fn instance = Persona(**cls_kvs) return instance