Bug 1427210: Use python docstrings; r?Fallen draft
authorTom Prince <mozilla@hocat.ca>
Wed, 27 Dec 2017 15:16:03 -0700
changeset 23605 89c1dea4c3878f659d355dca921e28498721c835
parent 23604 34fc1163a375b842a4d0547b5af3f9c3977f2e41
child 23606 f27580cf64d9d9fe7bfd8b50ef45f010b1dcbf23
push id193
push userbmo:mozilla@hocat.ca
push dateWed, 27 Dec 2017 22:25:50 +0000
reviewersFallen
bugs1427210
Bug 1427210: Use python docstrings; r?Fallen MozReview-Commit-ID: 87WEHkrCWdA
mail/check-sync-dirs.py
--- a/mail/check-sync-dirs.py
+++ b/mail/check-sync-dirs.py
@@ -30,49 +30,52 @@ if len(sys.argv) != 3:
     sys.exit(1)
 
 copy = os.path.abspath(sys.argv[1])
 original = os.path.abspath(sys.argv[2])
 
 
 def read_exceptions(filename):
     """
-    Return the contents of FILENAME, a 'check-sync-exceptions' file, as
-    a dictionary whose keys are exactly the list of filenames, along
-    with the basename of FILENAME itself.  If FILENAME does not exist,
-    return the empty dictionary.
+    Return the contents of ``filename``, a 'check-sync-exceptions' file, as a
+    set of filenames, along with the basename of ``filename`` itself.  If
+    ``filename`` does not exist, return the empty set.
     """
     if (os.path.exists(filename)):
         f = file(filename)
         exceptions = set()
         for line in f:
             line = line.strip()
             if line != '' and line[0] != '#':
                 exceptions.add(line)
         exceptions.add(os.path.basename(filename))
         f.close()
         return exceptions
     else:
         return set()
 
 
-# Return true if FILENAME matches any pattern in the list of filename
-# patterns PATTERNS.
 def fnmatch_any(filename, patterns):
+    """
+    Return ``True`` if ``filename`` matches any pattern in the list of filename
+    patterns ``patterns``.
+    """
     for pattern in patterns:
         if fnmatch.fnmatch(filename, pattern):
             return True
     return False
 
 
-# Check the contents of the directory tree COPY against ORIGINAL.  For each
-# file that differs, apply REPORT to COPY, ORIGINAL, and the file's
-# relative path.  COPY and ORIGINAL should be absolute.  Ignore files
-# that match patterns given in the list IGNORE.
 def check(copy, original):
+    """
+    Check the contents of the directory tree ``copy`` against ``original``.  For each
+    file that differs, apply REPORT to ``copy``, ``original``, and the file's
+    relative path.  ``copy`` and ``original`` should be absolute.  Ignore files
+    that match patterns given in files named ``check-sync-exceptions``.
+    """
     os.chdir(copy)
     for (dirpath, dirnames, filenames) in os.walk('.'):
         exceptions = read_exceptions(join(dirpath, 'check-sync-exceptions'))
         for dirname in dirnames:
             if fnmatch_any(dirname, exceptions):
                 dirnames.remove(dirname)
                 break
         for filename in filenames:
@@ -84,19 +87,21 @@ def check(copy, original):
                 and filecmp.cmp(relative_name, original_name, False)):
                 continue
             report(copy, original, relative_name)
 
 
 differences_found = False
 
 
-# Print an error message for DIFFERING, which was found to differ
-# between COPY and ORIGINAL.  Set the global variable differences_found.
 def report(copy, original, differing):
+    """
+    Print an error message for ``differing``, which was found to differ between
+    ``copy`` and ``original``.  Set the global variable ``differences_found``.
+    """
     global differences_found
     if not differences_found:
         print >> sys.stderr, 'TEST-UNEXPECTED-FAIL | check-sync-dirs.py | build file copies are not in sync\n' \
                              'TEST-INFO | check-sync-dirs.py | file(s) found in:               %s\n' \
                              'TEST-INFO | check-sync-dirs.py | differ from their originals in: %s' \
                              % (copy, original)
     print >> sys.stderr, 'TEST-INFO | check-sync-dirs.py | differing file:                 %s' % differing
     differences_found = True