from datetime import datetime
from lxml import html
-from synnefo import settings
+from django.conf import settings
CLIENTS_CACHE_TIMEOUT = getattr(settings, 'CLOUDCMS_CLIENTS_CACHE_TIMEOUT', 120)
self.arch = arch
self.link = link
self.versions = []
- extra_options.update({'source_type': self.source_type, 'os': os})
- self.extra_version_options = extra_options
+ self.extra_version_options = {}
+ self.extra_version_options.update(extra_options)
+ self.extra_version_options.update({'source_type': self.source_type, 'os': self.os})
self.cache_backend = cache_backend
self.cache_key = self.os + self.arch + self.link
yield source.get_latest()
+
+class PithosXMLSource(VersionSource):
+ """
+ Extract version from versioninfo.xml
+ """
+ source_type = 'pithos_xml'
+
+ def load(self):
+ """
+ Extract first item from versioninfo.xml
+ """
+ spliturl = urlparse.urlsplit(self.link)
+ baseurl = spliturl.geturl().replace(spliturl.path, '')
+ html = self.get_url(self.link)
+ items = html.xpath("//item")
+
+ # helper lambdas
+ def _parse_row(row):
+ try:
+ name = row.find("title").text
+ link = row.find("enclosure").attrib["url"]
+ strdate = row.find("pubdate").text
+ date = datetime.strptime(strdate.split(" +")[0],
+ "%a, %d %B %Y %H:%M:%S")
+ print "DATE", date
+ version = row.find("title").text
+ return {
+ 'name': name,
+ 'link': link,
+ 'date': date,
+ 'version': version
+ }
+ except Exception, e:
+ return None
+
+ versions = filter(bool, map(_parse_row, items))
+ self.versions = versions
+ return self
+
+
# SOURCE TYPES CLASS MAP
SOURCE_TYPES = {
'redmine_files': RedmineSource,
'direct': DirectSource,
+ 'pithos_xml': PithosXMLSource,
'link': LinkSource
}
-