incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r614718 - /incubator/public/trunk/diff.py
Date Wed, 23 Jan 2008 22:37:44 GMT
Author: rdonkin
Date: Wed Jan 23 14:37:41 2008
New Revision: 614718

URL: http://svn.apache.org/viewvc?rev=614718&view=rev
Log:
Render differences into xml document

Modified:
    incubator/public/trunk/diff.py

Modified: incubator/public/trunk/diff.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/diff.py?rev=614718&r1=614717&r2=614718&view=diff
==============================================================================
--- incubator/public/trunk/diff.py (original)
+++ incubator/public/trunk/diff.py Wed Jan 23 14:37:41 2008
@@ -13,7 +13,17 @@
 #########################################################################################
 
 import xml.parsers.expat
+import os
+import os.path
+import subprocess
 
+class InvalidDocument(Exception):
+    def __init__(self, value):
+        self.value = value
+        
+    def __str__(self):
+        return repr(self.value)
+        
 class Document:
     def __init__(self):
         self.reset()
@@ -49,7 +59,6 @@
         
     def start_element(self, name, attrs):
         if name == 'document':
-            print attrs
             self.name = attrs.get('name')
             self.dir = attrs.get('dir')
         elif name == 'md5':
@@ -84,6 +93,9 @@
         else:
             return not (document.md5 == self.md5 and document.sha == self.sha 
                         and document.ripemd == self.ripemd)
+            
+    def summaryXml(self):
+        return '<document name="' + self.name + '" dir="' + self.dir + '"/>'
     
 def document(dir, name, md5, sha, ripemd):
     result = Document()
@@ -152,4 +164,55 @@
     results = Documents()
     for document in documents:
         results.append(document)
-    return results
\ No newline at end of file
+    return results
+
+class Auditor:
+    def __init__(self, basedir):
+        self.basedir = basedir
+        
+    def printSignatureChecks(self):
+        for file in os.listdir(self.basedir):
+            if file.endswith('.asc'):
+                print file
+                subprocess.Popen('gpg --verify ' + os.path.join(self.basedir, file), shell=True).wait()
+                print
+                
+    def load(self, name):
+        f = open(os.path.join(self.basedir, name), 'r')
+        try:
+            documents = Documents()
+            documents.load(f.read())
+            if not documents.on == name[-14:-4]:
+                raise InvalidDocument('Document date does not match file date.')
+            return documents
+        finally:
+            f.close()
+            
+    def latest(self):
+        xmlDocuments = filter(lambda x:x.endswith('.xml'), os.listdir(self.basedir))
+        xmlDocuments.sort()
+        return map(self.load, xmlDocuments[-2:])
+                
+    def latestDiffs(self):
+        latest = self.latest()
+        return self.diffs(latest[1], latest[0])
+        
+    def diffs(self, one, two):
+        added, removed, modified = one.compare(two)
+        toXml = lambda a, name: simpleElement(name, reduce(lambda b, c: b + c, map(lambda
x: x.summaryXml(), a), ''))
+        diff = toXml(added, 'added') + toXml(modified, 'modified') + toXml(removed, 'missing')
+        return '<changes from="' + two.on + '" to="' + one.on + '">' + diff + '</changes>'

+                
+def simpleElement(element, body):
+    return startTag(element) + body + endTag(element)
+                
+def startTag(element):
+    return '<' + element + '>'
+ 
+def endTag(element):
+    return '</' + element + '>'
+                
+if __name__ == '__main__':
+    auditor = Auditor('audit')
+    auditor.printSignatureChecks()
+    print auditor.latestDiffs()
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message