[Pypi-checkins] r919 - trunk/pypi

richard python-checkins at python.org
Wed Apr 20 02:09:37 CEST 2011


Author: richard
Date: Wed Apr 20 02:09:37 2011
New Revision: 919

Modified:
   trunk/pypi/config.ini.template
   trunk/pypi/store.py
   trunk/pypi/webui.py
Log:
prettify JSON output; try inline to maybe fix FF4 behaviour (thanks anatoly techtonik)

Modified: trunk/pypi/config.ini.template
==============================================================================
--- trunk/pypi/config.ini.template	(original)
+++ trunk/pypi/config.ini.template	Wed Apr 20 02:09:37 2011
@@ -15,6 +15,7 @@
 simple_script = /simple
 files_url = http://localhost/pypi_files
 rss_file = /tmp/pypi_rss.xml
+packages_rss_file = /tmp/pypi_packages_rss.xml
 debug_mode = yes
 cheesecake_password = secret
 privkey = privkey

Modified: trunk/pypi/store.py
==============================================================================
--- trunk/pypi/store.py	(original)
+++ trunk/pypi/store.py	Wed Apr 20 02:09:37 2011
@@ -844,6 +844,40 @@
     def changelog_last_hour(self):
         return self.changelog(int(time.time())-3600)
 
+    _Latest_Packages = FastResultRow('name version submitted_date! summary')
+    def latest_packages(self, num=40):
+        '''Fetch "number" latest packages registered, youngest to oldest.
+        '''
+        cursor = self.get_cursor()
+        # After the limited query below, we still have to do
+        # filtering. Assume that doubling the number of records
+        # we look for will still allow for sufficient room for
+        # filtering out unneeded records. If this was wrong,
+        # try again without limit.
+        limit = ' limit %s' % (2*num)
+        # This query is designed to run from the journals_latest_releases
+        # index, doing a reverse index scan, then lookups in the releases
+        # table to find the description and whether the package is hidden.
+        # 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'''
+        #print ' '.join((statement % limit).split())
+        safe_execute(cursor, statement % limit)
+        result = Result(None, self.get_unique(cursor.fetchall())[:num],
+                self._Latest_Releases)
+        if len(result) == num:
+            return result
+        # try again without limit
+        safe_execute(cursor, statement % '')
+        return Result(None, self.get_unique(cursor.fetchall())[:num],
+                self._Latest_Releases)
+
     _Latest_Releases = FastResultRow('name version submitted_date! summary')
     def latest_releases(self, num=40):
         ''' Fetch "number" latest releases, youngest to oldest.

Modified: trunk/pypi/webui.py
==============================================================================
--- trunk/pypi/webui.py	(original)
+++ trunk/pypi/webui.py	Wed Apr 20 02:09:37 2011
@@ -1097,13 +1097,14 @@
             url['upload_time'] = url['upload_time'].strftime('%Y-%m-%dT%H:%M:%S')
         self.handler.send_response(200, "OK")
         self.handler.set_content_type('application/json; charset="UTF-8"')
-        filename = '%s-%s.json'%(name.encode('ascii', 'replace'),
-            version.encode('ascii', 'replace'))
-#        self.handler.send_header('Content-Disposition',
-#            'attachment; filename=%s'%filename)
+        #filename = '%s-%s.json'%(name.encode('ascii', 'replace'),
+        #    version.encode('ascii', 'replace'))
+        #self.handler.send_header('Content-Disposition', 
+        #    'attachment; filename=%s'%filename)
+        self.handler.send_header('Content-Disposition', 'inline')
         self.handler.end_headers()
         # write the JSONP extra crap if necessary
-        s = json.dumps(d)
+        s = json.dumps(d, indent=4)
         callback = self.form.get('callback')
         if callback:
             s = '%s(%s)' % (callback, s)


More information about the Pypi-checkins mailing list