[Commits] (heikki) Minor refactoring - move MD5sum and SHAsum into hardhatutil and combine their common body.

commits at osafoundation.org commits at osafoundation.org
Wed Sep 8 19:30:50 PDT 2004


Commit by: heikki
Modified files:
hardhat/distIndex.py 1.3 1.4
hardhat/hardhatutil.py 1.5 1.6
hardhat/tinderbox.py 1.20 1.21

Log message:
Minor refactoring - move MD5sum and SHAsum into hardhatutil and combine their common body.

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/hardhat/distIndex.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4
http://cvs.osafoundation.org/index.cgi/hardhat/hardhatutil.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/hardhat/tinderbox.py.diff?r1=text&tr1=1.20&r2=text&tr2=1.21

Index: hardhat/hardhatutil.py
diff -u hardhat/hardhatutil.py:1.5 hardhat/hardhatutil.py:1.6
--- hardhat/hardhatutil.py:1.5	Thu Aug 26 13:05:13 2004
+++ hardhat/hardhatutil.py	Wed Sep  8 19:30:49 2004
@@ -1,4 +1,4 @@
-import os, sys, time
+import os, sys, time, sha, md5
 
 def findInPath(path,fileName):
     dirs = path.split(os.pathsep)
@@ -186,3 +186,22 @@
     s = s.replace(":", "")
     return s
 
+
+def _checksum(hashobj, filename):
+    fileobj = open(filename)
+    filedata = fileobj.read()
+    fileobj.close()
+    hashobj.update(filedata)
+    return hashobj.hexdigest()
+    
+
+def MD5sum(filename):
+    """Compute MD5 checksum for the file
+    """
+    return _checksum(md5.new(), filename)
+
+
+def SHAsum(filename):
+    """Compute SHA-1 checksum for the file
+    """
+    return _checksum(sha.new(), filename)

Index: hardhat/distIndex.py
diff -u hardhat/distIndex.py:1.3 hardhat/distIndex.py:1.4
--- hardhat/distIndex.py:1.3	Fri Aug 27 12:59:33 2004
+++ hardhat/distIndex.py	Wed Sep  8 19:30:49 2004
@@ -14,7 +14,7 @@
 True = 1
 False = 0
 
-import os, sys, shutil, re, time, string, sha, md5
+import os, sys, shutil, re, time, string
 from optparse import OptionParser
 
 path = os.environ.get('PATH', os.environ.get('path'))
@@ -49,26 +49,6 @@
     'developer' : ["Developers' distribution", "If you're a developer and want to run Chandler in debugging mode, this distribution contains debug versions of the binaries.  Assertions are active, the __debug__ global is set to True, and memory leaks are listed upon exit.  You can also use this distribution to develop your own parcels (See <a href='http://wiki.osafoundation.org/bin/view/Chandler/ParcelLoading'>Parcel Loading</a> for details on loading your own parcels)."],
 }
 
-def MD5sum(filename):
-    """Compute MD5 checksum for the file
-    """
-    m = md5.new()
-    fileobj = open(filename)
-    filedata = fileobj.read()
-    fileobj.close()
-    m.update(filedata)
-    return m.hexdigest()
-
-def SHAsum(filename):
-    """Compute SHA-1 checksum for the file
-    """
-    s = sha.new()
-    fileobj = open(filename)
-    filedata = fileobj.read()
-    fileobj.close()
-    s.update(filedata)
-    return s.hexdigest()
-
 def MakeJS(buildName, buildType):
     """
     Generates a javascript 'id.js' page for a Chandler Milestone/Release build
@@ -122,8 +102,10 @@
             fileOut.write("<tr><td>\n")
             fileOut.write("<h3><a href=http://builds.osafoundation.org" + fileName + ">" + thisFile + "</a></h3>\n</td></tr>\n")
             fileOut.write("<tr><td>\n")
-            fileOut.write(" MD5 checksum: " + MD5sum(fileName) + "<br>")
-            fileOut.write(" SHA checksum: " + SHAsum(fileName) + "<br>")
+            fileOut.write(" MD5 checksum: " + hardhatutil.MD5sum(fileName) +\
+                          "<br>")
+            fileOut.write(" SHA checksum: " + hardhatutil.SHAsum(fileName) +\
+                          "<br>")
             fileOut.write("</td></tr>\n<tr><td><hr></td></tr>\n")
         elif fileName.find("Chan") > 0:
             print "Generating data for ", thisFile
@@ -136,8 +118,10 @@
             else:
                 fileOut.write( _descriptions['enduser'][1])
             fileOut.write("<tr><td>\n")
-            fileOut.write(" MD5 checksum: " + MD5sum(fileName) + "<br>")
-            fileOut.write(" SHA checksum: " + SHAsum(fileName) + "<br>")
+            fileOut.write(" MD5 checksum: " + hardhatutil.MD5sum(fileName) +\
+                          "<br>")
+            fileOut.write(" SHA checksum: " + hardhatutil.SHAsum(fileName) +\
+                          "<br>")
             fileOut.write("</td></tr>\n<tr><td><hr></td></tr>\n")
         else:
             print "skipping ", thisFile

Index: hardhat/tinderbox.py
diff -u hardhat/tinderbox.py:1.20 hardhat/tinderbox.py:1.21
--- hardhat/tinderbox.py:1.20	Wed Sep  8 17:31:14 2004
+++ hardhat/tinderbox.py	Wed Sep  8 19:30:49 2004
@@ -6,7 +6,7 @@
 # The cycle.py script does the hardhat updates, so any changes
 # to the main script can be picked up
 
-import hardhatutil, time, smtplib, os, sys, md5, sha
+import hardhatutil, time, smtplib, os, sys
 from optparse import OptionParser
 
 whereAmI = os.path.dirname(os.path.abspath(hardhatutil.__file__))
@@ -270,26 +270,6 @@
     'developer' : ["Developers' distribution", "If you're a developer and want to run Chandler in debugging mode, this distribution contains debug versions of the binaries.  Assertions are active, the __debug__ global is set to True, and memory leaks are listed upon exit.  You can also use this distribution to develop your own parcels (See <a href='http://wiki.osafoundation.org/bin/view/Chandler/ParcelLoading'>Parcel Loading</a> for details on loading your own parcels)."],
 }
 
-def MD5sum(filename):
-    """Compute MD5 checksum for the file
-    """
-    m = md5.new()
-    fileobj = open(filename)
-    filedata = fileobj.read()
-    fileobj.close()
-    m.update(filedata)
-    return m.hexdigest()
-
-def SHAsum(filename):
-    """Compute SHA-1 checksum for the file
-    """
-    s = sha.new()
-    fileobj = open(filename)
-    filedata = fileobj.read()
-    fileobj.close()
-    s.update(filedata)
-    return s.hexdigest()
-
 
 def CreateIndex(outputDir, newDirName, nowString, buildName):
     """
@@ -319,10 +299,12 @@
 
         index += '<p>Download <a href="' + actualDistroFile + '"> ' +\
                  _descriptions[distro][0] + '</a>: <br>\n' +\
-                 ' MD5 checksum: ' + MD5sum(outputDir + os.sep + newDirName +\
+                 ' MD5 checksum: ' + hardhatutil.MD5sum(outputDir + os.sep +\
+                                                        newDirName +\
                                             os.sep + actualDistroFile) +\
                  '<br>\n' +\
-                 ' SHA checksum: ' + SHAsum(outputDir + os.sep + newDirName +\
+                 ' SHA checksum: ' + hardhatutil.SHAsum(outputDir + os.sep +\
+                                                        newDirName +\
                                             os.sep + actualDistroFile) +\
                  '<br>\n<p> ' + _descriptions[distro][1] + '</p>\n' +\
                  '</body></html>\n'
@@ -346,7 +328,8 @@
     fileOut = file(outputDir+os.sep+"time.js", "w")
     fileOut.write("document.write('" + nowString + "');\n")
     fileOut.close()
-    
+
+
 def _readFile(path):
     fileIn = open(path, "r")
     line = fileIn.readline()



More information about the Commits mailing list