Bump version to 0.15
[snf-cloudcms] / cloudcms / clients.py
index efed810..53f960e 100644 (file)
@@ -10,7 +10,7 @@ import urllib, urllib2, cookielib, urlparse
 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)
 
@@ -24,8 +24,9 @@ class VersionSource(object):
         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
@@ -169,10 +170,50 @@ class ClientVersions(object):
             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
 }
-