[PATCH 2 of 4] verify-cvs2svn: normalize pass/fail reporting

Greg Ward <[email protected]>
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <54ea2724fd19648bb1ad.1250643308@davros>
- terminology change: "anomaly" to "fail"
- make "pass" explicit (when doing a full verification, at least)
- allow multiple failures on individual files (mode and contents)

Also:
- code formatting
- add __str__() method to the three *Repos classes
- use True/False instead of 1/0

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2385054

To unsubscribe from this discussion, e-mail: [[email protected]].
verify-normalize-reporting.patch (text/x-patch, 6.2 KB)
# HG changeset patch
# User Greg Ward <[email protected]>
# Date 1249137830 14400
# Node ID 54ea2724fd19648bb1ad68377e564372a7a73818
# Parent  b7079a58632a3499400b84c084de8e6c0b52f12c
verify-cvs2svn: normalize pass/fail reporting.
- terminology change: "anomaly" to "fail"
- make "pass" explicit (when doing a full verification, at least)
- allow multiple failures on individual files (mode and contents)

Also:
- code formatting
- add __str__() method to the three *Repos classes
- use True/False instead of 1/0

diff --git a/contrib/verify-cvs2svn.py b/contrib/verify-cvs2svn.py
--- a/contrib/verify-cvs2svn.py
+++ b/contrib/verify-cvs2svn.py
@@ -78,6 +78,9 @@
         self.module = os.path.join(os.path.basename(self.cvsroot), self.module)
         self.cvsroot = parent
 
+  def __str__(self):
+    return os.path.basename(self.cvsroot)
+
   def export(self, dest_path, rev=None):
     """Export revision REV to DEST_PATH where REV can be None to export
     the HEAD revision, or any valid CVS revision string to export that
@@ -119,6 +122,9 @@
     else:
       self.branch_list = []
 
+  def __str__(self):
+    return self.url.split('/')[-1]
+
   def export(self, path, dest_path):
     """Export PATH to DEST_PATH."""
     url = '/'.join([self.url, path])
@@ -169,6 +175,9 @@
     self._branches = None               # cache result of branches()
     self._have_default = None           # so export_trunk() doesn't blow up
 
+  def __str__(self):
+    return os.path.basename(self.path)
+
   def _export(self, dest_path, rev):
     cmd = self.base_cmd + ['archive',
                            '--type', 'files',
@@ -257,10 +266,10 @@
 
   def report(self, summary, details=None):
     self.count += 1
-    sys.stdout.write('*** ANOMALY: %s\n' % summary)
+    sys.stdout.write(' FAIL: %s\n' % summary)
     if details:
       for line in details:
-        sys.stdout.write('***  %s\n' % line)
+        sys.stdout.write('  %s\n' % line)
 
   def __nonzero__(self):
     return self.count > 0
@@ -270,6 +279,7 @@
   specified as two base paths BASE1 and BASE2, and a path REL_PATH that
   is relative to the two base paths.  Return 1 if the file mode and
   contents are identical, else 0."""
+  ok = True
   path1 = os.path.join(base1, rel_path)
   path2 = os.path.join(base2, rel_path)
   mode1 = os.stat(path1).st_mode & 0700   # only look at owner bits
@@ -278,10 +288,11 @@
     failures.report('File modes differ for %s' % rel_path,
                     details=['%s: %o' % (path1, mode1),
                              '%s: %o' % (path2, mode2)])
+    ok = False
 
   file1 = open(path1, 'rb')
   file2 = open(path2, 'rb')
-  while 1:
+  while True:
     data1 = file1.read(8192)
     data2 = file2.read(8192)
     if data1 != data2:
@@ -293,9 +304,11 @@
         diff = None
       failures.report('File contents differ for %s' % rel_path,
                       details=diff)
-      return 0
-    if len(data1) == 0:
-      return 1
+      ok = False
+    if len(data1) == 0:                 # eof
+      break
+
+  return ok
 
 
 def tree_compare(failures, base1, base2, run_diff, rel_path=''):
@@ -386,18 +399,22 @@
   and files in the trunk, all tags and all branches in the conversion
   repository VERIFYREPOS matches the ones in the CVS repository CVSREPOS.
   CTX is passed through to verify_contents_single()."""
-  anomalies = []
+  locations = []                        # branches/tags that failed
 
   # Verify contents of trunk
   print 'Verifying trunk'
-  if not verify_contents_single(failures, cvsrepos, verifyrepos, 'trunk', None, ctx):
-    anomalies.append('trunk')
+  ok = verify_contents_single(
+    failures, cvsrepos, verifyrepos, 'trunk', None, ctx)
+  if not ok:
+    locations.append('trunk')
 
   # Verify contents of all tags
   for tag in verifyrepos.tags():
     print 'Verifying tag', tag
-    if not verify_contents_single(failures, cvsrepos, verifyrepos, 'tag', tag, ctx):
-      anomalies.append('tag:' + tag)
+    ok = verify_contents_single(
+      failures, cvsrepos, verifyrepos, 'tag', tag, ctx)
+    if not ok:
+      locations.append('tag:' + tag)
 
   # Verify contents of all branches
   for branch in verifyrepos.branches():
@@ -405,18 +422,21 @@
       print 'Skipped branch', branch
     else:
       print 'Verifying branch', branch
-      if not verify_contents_single(failures, cvsrepos, verifyrepos, 'branch', branch, ctx):
-        anomalies.append('branch:' + branch)
+      ok = verify_contents_single(
+        failures, cvsrepos, verifyrepos, 'branch', branch, ctx)
+      if not ok:
+        locations.append('branch:' + branch)
+
+  assert bool(failures) == bool(locations)
 
   # Show the results
-  if len(anomalies) == 0:
-    print 'No content anomalies detected'
+  if failures:
+    sys.stdout.write('FAIL: %s != %s: %d failure(s) in:\n'
+                     % (cvsrepos, verifyrepos, failures.count))
+    for location in locations:
+      sys.stdout.write('  %s\n' % location)
   else:
-    print '%d content anomal%s detected:' % (len(anomalies),
-        len(anomalies) == 1 and "y" or "ies")
-    for anomaly in anomalies:
-      print '   ', anomaly
-
+    sys.stdout.write('PASS: %s == %s\n' % (cvsrepos, verifyrepos))
 
 class OptionContext:
   pass
@@ -494,16 +514,20 @@
     # Do our thing...
     if verify_branch:
       print 'Verifying branch', verify_branch
-      verify_contents_single(failures, cvsrepos, verifyrepos, 'branch', verify_branch, options)
+      verify_contents_single(
+        failures, cvsrepos, verifyrepos, 'branch', verify_branch, options)
     elif verify_tag:
       print 'Verifying tag', verify_tag
-      verify_contents_single(failures, cvsrepos, verifyrepos, 'tag', verify_tag, options)
+      verify_contents_single(
+        failures, cvsrepos, verifyrepos, 'tag', verify_tag, options)
     elif verify_trunk:
       print 'Verifying trunk'
-      verify_contents_single(failures, cvsrepos, verifyrepos, 'trunk', None, options)
+      verify_contents_single(
+        failures, cvsrepos, verifyrepos, 'trunk', None, options)
     else:
       # Verify trunk, tags and branches
-      verify_contents(failures, cvsrepos, verifyrepos, options)
+      verify_contents(
+        failures, cvsrepos, verifyrepos, options)
   except RuntimeError, e:
     error(str(e))
   except KeyboardInterrupt:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.