[Pypi-checkins] r949 - in trunk/pypi: . templates
richard
python-checkins at python.org
Mon Aug 22 08:51:59 CEST 2011
Author: richard
Date: Mon Aug 22 08:51:58 2011
New Revision: 949
Added:
trunk/pypi/templates/packages-rss.xml
Modified:
trunk/pypi/config.py
trunk/pypi/store.py
trunk/pypi/webui.py
Log:
add newest packages RSS
Modified: trunk/pypi/config.py
==============================================================================
--- trunk/pypi/config.py (original)
+++ trunk/pypi/config.py Mon Aug 22 08:51:58 2011
@@ -30,6 +30,7 @@
self.simple_script = c.get('webui', 'simple_script')
self.files_url = c.get('webui', 'files_url')
self.rss_file = c.get('webui', 'rss_file')
+ self.packages_rss_file = c.get('webui', 'packages_rss_file')
self.debug_mode = c.get('webui', 'debug_mode')
self.cheesecake_password = c.get('webui', 'cheesecake_password')
self.key_dir = c.get('webui', 'key_dir')
Modified: trunk/pypi/store.py
==============================================================================
--- trunk/pypi/store.py (original)
+++ trunk/pypi/store.py Mon Aug 22 08:51:58 2011
@@ -884,12 +884,13 @@
# Postgres will only do that if the number of expected results
# is "small".
statement = '''
- select j.name, j.version, j.submitted_date, r.summary
- from (select name,version,submitted_date from journals
- where version is not null and action='create'
- order by submitted_date desc %s) j, releases r
- where j.name=r.name and j.version=r.version
- and not r._pypi_hidden order by j.submitted_date desc'''
+ select j.name, r.version, j.submitted_date, r.summary
+ from (select name,version,submitted_date from journals
+ where action='create' order by submitted_date desc %s) j,
+ releases r
+ where j.name=r.name and r.version is not NULL
+ and not r._pypi_hidden
+ order by j.submitted_date desc'''
#print ' '.join((statement % limit).split())
safe_execute(cursor, statement % limit)
result = Result(None, self.get_unique(cursor.fetchall())[:num],
Added: trunk/pypi/templates/packages-rss.xml
==============================================================================
--- (empty file)
+++ trunk/pypi/templates/packages-rss.xml Mon Aug 22 08:51:58 2011
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
+<rss version="0.91"
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ xmlns:metal="http://xml.zope.org/namespaces/metal">
+ <channel>
+ <title>PyPI Newest Packages</title>
+ <link tal:content="string:${app/url_machine}${app/url_path}" />
+ <description>Newest packages registered at the Python Package Index</description>
+ <language>en</language>
+
+ <item tal:repeat="release app/store/latest_packages">
+ <title tal:content="string:${release/name} ${release/version}" />
+ <link tal:content="python:'http://pypi.python.org%s'%app.packageURL(
+ release['name'], release['version'])" />
+ <description tal:content="release/summary" />
+ <pubDate tal:content="python:release['submitted_date'].strftime('%d %b %Y %H:%M:%S GMT')" />
+ </item>
+ </channel>
+</rss>
Modified: trunk/pypi/webui.py
==============================================================================
--- trunk/pypi/webui.py (original)
+++ trunk/pypi/webui.py Mon Aug 22 08:51:58 2011
@@ -389,7 +389,8 @@
('submit_form', 'Package submission'),
('list_classifiers', 'List trove classifiers'),
('index', 'List packages'),
- ('rss', 'RSS (last 40 updates)'),
+ ('rss', 'RSS (latest 40 updates)'),
+ ('package_rss', 'RSS (newest 40 packages)'),
('role_form', 'Admin'),
)
def navlinks_html(self):
@@ -520,7 +521,8 @@
display register_form user_form forgotten_password_form user
password_reset role role_form list_classifiers login logout files
file_upload show_md5 doc_upload claim openid openid_return dropid
- clear_auth addkey delkey lasthour json gae_file about delete_user'''.split():
+ clear_auth addkey delkey lasthour json gae_file about delete_user
+ rss_regen'''.split():
getattr(self, action)()
else:
#raise NotFound, 'Unknown action %s' % action
@@ -677,7 +679,7 @@
"""
# determine whether the rss file is up to date
if not os.path.exists(self.config.rss_file):
- self.rss_regen(self.config.rss_file)
+ self.rss_regen()
# TODO: throw in a last-modified header too?
self.handler.send_response(200, 'OK')
@@ -685,22 +687,49 @@
self.handler.end_headers()
self.wfile.write(open(self.config.rss_file).read())
- def rss_regen(self, rss_file=None):
- if rss_file is None:
- rss_file = self.config.rss_file
+ def packages_rss(self):
+ """Dump the last N days' updates as an RSS feed.
+ """
+ # determine whether the rss file is up to date
+ if not os.path.exists(self.config.packages_rss_file):
+ self.rss_regen()
+
+ # TODO: throw in a last-modified header too?
+ self.handler.send_response(200, 'OK')
+ self.handler.set_content_type('text/xml; charset=utf-8')
+ self.handler.end_headers()
+ self.wfile.write(open(self.config.packages_rss_file).read())
+
+ def rss_regen(self):
context = {}
context['app'] = self
+ # generate the releases RSS
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
template = PyPiPageTemplate('rss.xml', template_dir)
content = template(**context)
+ f = open(self.config.rss_file, 'w')
+ try:
+ f.write(content.encode('utf-8'))
+ finally:
+ f.close()
- f = open(rss_file, 'w')
+ # generate the packages RSS
+ template_dir = os.path.join(os.path.dirname(__file__), 'templates')
+ template = PyPiPageTemplate('packages-rss.xml', template_dir)
+ content = template(**context)
+ f = open(self.config.packages_rss_file, 'w')
try:
f.write(content.encode('utf-8'))
finally:
f.close()
+ # just for making this all OK
+ self.handler.send_response(200, 'OK')
+ self.handler.set_content_type('text/plain')
+ self.handler.end_headers()
+ self.wfile.write('OK')
+
def lasthour(self):
self.write_template('rss1hour.xml', **{'content-type':'text/xml; charset=utf-8'})
More information about the Pypi-checkins
mailing list