Filter out components not listed in origins file

If component is not mentioned in origins file (like oslo-messaging in
havana-1) this means it is not needed for this origins and it should
be ignored.

Change-Id: I8ce113bd823d6a3d3f1c743b30585af79966720e
This commit is contained in:
Ivan A. Melnikov 2013-12-26 21:28:22 +02:00
parent bb679fe3ea
commit d10a5db610
4 changed files with 16 additions and 22 deletions

View File

@ -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))

View File

@ -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 []

View File

@ -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)

View File

@ -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