[cmor-tables] 70/83: Updated manip tools

Alastair McKinstry mckinstry at moszumanska.debian.org
Sun Aug 30 08:06:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch master
in repository cmor-tables.

commit b5ba1f89c4d0414e2e819aced8790a166e9e9cd8
Author: Charles Doutriaux <doutriaux1 at llnl.gov>
Date:   Thu May 19 11:05:02 2011 -0700

    Updated manip tools
---
 Lib/tables_manip_tools.py      | 141 ++++++++++++++++++++++-------------------
 Tables_csv/standard_output.xls | Bin 704512 -> 704512 bytes
 2 files changed, 75 insertions(+), 66 deletions(-)

diff --git a/Lib/tables_manip_tools.py b/Lib/tables_manip_tools.py
index c4b8725..700371a 100644
--- a/Lib/tables_manip_tools.py
+++ b/Lib/tables_manip_tools.py
@@ -8,72 +8,81 @@ class TableBadDate(Exception):
     pass
 class TableBadMD5(Exception):
     pass
-def splitTableString(str):
-    sp=str.split()
-    table = sp[1]
-    date=" ".join(sp[2:5])[1:-1].strip()
-    md5 = sp[-1]
-    if len(md5)!=32:
-        md5=None
-    return table,date,md5
-
-def preprocess(table,date=None,md5=None):
-    if date is None and md5 is None:
-        table,date,md5 = splitTableString(table)
-    return table,date,md5
-    
-def fetchLatestTable(table):
-    table,data,md5 = preprocess(table)
-    H=httplib.HTTPConnection("uv-cdat.llnl.gov")
-    H.request("GET","/gitweb/?p=cmip5-cmor-tables.git;a=blob_plain;f=Tables/CMIP5_%s;hb=HEAD" % table)
-    r = H.getresponse()
-    return r.read()
-
-
-def fetchATable(table,commit):
-    H=httplib.HTTPConnection("uv-cdat.llnl.gov")
-    H.request("GET","/gitweb/?p=cmip5-cmor-tables.git;a=blob_plain;f=Tables/CMIP5_%s;h=%s" % (table,commit))
-    r=H.getresponse()
-    return r.read()
-    
-def fetchTable(table,date=None):
-    table,date,md5 = preprocess(table,date)
-    checkTable(table,date)
-    # Ok now fetch the history
-    H=httplib.HTTPConnection("uv-cdat.llnl.gov")
-    H.request("GET","/gitweb/?p=cmip5-cmor-tables.git;a=history;f=Tables/CMIP5_%s;hb=HEAD" % table)
-    r = H.getresponse().read()
-    for l in r.split("\n"):
-        i= l.find(";hp=")
-        if i>-1:
-            commit=l[i+4:i+44]
-            t = fetchATable(table,commit)
-            j=t.find("\ntable_date:")
-            tdate = t[j+12:j+100]
-            tdate = tdate.split("\n")[0].split("!")[0].strip()
-            if tdate == date:
-                break
-    return t
-    
-def checkTable(table,date=None,md5=None):
-    table,date,md5 = preprocess(table,date,md5)
-    H=httplib.HTTPConnection("uv-cdat.llnl.gov")
-    H.request("GET","/gitweb/?p=cmip5-cmor-tables.git;a=blob_plain;f=Tables/md5s;hb=HEAD")
-    r = H.getresponse()
-    md5Table = eval( r.read())["CMIP5"]
-    table = md5Table.get(table,None)
-    if table is None:
-        raise TableBadName("Invalid Table name: %s" % table)
-    dateMd5 = table.get(date,None)
-    if dateMd5 is None:
-        raise TableBadDate("Invalid Table date: %s" % date)
-    if md5 is not None and md5!=dateMd5:
-        raise TableBadMD5("Invalid Table md5: %s" % md5)
-    return
-
-
-t = fetchTable("Oclim","12 May 2010")
-print t
+
+class CMORTables:
+    def __init__(self,name,prefix,url="uv-cdat.llnl.gov"):
+        self.repo_url=url
+        self.repo_name=name
+        self.repo_prefix=prefix
+        self.H=httplib.HTTPConnection(self.repo_url)
+
+    def splitTableString(self,str):
+        sp=str.split()
+        table = sp[1]
+        date=" ".join(sp[2:5])[1:-1].strip()
+        md5 = sp[-1]
+        if len(md5)!=32:
+            md5=None
+        return table,date,md5
+
+    def preprocess(self,table,date=None,md5=None):
+        if date is None and md5 is None:
+            table,date,md5 = splitTableString(table)
+        return table,date,md5
+
+    def fetchLatestTable(self,table):
+        table,data,md5 = self.preprocess(table)
+        self.H.request("GET","/gitweb/?p=%s.git;a=blob_plain;f=Tables/%s_%s;hb=HEAD" % (self.repo_name,self.repo_prefix,table))
+        r = self.H.getresponse()
+        return r.read()
+
+
+    def fetchATable(self,table,commit):
+        self.H.request("GET","/gitweb/?p=%s.git;a=blob_plain;f=Tables/%s_%s;h=%s" % (self.repo_name,self.repo_prefix,table,commit))
+        r=self.H.getresponse()
+        return r.read()
+
+    def fetchTable(self,table,date=None):
+        table,date,md5 = self.preprocess(table,date)
+        self.checkTable(table,date)
+        # Ok now fetch the history
+        self.H.request("GET","/gitweb/?p=%s.git;a=history;f=Tables/%s_%s;hb=HEAD" % (self.repo_name,self.repo_prefix,table))
+        r = self.H.getresponse().read()
+        for l in r.split("\n"):
+            i= l.find(";hp=")
+            if i>-1:
+                commit=l[i+4:i+44]
+                t = self.fetchATable(table,commit)
+                j=t.find("\ntable_date:")
+                tdate = t[j+12:j+100]
+                tdate = tdate.split("\n")[0].split("!")[0].strip()
+                if tdate == date:
+                    break
+        return t
+
+    def checkTable(self,table,date=None,md5=None):
+        table,date,md5 = self.preprocess(table,date,md5)
+        self.H.request("GET","/gitweb/?p=%s.git;a=blob_plain;f=Tables/md5s;hb=HEAD" % self.repo_name)
+        r = self.H.getresponse()
+        md5Table = eval( r.read())[self.repo_prefix]
+        table = md5Table.get(table,None)
+        if table is None:
+            raise TableBadName("Invalid Table name: %s" % table)
+        dateMd5 = table.get(date,None)
+        if dateMd5 is None:
+            raise TableBadDate("Invalid Table date: %s" % date)
+        if md5 is not None and md5!=dateMd5:
+            raise TableBadMD5("Invalid Table md5: %s" % md5)
+        return
+
+if __name__=="__main__":
+    repo_name = "cmip5-cmor-tables"
+    repo_url = "uv-cdat.llnl.gov"
+    repo_prefix="CMIP5"
+    Tables = CMORTables(repo_name,repo_prefix,repo_url)
+    t = Tables.fetchTable("Oclim","12 May 2010")
+    print t
+
 
 ## import cdms2
 ## f=cdms2.open("/git/cmor/CMIP5/output/ukmo/HadCM3/piControl/monClim/ocean/difvso/r1i1p1/difvso_Oclim_HadCM3_piControl_r1i1p1_185001-184912_clim.nc")
diff --git a/Tables_csv/standard_output.xls b/Tables_csv/standard_output.xls
index b3ed0b5..8889b0e 100644
Binary files a/Tables_csv/standard_output.xls and b/Tables_csv/standard_output.xls differ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cmor-tables.git



More information about the debian-science-commits mailing list