Commits

Janto Dreijer committed 6cb15f9

news sidebar

  • Participants
  • Parent commits 2d351b2

Comments (0)

Files changed (3)

File code/scikits.py

 		title = self.name
 		search_box_html = SearchPage.search_box()
 
-		#~ # latest changes
-		#~ newest_packages_html = ""
-		#~ news_items = []
-		#~ for packages in Package.packages().values():
-			#~ version = package.latest_version()
-			#~ news_items.append((the_time, text))
-		#~ news_items.sort(reverse=True)
-		#~ if news_items:
-			#~ newest_packages_html = """
+		# latest changes
 
-			#~ """
+		## query pypi for changelog
+		changes, expired = Cache.get("pypi_changelog")
+		if expired:
+			server = xmlrpclib.ServerProxy('http://pypi.python.org/pypi', transport=GoogleXMLRPCTransport())
+			new_changes = server.changelog(int(time.time() - SECONDS_IN_WEEK)) # changes made in last week
+			if new_changes:
+				Cache.set("pypi_changelog", value=new_changes, duration=SECONDS_IN_HOUR)
+			changes = new_changes
+		changes = changes if changes is not None else []
+
+		changes = [c for c in changes if "scikit" in c[0].lower()] # filter changes relevant to scikits
+
+		## convert to html
+		max_items = 5
+		newest_packages_html = []
+		if changes:
+			newest_packages_html.append("<h3>News</h3>")
+			items = 0
+			for (name, version), g in groupby(sorted(changes), key=lambda c: (c[0], c[1])):
+				newest_packages_html.append('<a href="http://pypi.python.org/pypi/%(name)s">%(name)s</a>' % locals())
+				#~ newest_packages_html.append("<ul>")
+				#~ for n, v, timestamp, action in g:
+					#~ newest_packages_html.append("<li>%(action)s</li>" % locals())
+					#~ items += 1
+				#~ newest_packages_html.append("</ul>")
+				newest_packages_html.append("<br />")
+				items += 1
+				if max_items <= items:
+					break
+		newest_packages_html = "\n".join(newest_packages_html)
 
 		# admin sidebar
 		admin_sidebar_html = ""
 
 	@classmethod
 	def packages(self):
-		packages = memcache.get("packages")
-		if packages is None:
+		packages, expired = Cache.get("packages")
+		if expired or packages is None:
 			packages = {}
 
 			from_repo = 1
 					package = Package(name=package_name, repo_url=repo_url)
 					packages[package.name] = package
 
-			assert memcache.set(key="packages", value=packages, time=FETCH_CACHE_AGE), package
+			assert Cache.set(key="packages", value=packages, duration=FETCH_CACHE_AGE), package
 
 		return packages
 

File code/templates.py

 	<ul>
 	<li><a href="/">Home</a> |&nbsp;</li>
 	<li><a href="/about">About SciKits</a> |&nbsp;</li>
-	<li><a href="/scikits">Get SciKits</a> |&nbsp;</li>
+	<li><a href="/scikits">Download a SciKit</a> |&nbsp;</li>
 	<li><a href="/contribute">Contribute</a></li>
 	</ul>
 </div>
 
 	%(admin_sidebar_html)s
 
+	%(newest_packages_html)s
+
 	<h3>Quick search</h3>
 	%(search_box_html)s
 

File code/tools.py

 ON_DEV_SERVER = os.environ.get("SERVER_SOFTWARE", "dev").lower().startswith("dev")
 REPO_PATH = "http://svn.scipy.org/svn/scikits/trunk"
 
+SECONDS_IN_MINUTE = 60
+SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60
+SECONDS_IN_DAY = SECONDS_IN_MINUTE * 24
+SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
+SECONDS_IN_MONTH = SECONDS_IN_DAY * 28
+
 # how often new data needs to be loaded
-FETCH_CACHE_AGE = 60 * 60 * 2
+FETCH_CACHE_AGE = SECONDS_IN_HOUR * 2
 
 import time
 
 class Cache(object):
 
 	"""
-	memcache that only notifies when object expires.
+	memcache that notifies if object expired but also still returns previous value
 	"""
 
 	@classmethod
 		timeout = (time.time()+duration) if duration is not None else None
 		return memcache.set(key=key, value=(value, timeout))
 
-#~ def get_url(url, force_fetch=False):
-	#~ result = memcache.get(url)
-	#~ if result is None or force_fetch:
-		#~ logger.debug("fetching %s" % url)
-		#~ result = urlfetch.fetch(url)
-		#~ assert memcache.set(key=url, value=result, time=FETCH_CACHE_AGE), url
-	#~ else:
-		#~ logger.debug("cache hit for %s" % url)
-	#~ return result
-
 def get_url(url, force_fetch=False):
 	response, expired = Cache.get(url)
 	if expired or force_fetch: