[Pypi-checkins] r835 - trunk/appengine
martin.von.loewis
python-checkins at python.org
Sat Jul 31 10:44:08 CEST 2010
Author: martin.von.loewis
Date: Sat Jul 31 10:44:07 2010
New Revision: 835
Modified:
trunk/appengine/fetch.py
trunk/appengine/handlers.py
trunk/appengine/mirror.py
Log:
Fix handlers and last-modified.
Modified: trunk/appengine/fetch.py
==============================================================================
--- trunk/appengine/fetch.py (original)
+++ trunk/appengine/fetch.py Sat Jul 31 10:44:07 2010
@@ -1,11 +1,11 @@
import httplib, xmlrpclib, time, pickle, urllib2, binascii, os, logging, re
try:
- from xml.etree.cElementTree import *
+ from xml.etree.cElementTree import *
except ImportError:
- try:
- from xml.etree.ElementTree import *
- except ImportError:
- from elementtree.ElementTree import *
+ try:
+ from xml.etree.ElementTree import *
+ except ImportError:
+ from elementtree.ElementTree import *
from google.appengine.api.labs import taskqueue
from google.appengine.api.urlfetch import DownloadError
import model
@@ -114,17 +114,19 @@
f.contents.delete()
f.etag = r.msg['etag']
f.put()
+ elif r.status == 404:
+ logging.error('File %s not found' % path)
else:
raise ValueError, "Bad HTTP status (%s %s)" % (path, r.status)
def packages_listed(m, todo, t):
# reappend after all files
- todo.append('last_modified', t)
+ todo.append(('last_modified', t))
def last_modified(m, todo, t):
- m.last_modified = t
-
+ m.last_modified = time.strftime("%Y%m%dT%H:%M:%S", time.gmtime(t))
+ m.put()
actions = {'package':package,
'file':copy_file,
@@ -149,13 +151,15 @@
if todo:
# name the task, so that no two of them will be added
try:
+ # Allow re-running a task once a day
+ day = int(time.time())//3600/24-14820
n, p = todo[0]
if n == 'file':
p = p[1]
name = '%s-%s' % (n, p)
- name = re.sub('[^a-zA-Z0-9-]', '-', name)
+ name = re.sub('[^a-zA-Z0-9-]', '-', name)+'-'+str(day)
taskqueue.add(name=name, url='/step')
except taskqueue.InvalidTaskError, e:
# likely, task already existed, or was tombstoned
- logging.error("Queing task failed: %s" % str(e))
+ logging.error("Queing task %s failed: %s" % (name,e.__class__.__name__))
return "OK (%s %s)" % (action, param)
Modified: trunk/appengine/handlers.py
==============================================================================
--- trunk/appengine/handlers.py (original)
+++ trunk/appengine/handlers.py Sat Jul 31 10:44:07 2010
@@ -19,6 +19,12 @@
p = model.Project.get_by_key_name(path)
self.response.out.write(p.simple)
+class LastModified(webapp.RequestHandler):
+ def get(self):
+ self.response.headers['content-type'] = 'text/plain'
+ p = model.MirrorState.all().fetch(1)[0]
+ self.response.out.write(p.last_modified)
+
class Upload(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
path = self.request.get('path')
@@ -57,14 +63,23 @@
'path':path, 'dirs':dirs, 'files':files }))
class Serversig(webapp.RequestHandler):
- def get(self):
- #serversig
- pass
+ def get(self, path):
+ path = path.strip('/')
+ if not path:
+ self.response.headers['content-type'] = 'text/plain'
+ # no content
+ else:
+ p = model.Project.get_by_key_name(path)
+ if p and p.sig:
+ self.response.headers['content-type'] = 'application/octet-stream'
+ self.response.out.write(p.sig)
+ else:
+ self.response.error(404)
class Stats(webapp.RequestHandler):
- def get(self):
- #localstats/days
- pass
+ def get(self, path):
+ self.response.headers['content-type'] = 'text/plain'
+ self.response.write('not implemented yet')
class Step(webapp.RequestHandler):
def get(self):
Modified: trunk/appengine/mirror.py
==============================================================================
--- trunk/appengine/mirror.py (original)
+++ trunk/appengine/mirror.py Sat Jul 31 10:44:07 2010
@@ -4,6 +4,7 @@
application = webapp.WSGIApplication(
[('/', Index),
+ ('/last-modified', LastModified),
('/simple/(.*)', Simple),
('/packages/(.*)', File),
('/serversig/(.*)', Serversig),
More information about the Pypi-checkins
mailing list