[cig-commits] r15977 - in doc/geodynamics.org/benchmarks/trunk: . utils utils/tmp
luis at geodynamics.org
luis at geodynamics.org
Mon Nov 16 14:49:07 PST 2009
Author: luis
Date: 2009-11-16 14:49:05 -0800 (Mon, 16 Nov 2009)
New Revision: 15977
Added:
doc/geodynamics.org/benchmarks/trunk/utils/tmp/
doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.py
doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.txt
Removed:
doc/geodynamics.org/benchmarks/trunk/upload.py
doc/geodynamics.org/benchmarks/trunk/upload.txt
Log:
Remove upload.py, as it has been replaced by publish.py
Deleted: doc/geodynamics.org/benchmarks/trunk/upload.py
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/upload.py 2009-11-16 22:48:59 UTC (rev 15976)
+++ doc/geodynamics.org/benchmarks/trunk/upload.py 2009-11-16 22:49:05 UTC (rev 15977)
@@ -1,217 +0,0 @@
-#!/usr/bin/env python2.6
-#
-# Reference docs:
-# http://www.zope.org/Documentation/Articles/WebDAV
-# http://plone.org/documentation/how-to/webdav
-# 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://docs.python.org/library/getpass.html
-# http://docs.python.org/library/pickle.html
-# http://docs.python.org/library/hashlib.html
-#
-
-import os
-import pexpect
-import pickle
-import hashlib
-
-
-# -----------------------------------------------------------------------------
-
-class DB(object):
- """
- Persistent dictionary which can reload itself on creation.
- """
-
- def __init__(self):
- self.db = dict()
- self.name = 'upload.pkl'
- if os.path.exists(self.name):
- pkl = open(self.name, 'rb')
- self.db = pickle.load(pkl)
- pkl.close()
- self.save()
-
- def save(self):
- pkl = open(self.name, 'wb')
- pickle.dump(self.db, pkl)
- pkl.close()
-
- def __contains__(self, item):
- return (item in self.db)
-
- def __getitem__(self, key):
- return self.db.get(key)
-
- def __setitem__(self, key, value):
- self.db[key] = value
-
-
-# actual database object where we'll be storing our file hashes
-db = DB()
-
-
-# -----------------------------------------------------------------------------
-
-def make_login_function():
- """
- Returns a function that prompts for user/password once, and
- remembers those in subsequent calls.
- """
-
- # store the user/password in a closure over our login() function
- env = dict(user=None, password=None)
-
- def login(p):
- """
- Acts on a pexpect instance, which will forward the
- user/password credentials to a child process.
- """
-
- if env['user'] is None:
- env['user'] = raw_input('Plone Username: ')
-
- if env['password'] is None:
- from getpass import getpass
- env['password'] = getpass('Plone Password: ')
-
- p.expect('Username for "Zope":*')
- p.sendline(env['user'])
-
- p.expect('Password:*')
- p.sendline(env['password'])
-
- return login
-
-
-# actual login function
-login = make_login_function()
-
-
-# -----------------------------------------------------------------------------
-
-def md5sum(filename):
- """
- Calculate the md5sum of the file contents.
- """
-
- m = hashlib.md5()
-
- with open(filename, 'rb') as fp:
- m.update(fp.read())
-
- return m.hexdigest()
-
-
-def has_changed(filename):
- """
- This function decides whether the html file in question
- has changed since the last upload.
- """
-
- current_md5 = md5sum(filename)
-
- if filename not in db:
- db[filename] = current_md5
- return True
-
- old_md5 = db[filename]
-
- # file has changed when the hashes are different
- return (current_md5 != old_md5)
-
-
-def geturl(filename):
- """
- Programmatically build target URL given the local .html filename.
- """
-
- # define the target-url pattern
- from common import benchroot
- target_url = benchroot + '/%s'
-
- # strip leading ./ if present
- if filename[0:2] == './':
- filename = filename[2:]
-
- # break up path into (parent collection, file base, file extension)
- from common import split_path
- coll, base, ext = split_path(filename)
- assert ext == '.html'
-
- # plone index pages are named 'index_html'
- if base == 'index':
- base = 'index_html'
-
- # finally, we pick the suffix (accounting for empty coll)
- suffix = base
- if coll:
- suffix = '%s/%s' % (coll, base)
-
- # once we have the suffix, apply it to the target_url pattern
- return target_url % suffix
-
-
-# -----------------------------------------------------------------------------
-
-def upload(filename):
- """
- Use nd to upload (PUT) the given .html file.
- """
-
- # calculate the target URL for our .html file
- target_url = geturl(filename)
-
- # spawn a pexpect child process that will upload the desired file
- p = pexpect.spawn("nd -p '%s' '%s'" % (filename, target_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)
-
- # give some feedback while the file uploads
- print "Uploaded %s" % target_url
-
- # now that we've uploaded the file, we can update our database
- # with the current hash (replacing the old hash)
- db[filename] = md5sum(filename)
-
-
-def upload_all_html_files():
- """
- Upload all modified *.html files.
- """
-
- from common import groups, locate
-
- print "Scanning for files to upload..."
- for group in groups:
- for filename in locate('*.html', root=group):
- if has_changed(filename):
- upload(filename)
-
-
-def upload_from_list():
- """
- Upload files in 'upload.txt'.
- """
-
- from common import readlines
-
- print "Scanning for files to upload..."
- for filename in readlines('upload.txt'):
- if has_changed(filename):
- upload(filename)
-
-
-# -----------------------------------------------------------------------------
-
-def main():
- upload_from_list()
- db.save()
-
-
-if __name__ == '__main__':
- main()
Deleted: doc/geodynamics.org/benchmarks/trunk/upload.txt
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/upload.txt 2009-11-16 22:48:59 UTC (rev 15976)
+++ doc/geodynamics.org/benchmarks/trunk/upload.txt 2009-11-16 22:49:05 UTC (rev 15977)
@@ -1,36 +0,0 @@
-./index.html
-./geodyn/index.html
-./long/index.html
-./long/falling-sphere.html
-./long/circular-inclusion.html
-./long/relaxation-topography.html
-./long/divergence.html
-./long/drucker-prager.html
-./long/geomod2004.html
-./long/geomod2008.html
-./magma/index.html
-./magma/mckenzie-equations.html
-./magma/running-stgmadds.html
-./magma/milestone1.html
-./magma/milestone2.html
-./magma/milestone3.html
-./magma/milestone4.html
-./magma/milestone5.html
-./mc/index.html
-./mc/2d-cartesian/index.html
-./mc/2d-cartesian/suite1.html
-./mc/2d-cartesian/suite2.html
-./mc/2d-cartesian/suite3.html
-./mc/2d-cartesian/suite4.html
-./mc/3d-spherical/index.html
-./seismo/index.html
-./short/index.html
-./short/overview.html
-./short/strikeslip/index.html
-./short/strikeslip/description-ss.html
-./short/strikeslip/plots/index.html
-./short/rs-nog/description-rs-nog.html
-./short/rs-nog/plots/index.html
-./short/rs/description-rs.html
-./short/landers/description-landers.html
-./short/savage-prescott/index.html
Copied: doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.py (from rev 15976, doc/geodynamics.org/benchmarks/trunk/upload.py)
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.py (rev 0)
+++ doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.py 2009-11-16 22:49:05 UTC (rev 15977)
@@ -0,0 +1,217 @@
+#!/usr/bin/env python2.6
+#
+# Reference docs:
+# http://www.zope.org/Documentation/Articles/WebDAV
+# http://plone.org/documentation/how-to/webdav
+# 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://docs.python.org/library/getpass.html
+# http://docs.python.org/library/pickle.html
+# http://docs.python.org/library/hashlib.html
+#
+
+import os
+import pexpect
+import pickle
+import hashlib
+
+
+# -----------------------------------------------------------------------------
+
+class DB(object):
+ """
+ Persistent dictionary which can reload itself on creation.
+ """
+
+ def __init__(self):
+ self.db = dict()
+ self.name = 'upload.pkl'
+ if os.path.exists(self.name):
+ pkl = open(self.name, 'rb')
+ self.db = pickle.load(pkl)
+ pkl.close()
+ self.save()
+
+ def save(self):
+ pkl = open(self.name, 'wb')
+ pickle.dump(self.db, pkl)
+ pkl.close()
+
+ def __contains__(self, item):
+ return (item in self.db)
+
+ def __getitem__(self, key):
+ return self.db.get(key)
+
+ def __setitem__(self, key, value):
+ self.db[key] = value
+
+
+# actual database object where we'll be storing our file hashes
+db = DB()
+
+
+# -----------------------------------------------------------------------------
+
+def make_login_function():
+ """
+ Returns a function that prompts for user/password once, and
+ remembers those in subsequent calls.
+ """
+
+ # store the user/password in a closure over our login() function
+ env = dict(user=None, password=None)
+
+ def login(p):
+ """
+ Acts on a pexpect instance, which will forward the
+ user/password credentials to a child process.
+ """
+
+ if env['user'] is None:
+ env['user'] = raw_input('Plone Username: ')
+
+ if env['password'] is None:
+ from getpass import getpass
+ env['password'] = getpass('Plone Password: ')
+
+ p.expect('Username for "Zope":*')
+ p.sendline(env['user'])
+
+ p.expect('Password:*')
+ p.sendline(env['password'])
+
+ return login
+
+
+# actual login function
+login = make_login_function()
+
+
+# -----------------------------------------------------------------------------
+
+def md5sum(filename):
+ """
+ Calculate the md5sum of the file contents.
+ """
+
+ m = hashlib.md5()
+
+ with open(filename, 'rb') as fp:
+ m.update(fp.read())
+
+ return m.hexdigest()
+
+
+def has_changed(filename):
+ """
+ This function decides whether the html file in question
+ has changed since the last upload.
+ """
+
+ current_md5 = md5sum(filename)
+
+ if filename not in db:
+ db[filename] = current_md5
+ return True
+
+ old_md5 = db[filename]
+
+ # file has changed when the hashes are different
+ return (current_md5 != old_md5)
+
+
+def geturl(filename):
+ """
+ Programmatically build target URL given the local .html filename.
+ """
+
+ # define the target-url pattern
+ from common import benchroot
+ target_url = benchroot + '/%s'
+
+ # strip leading ./ if present
+ if filename[0:2] == './':
+ filename = filename[2:]
+
+ # break up path into (parent collection, file base, file extension)
+ from common import split_path
+ coll, base, ext = split_path(filename)
+ assert ext == '.html'
+
+ # plone index pages are named 'index_html'
+ if base == 'index':
+ base = 'index_html'
+
+ # finally, we pick the suffix (accounting for empty coll)
+ suffix = base
+ if coll:
+ suffix = '%s/%s' % (coll, base)
+
+ # once we have the suffix, apply it to the target_url pattern
+ return target_url % suffix
+
+
+# -----------------------------------------------------------------------------
+
+def upload(filename):
+ """
+ Use nd to upload (PUT) the given .html file.
+ """
+
+ # calculate the target URL for our .html file
+ target_url = geturl(filename)
+
+ # spawn a pexpect child process that will upload the desired file
+ p = pexpect.spawn("nd -p '%s' '%s'" % (filename, target_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)
+
+ # give some feedback while the file uploads
+ print "Uploaded %s" % target_url
+
+ # now that we've uploaded the file, we can update our database
+ # with the current hash (replacing the old hash)
+ db[filename] = md5sum(filename)
+
+
+def upload_all_html_files():
+ """
+ Upload all modified *.html files.
+ """
+
+ from common import groups, locate
+
+ print "Scanning for files to upload..."
+ for group in groups:
+ for filename in locate('*.html', root=group):
+ if has_changed(filename):
+ upload(filename)
+
+
+def upload_from_list():
+ """
+ Upload files in 'upload.txt'.
+ """
+
+ from common import readlines
+
+ print "Scanning for files to upload..."
+ for filename in readlines('upload.txt'):
+ if has_changed(filename):
+ upload(filename)
+
+
+# -----------------------------------------------------------------------------
+
+def main():
+ upload_from_list()
+ db.save()
+
+
+if __name__ == '__main__':
+ main()
Copied: doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.txt (from rev 15976, doc/geodynamics.org/benchmarks/trunk/upload.txt)
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.txt (rev 0)
+++ doc/geodynamics.org/benchmarks/trunk/utils/tmp/upload.txt 2009-11-16 22:49:05 UTC (rev 15977)
@@ -0,0 +1,36 @@
+./index.html
+./geodyn/index.html
+./long/index.html
+./long/falling-sphere.html
+./long/circular-inclusion.html
+./long/relaxation-topography.html
+./long/divergence.html
+./long/drucker-prager.html
+./long/geomod2004.html
+./long/geomod2008.html
+./magma/index.html
+./magma/mckenzie-equations.html
+./magma/running-stgmadds.html
+./magma/milestone1.html
+./magma/milestone2.html
+./magma/milestone3.html
+./magma/milestone4.html
+./magma/milestone5.html
+./mc/index.html
+./mc/2d-cartesian/index.html
+./mc/2d-cartesian/suite1.html
+./mc/2d-cartesian/suite2.html
+./mc/2d-cartesian/suite3.html
+./mc/2d-cartesian/suite4.html
+./mc/3d-spherical/index.html
+./seismo/index.html
+./short/index.html
+./short/overview.html
+./short/strikeslip/index.html
+./short/strikeslip/description-ss.html
+./short/strikeslip/plots/index.html
+./short/rs-nog/description-rs-nog.html
+./short/rs-nog/plots/index.html
+./short/rs/description-rs.html
+./short/landers/description-landers.html
+./short/savage-prescott/index.html
More information about the CIG-COMMITS
mailing list