diff sat_website/utils.py @ 39:d2c45f4ba57e

add downloads.html
author souliane <souliane@mailoo.org>
date Tue, 27 Jan 2015 18:23:39 +0100
parents 31d196cf3b34
children dfe7139dae0a
line wrap: on
line diff
--- a/sat_website/utils.py	Tue Jan 27 12:17:09 2015 +0100
+++ b/sat_website/utils.py	Tue Jan 27 18:23:39 2015 +0100
@@ -20,24 +20,33 @@
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-from os.path import basename,realpath,join
+from os.path import basename, realpath, join
 from django.conf import settings
+from collections import OrderedDict
+
+
+def get_projects_infos(infos):
+    """Return a dict binding project names to a tuple containing:
+        - the external download path
+        - the version number
+        - a short description about the project archive
+        
+    @param infos: dict binding project names to a short description
 
-def get_latest_sat():
-    """Return a tuple with download path of latest SàT version, and version number"""
-    try:
-        path = settings.SAT_LINK_PATH
-        real_path = realpath(path)
-        filename = basename(real_path)
-        version = filename[4:-8] #filename must be in the form of sat-version.tar.bz2
-        if hasattr(settings, "SAT_DL_PATH"):
-            dl_path = settings.SAT_DL_PATH
-        else:
-            dl_path = join(settings.SAT_DL_PREFIX, filename)
-    except AttributeError:
-        return (None, None)
-    
-    return (dl_path, version)
+    @return: dict {unicode: (unicode, unicode, unicode)
+    """
+    result = OrderedDict()
+    for dir, name in settings.PROJECTS_NAMES:
+        if not name:
+            name = dir
+        path = join(dir, name) + settings.ARCHIVE_SUFFIX  # e.g urwid-satext/urwid_satext.tar.bz2
+        int_path = join(settings.PROJECTS_INTERNAL_PATH, path)  # this is a symbolic link
+        # base name of the real path MUST look like: <project>-<version><ARCHIVE_SUFFIX>
+        version = basename(realpath(int_path))[len(name) + 1:-len(settings.ARCHIVE_SUFFIX)]
+        ext_path = join(settings.PROJECTS_EXTERNAL_PATH, path)
+        result[name] = (ext_path, version, infos[name] if name in infos else '')
+
+    return result
 
 def get_libervia_demo_url():
     """Return the URL to Libervia online demo"""