def load(self, plugin_path=None): """Loads data from the given plugin path and producing data tree. :param plugin_path: plugin root path :param plugin_path: str|basestring|None :return: data tree starting from the data in root metadata file :rtype: tuple(dict, utils.ReportNode) """ plugin_path = plugin_path or self.plugin_path report = utils.ReportNode( u"File structure validation: {}".format(plugin_path)) data, root_report = self._load_root_metadata_file() report.add_nodes(root_report) # load files with fixed location for key, file_path in six.iteritems(self.paths_to_fields): file_report = utils.ReportNode(file_path) try: data[key] = self.files_manager.load( self._get_absolute_path(file_path)) except errors.NoPluginFileFound as exc: data[key] = None file_report.warning(exc) except Exception as exc: file_report.error(exc) finally: report.add_nodes(file_report) if report.is_failed(): raise errors.ParseError(report.render()) return data, report
def _load_config(self, file_name): config = os.path.join(self.plugin_path, file_name) if os.access(config, os.R_OK): with open(config, "r") as conf: try: return yaml.safe_load(conf.read()) except yaml.YAMLError as exc: logger.warning(exc) raise errors.ParseError( 'Problem with loading YAML file {0}'.format(config)) else: logger.warning("Config {0} is not readable.".format(config))
def _get_package_version_from_path(plugin_path): config = os.path.join(plugin_path, PLUGIN_ROOT_FILE) if os.access(config, os.R_OK): with open(config, "r") as conf: try: return yaml.safe_load( conf.read()).get(PLUGIN_PACKAGE_VERSION_FIELD) except yaml.YAMLError as exc: logger.warning(exc) raise errors.ParseError( 'Problem with loading YAML file {0}'.format(config)) else: raise Exception("Config {0} is not readable.".format(config))
def p_error(p): raise errors.ParseError("Syntax error at '%s'" % getattr(p, 'value', ''))