2 from sfa.util.xml import XML
3 from sfa.util.config import Config
7 required_fields = ['version', 'url']
9 template = """<api_versions>
10 <api_version name="" version="" url="" />
13 def __init__(self, string=None, filename=None, create=False):
23 # load the default file
25 api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
26 self.load(api_versions_file)
29 self.xml = XML(string=ApiVersions.template)
31 def load(self, source):
32 self.xml = XML(source)
34 def get_versions(self):
36 for value in self.xml.todict().values():
39 if isinstance(value, list):
41 if isinstance(item, dict) and \
42 set(ApiVersions.required_fields).issubset(item.keys()) and \
43 item['version'] != '' and item['url'] != '':
44 versions[str(item['version'])] = item['url']