deb-murano/murano/packages/package.py
Stan Lagun 9a9f3436e1 Version-aware YAML loading
* Refactoring of "packages" Python package
* Now MuranoPL YAML classes can be parsed by different engines
depending on Format string in package manifest

With this change MuranoPL classes will no longer
be read and parsed (including YAQL expressions parsing)
upon package load but only on first class access and
with ability to peak different parsers depending on
format version specified in manifest. As a consequence
it is now possible to use different YAQL engines for
different package format versions. Also startup
time was greatly improved as unneeded classes are no more
parsed and logos and UI forms are not loaded.

Partially implements: blueprint murano-versioning

Change-Id: I23fc5da1a43b405d526438329dc04aed589dee13
2015-09-03 12:07:13 +00:00

128 lines
3.1 KiB
Python

# Copyright (c) 2015 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import abc
import io
import os
import zipfile
import six
class PackageType(object):
Library = 'Library'
Application = 'Application'
ALL = [Library, Application]
@six.add_metaclass(abc.ABCMeta)
class Package(object):
def __init__(self, source_directory, package_format, runtime_version):
self._source_directory = source_directory
self._format = package_format
self._runtime_version = runtime_version
self._blob_cache = None
@property
def format(self):
return self._format
@abc.abstractproperty
def full_name(self):
raise NotImplementedError()
@abc.abstractproperty
def version(self):
raise NotImplementedError()
@abc.abstractproperty
def classes(self):
raise NotImplementedError()
@property
def runtime_version(self):
return self._runtime_version
@abc.abstractproperty
def requirements(self):
raise NotImplementedError()
@abc.abstractproperty
def package_type(self):
raise NotImplementedError()
@abc.abstractproperty
def display_name(self):
raise NotImplementedError()
@abc.abstractproperty
def description(self):
raise NotImplementedError()
@abc.abstractproperty
def author(self):
raise NotImplementedError()
@abc.abstractproperty
def supplier(self):
raise NotImplementedError()
@abc.abstractproperty
def tags(self):
raise NotImplementedError()
@abc.abstractproperty
def logo(self):
raise NotImplementedError()
@abc.abstractproperty
def supplier_logo(self):
raise NotImplementedError()
@property
def blob(self):
if not self._blob_cache:
self._blob_cache = _pack_dir(self._source_directory)
return self._blob_cache
@abc.abstractmethod
def get_class(self, name):
raise NotImplementedError()
@abc.abstractmethod
def get_resource(self, name):
raise NotImplementedError()
@abc.abstractproperty
def ui(self):
raise NotImplementedError()
def _zip_dir(path, zip_file):
for root, dirs, files in os.walk(path):
for f in files:
abs_path = os.path.join(root, f)
relative_path = os.path.relpath(abs_path, path)
zip_file.write(abs_path, relative_path)
def _pack_dir(source_directory):
blob = io.BytesIO()
zip_file = zipfile.ZipFile(blob, mode='w')
_zip_dir(source_directory, zip_file)
zip_file.close()
return blob.getvalue()