Commits

Martin von Löwis committed b557aa1

Add support for master-initiated sync operations.

Comments (0)

Files changed (4)

     ServerName X.pypi.python.org
     CustomLog /var/log/apache2/pypi.log combined
     DocumentRoot /var/pypi/web
+    ScriptAlias /sync /path/pep381sync.cgi
   </VirtualHost>
 
 To propagate the download statistics back to the central server,
 - Print nicer message for Ctrl-C (Jacob Kaplan-Moss)
 - Add --help option to pep381run (Horst Gutmann)
 - Drop mvindex again
+- Add support for master-initiated sync operations
 
 1.3 (2010-07-06):
 

pep381client/__init__.py

         res = cPickle.load(open(os.path.join(homedir, "status"), "rb"))
         res.storage = storage or sqlite.SqliteStorage(os.path.join(homedir, "files"))
         res.defaults()
+        res.homedir = homedir # override pickled value in case it got relocated
         return res
 
     #################### Synchronization logic ##############################

scripts/pep381run

 except ImportError:
     # See whether we are run out of a source tree
     module_path = os.path.join(os.path.dirname(sys.argv[0]), 
-                               '..', 'pep381client')
+                               '..')
     if os.path.exists(module_path):
-        sys.path.extend(module_path)
+        sys.path.append(module_path)
     import pep381client
 
 opts = optparse.OptionParser(usage="Usage: pep381run [OPTIONS] <targetdir>")

scripts/pep381sync.cgi

+#!/usr/bin/env python
+# replace this with actual mirror location, 
+# or set PYPITARGET environment variable
+targetdir = '/pypi'
+
+import os, sys, signal
+
+dirname = os.path.dirname(sys.argv[0])
+
+if "PYPITARGET" in os.environ:
+    targetdir = os.environ["PYPITARGET"]
+
+if not os.path.exists(targetdir):
+    print "Status: 412 Precondition failed"
+    print "Content-type: text/plain"
+    print
+    print "PyPI mirror targetdir not configured"
+    raise SystemExit
+
+# detach from webserver
+if os.fork() == 0:
+    # child process: run mirroring quietly
+    # close fds so that the web server won't wait for further input
+    os.close(0)
+    os.close(1)
+    os.close(2)
+    os.execl(os.path.join(dirname, "pep381run"),
+             os.path.join(dirname, "pep381run"),
+             "-q", targetdir)
+else:
+    # parent process; print status and exit
+    print "Content-Type: text/plain"
+    print
+    print "Mirroring started"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.