[cig-commits] r15841 - doc/geodynamics.org/benchmarks/trunk
luis at geodynamics.org
luis at geodynamics.org
Mon Oct 19 12:34:01 PDT 2009
Author: luis
Date: 2009-10-19 12:34:00 -0700 (Mon, 19 Oct 2009)
New Revision: 15841
Modified:
doc/geodynamics.org/benchmarks/trunk/common.py
Log:
Updated common.py
Modified: doc/geodynamics.org/benchmarks/trunk/common.py
===================================================================
--- doc/geodynamics.org/benchmarks/trunk/common.py 2009-10-19 19:33:51 UTC (rev 15840)
+++ doc/geodynamics.org/benchmarks/trunk/common.py 2009-10-19 19:34:00 UTC (rev 15841)
@@ -7,12 +7,22 @@
#
import os
+import re
+import hashlib
+# Site URLs
siteroot = "http://geodynamics.org/cig"
softroot = siteroot + "/software"
benchroot = softroot + "/benchmarks"
testroot = benchroot + "/test"
+# Mount points for WebDAV
+webdav_siteroot = "/Volumes/cig"
+webdav_softroot = webdav_siteroot + "/software"
+webdav_benchroot = webdav_softroot + "/benchmarks"
+webdav_testroot = webdav_benchroot + "/test"
+
+# Working-group names
groups = [
'cs',
'geodyn',
@@ -23,7 +33,10 @@
'short',
]
+# Regular expression for parsing site content
+site_content_pattern = re.compile(r"(?P<header>.*)Content-Type: (?P<content_type>.*)\n\n(?P<content>.*)", re.DOTALL)
+
def locate(pattern, root=os.getcwd()):
"""
Return filenames that match given pattern.
@@ -45,6 +58,22 @@
yield line.strip()
+def readfile(filename):
+ """
+ Returns contents of filename.
+ """
+ with open(filename, 'r') as fp:
+ return fp.read()
+
+
+def writefile(filename, contents):
+ """
+ Writes contents into filename.
+ """
+ with open(filename, 'w') as fp:
+ fp.write(contents)
+
+
def split_path(filename):
"""
Split path into three components: (dirname, base, extension)
@@ -55,3 +84,71 @@
return (collection, base, extension)
+def localname(url, ext='.rst'):
+ """
+ Given a relative url, calculate the local filename.
+ """
+ return "%s%s" % (url.replace("/index_html", "/index"), ext)
+
+
+def sitename(filename, prefix=benchroot):
+ """
+ Given a source filename, deduce the corresponding relative url
+ that will be used on the site. If a prefix is given, the url
+ will be made absolute by prepending that prefix.
+ """
+
+ coll, base, ext = split_path(os.path.normpath(filename))
+
+ # plone index pages are named 'index_html'
+ if base == "index":
+ base = "index_html"
+
+ # start with base as our
+ url = base
+
+ # prepend coll if nonempty
+ if coll:
+ url = "%s/%s" % (coll, url)
+
+ # prepend prefix if nonempty
+ if prefix:
+ url = "%s/%s" % (prefix, url)
+
+ return url
+
+
+def headername(filename):
+ root, ext = os.path.splitext(filename)
+ return root + '.header'
+
+
+def latestname(filename):
+ return os.path.normpath(os.path.join('./_latest', filename))
+
+
+def split_content(filename):
+ all = readfile(filename)
+ match = re.match(site_content_pattern, all)
+ meta, content = None, None
+ if match:
+ meta = match.group('header')
+ meta += 'Content-Type: %s\n\n' % match.group('content_type')
+ content = match.group('content')
+ return meta, content
+
+
+def md5sum(s):
+ """
+ Calculate the md5sum of a string
+ """
+ m = hashlib.md5()
+ m.update(s)
+ return m.hexdigest()
+
+def local_md5sum(filename):
+ return md5sum(readfile(filename))
+
+def latest_md5sum(filename):
+ return md5sum(readfile(latestname(filename)))
+
More information about the CIG-COMMITS
mailing list