[cig-commits] r15737 - in doc/geodynamics.org/benchmarks/trunk: . long
luis at geodynamics.org
luis at geodynamics.org
Thu Oct 1 17:39:08 PDT 2009
Author: luis
Date: 2009-10-01 17:39:07 -0700 (Thu, 01 Oct 2009)
New Revision: 15737
Removed:
doc/geodynamics.org/benchmarks/trunk/upload.sh
Modified:
doc/geodynamics.org/benchmarks/trunk/.gitignore
doc/geodynamics.org/benchmarks/trunk/Makefile
doc/geodynamics.org/benchmarks/trunk/long/index.html
doc/geodynamics.org/benchmarks/trunk/upload.py
Log:
Replaced upload.sh with upload.py
Changed upload.py so that it prompts your plone user/password
instead of having it hardcoded in zopelogin.py. The login
function will only prompt you once (per run), and will remember
your authentication credentials for all other files.
Modified: doc/geodynamics.org/benchmarks/trunk/.gitignore
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/.gitignore 2009-10-01 21:37:21 UTC (rev 15736)
+++ doc/geodynamics.org/benchmarks/trunk/.gitignore 2009-10-02 00:39:07 UTC (rev 15737)
@@ -1,5 +1,4 @@
.*.swp
-/zopelogin.py
# for now, ignore these
/utils
Modified: doc/geodynamics.org/benchmarks/trunk/Makefile
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/Makefile 2009-10-01 21:37:21 UTC (rev 15736)
+++ doc/geodynamics.org/benchmarks/trunk/Makefile 2009-10-02 00:39:07 UTC (rev 15737)
@@ -5,7 +5,7 @@
./generate.sh
up:
- ./upload.sh
+ ./upload.py
clean:
./clean.sh
Modified: doc/geodynamics.org/benchmarks/trunk/long/index.html
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/long/index.html 2009-10-01 21:37:21 UTC (rev 15736)
+++ doc/geodynamics.org/benchmarks/trunk/long/index.html 2009-10-02 00:39:07 UTC (rev 15737)
@@ -305,7 +305,7 @@
<h1>Links</h1>
<ul class="simple">
<li><a class="reference external" href="http://geodynamics.org/cig/software/packages/long/gale/tutorials">Four Gale Tutorials</a></li>
-<li><a class="reference external" href="http://geodynamics.org/cig/workinggroups/long/workarea">Original Work Area (currently empty)</a></li>
+<li><a class="reference external" href="http://geodynamics.org/cig/workinggroups/long/workarea">Original Work Area</a></li>
</ul>
</div>
</div>
Modified: doc/geodynamics.org/benchmarks/trunk/upload.py
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/upload.py 2009-10-01 21:37:21 UTC (rev 15736)
+++ doc/geodynamics.org/benchmarks/trunk/upload.py 2009-10-02 00:39:07 UTC (rev 15737)
@@ -3,30 +3,131 @@
# http://pexpect.sourceforge.net/pexpect.html
# http://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/
# http://www.palovick.com/code/python/python-ssh-client.php
+# http://www.brunningonline.net/simon/blog/archives/002022.html
+# http://docs.python.org/library/os.path.html
+# http://docs.python.org/library/getpass.html
#
+
import pexpect
-from zopelogin import user, password
+import os
+def make_login_function():
+ """
+ Returns a function that prompts for user/password once, and
+ remembers those in subsequent calls.
+ """
-def login(p):
- p.expect('Username for "Zope":*')
- p.sendline(user)
- p.expect('Password:*')
- p.sendline(password)
+ env = dict(user=None, password=None)
-def main():
- import sys
+ def login(p):
+ """
+ Act on a pexpect instance, which will forward the
+ user/password credentials to a child process.
+ """
- if len(sys.argv) != 3:
- print "Usage: %s <file> <url>" % sys.argv[0]
- sys.exit(1)
+ if env['user'] is None:
+ env['user'] = raw_input('Plone Username: ')
- file = sys.argv[1]
- url = sys.argv[2]
+ if env['password'] is None:
+ from getpass import getpass
+ env['password'] = getpass('Plone Password: ')
- print("Uploading to " + url)
- p = pexpect.spawn("nd -p '%s' '%s'" % (file, url))
+ p.expect('Username for "Zope":*')
+ p.sendline(env['user'])
+
+ p.expect('Password:*')
+ p.sendline(env['password'])
+
+ return login
+
+
+login = make_login_function()
+
+
+def upload(filename, url):
+ """
+ Use nd to upload (PUT) given file into a target url
+ """
+
+ # spawn a pexpect child process
+ p = pexpect.spawn("nd -p '%s' '%s'" % (filename, url))
+
+ # nd will prompt for a password, so we forward the pexpect object
+ # to our special login function, which will remember your user/password
+ # after you've entered it once.
login(p)
+ # show something as feedback
+ print "Uploaded %s" % url
+
+
+def locate(pattern, root=os.getcwd()):
+ """
+ Return filenames that match given pattern
+ """
+ from fnmatch import fnmatch
+ for (path, dirs, files) in os.walk(root):
+ matches = [os.path.join(path, filename)
+ for filename in files if fnmatch(filename, pattern)]
+ for filename in matches:
+ yield filename
+
+
+def geturl(filename):
+ """
+ Programmatically build a URL given a filename
+ """
+
+ # target-url pattern
+ url = 'http://geodynamics.org/cig/software/benchmarks/%s/%s'
+
+ # strip leading ./ if present
+ if filename[0:2] == './':
+ filename = filename[2:]
+
+ # strip out the file extension
+ coll = os.path.dirname(filename)
+ (base, ext) = os.path.splitext(os.path.basename(filename))
+
+ # while we're ignoring the file extension, we only want to operate
+ # on html files (fail otherwise)
+ assert ext == '.html'
+
+ # plone index pages are named 'index_html'
+ if base == 'index':
+ base = 'index_html'
+
+ # we're done. fill in the url pattern
+ return url % (coll, base)
+
+
+def upload_all_html_files():
+ """
+ Upload all *.html files under the group subdirectories.
+ """
+ groups = ['cs', 'geodyn', 'long', 'magma', 'mc', 'seismo', 'short']
+ for group in groups:
+ for filename in locate('*.html', root=group):
+ upload(filename, geturl(filename))
+
+
+def upload_from_list():
+ """
+ Upload all files in 'upload.txt'
+ """
+ def upload_list():
+ fp = open('upload.txt', 'r')
+ for line in fp.readlines():
+ yield line.strip()
+ fp.close()
+
+ for filename in upload_list():
+ upload(filename, geturl(filename))
+
+
+def main():
+ upload_from_list()
+
+
if __name__ == '__main__':
main()
Deleted: doc/geodynamics.org/benchmarks/trunk/upload.sh
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/upload.sh 2009-10-01 21:37:21 UTC (rev 15736)
+++ doc/geodynamics.org/benchmarks/trunk/upload.sh 2009-10-02 00:39:07 UTC (rev 15737)
@@ -1,32 +0,0 @@
-#!/bin/bash
-#
-# This script uploads the resulting html pages into plone.
-#
-
-source ./common.sh
-
-for html in $(cat ./upload.txt); do
-
- # strip out leading ./ from the relative filename
- path=$(echo $html | sed sq^\./qqg)
-
- # which collection to
- coll=$(dirname $path)
-
- # figure out the base name
- base=$(basename $path .html)
- if [ "$base" == "index" ]; then
- base="index_html"
- fi
-
- # figure out the document title
- rst="./${coll}/${base}.rst"
-
- # build the target url
- url="${benchroot}/${coll}/${base}"
-
- # upload file to target url
- ./upload.py ${html} ${url}
-
-done
-
More information about the CIG-COMMITS
mailing list