def __loadResource(resource): """ Loads resources configuration from the default and custom config files @param resource: resource to fetch the config for @return: resources XML representation """ default_resourece = ConfigManager.RESOURCES_CONFIG_DIR + os.sep + resource + ".xml" custom_resourece = ConfigManager.CUSTOM_RESOURCES_CONFIG_DIR + os.sep + resource + "s.xml" if os.path.exists(default_resourece) and os.path.isfile(default_resourece): if os.path.exists(custom_resourece) and os.path.isfile(custom_resourece): return XmlUtils.combine([default_resourece, custom_resourece]) return FileUtils.getContent(default_resourece) else: raise NotFoundResourceConfigError(resource)
def combine(files): """ Combines XML files @param files: list of xml files to combine @return: combined XML """ combined = [] if files and len(files) >= 2: elements = [et.parse(f).getroot() for f in files] for r in elements[1:]: for child in r._children: root_copy = deepcopy(elements[0]) XmlUtils.__combineElement(root_copy, child) xml_str = et.tostring(root_copy, encoding='utf8', method='xml') combined.append(xml_str) return combined elif len(files) == 1: return FileUtils.getContent(files[0])