[Pypi-checkins] r838 - in trunk/pypi: . tools

martin.von.loewis python-checkins at python.org
Sun Aug 1 23:50:26 CEST 2010


Author: martin.von.loewis
Date: Sun Aug  1 23:50:26 2010
New Revision: 838

Added:
   trunk/pypi/gae.py   (contents, props changed)
Modified:
   trunk/pypi/tools/touch_all_files.py
   trunk/pypi/webui.py
Log:
Add GAE support.


Added: trunk/pypi/gae.py
==============================================================================
--- (empty file)
+++ trunk/pypi/gae.py	Sun Aug  1 23:50:26 2010
@@ -0,0 +1,53 @@
+# Helper for the mirror on GAE
+# GAE GETs an action gae_file, giving GAE host and a secret
+# PyPI GETs /mkupload/secret, learning path and upload session
+# PyPI POSTs to upload session
+import urllib2, httplib, threading, os, binascii, urlparse
+
+POST="""\
+--%(boundary)s
+Content-Disposition: form-data; name=secret
+
+%(secret)s
+--%(boundary)s
+Content-Disposition: form-data; name=path
+
+%(path)s
+--%(boundary)s
+Content-Disposition: form-data; name=file; filename=data.bin
+
+%(data)s
+"""
+POST = "\r\n".join(POST.splitlines())
+
+# XXX Not sure how to report errors
+def doit(host, secret, srcdir):
+    x = urllib2.urlopen('http://%s/mkupload/%s' % (host, secret))
+    if x.code != 200:
+        #print "mkupload failed (%s)" % r.code
+        return
+    path,url = x.read().splitlines()
+    host, session = urlparse.urlsplit(url)[1:3]
+    try:
+        data = open(srcdir+"/"+path).read()
+    except IOError, e:
+        #print "Read of %s failed:%s"%(path,str(e))
+        return
+    boundary = ""
+    while boundary in data:
+        boundary = binascii.hexlify(os.urandom(10))
+    body = POST % locals()
+    c = httplib.HTTPConnection(host)
+    c.request('POST', session,
+              headers = {'Content-type':'multipart/form-data; boundary='+boundary,
+                         'Content-length':str(len(body))},
+              body=body)
+    resp = c.getresponse()
+    data = resp.read()
+    # result code should be redirect
+    c.close()
+
+def transfer(host, secret, srcdir):
+    t = threading.Thread(target=doit, args=(host, secret, srcdir))
+    t.start()
+

Modified: trunk/pypi/tools/touch_all_files.py
==============================================================================
--- trunk/pypi/tools/touch_all_files.py	(original)
+++ trunk/pypi/tools/touch_all_files.py	Sun Aug  1 23:50:26 2010
@@ -33,4 +33,4 @@
             os.makedirs(dir)
         if not os.path.exists(path):
             print "Creating file %s" % path
-            open(path, "a")
+            open(path, "a").write('Contents of '+path+'\n')

Modified: trunk/pypi/webui.py
==============================================================================
--- trunk/pypi/webui.py	(original)
+++ trunk/pypi/webui.py	Sun Aug  1 23:50:26 2010
@@ -28,7 +28,7 @@
 
 # local imports
 import store, config, versionpredicate, verify_filetype, rpc
-import MailingLogger, openid2rp
+import MailingLogger, openid2rp, gae
 from mini_pkg_resources import safe_name
 
 esc = cgi.escape
@@ -555,7 +555,7 @@
         password_reset role role_form list_classifiers login logout files
         file_upload show_md5 doc_upload claim openid openid_return dropid
         rate comment addcomment delcomment clear_auth addkey delkey lasthour
-        json'''.split():
+        json gae_file'''.split():
             getattr(self, action)()
         else:
             #raise NotFound, 'Unknown action %s' % action
@@ -2424,6 +2424,15 @@
         raise Redirect("http://packages.python.org/%s/" % name)
 
     #
+    # Reverse download for Google AppEngine
+    #
+    def gae_file(self):
+        host = self.form['host']
+        secret = self.form['secret']
+        gae.transfer(host, secret, self.config.database_files_dir)
+        self.handler.send_response(204, 'Initiated')
+
+    #
     # classifiers listing
     #
     def list_classifiers(self):


More information about the Pypi-checkins mailing list