/[jscoverage]/trunk/js/config/check-sync-dirs.py
ViewVC logotype

Annotation of /trunk/js/config/check-sync-dirs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 399 - (hide annotations)
Tue Dec 9 03:37:47 2008 UTC (11 years, 10 months ago) by siliconforks
File MIME type: text/x-python
File size: 3891 byte(s)
Use SpiderMonkey from Firefox 3.1b2.

1 siliconforks 399 # check-sync-dirs.py --- check that one directory is an exact subset of another
2     #
3     # Usage: python check-sync-dirs.py COPY ORIGINAL
4     #
5     # Check that the files present in the directory tree COPY are exact
6     # copies of their counterparts in the directory tree ORIGINAL. COPY
7     # need not have all the files in ORIGINAL, but COPY may not have files
8     # absent from ORIGINAL.
9     #
10     # Each directory in COPY may have a file named
11     # 'check-sync-exceptions', which lists files in COPY that need not be
12     # the same as the corresponding file in ORIGINAL, or exist at all in
13     # ORIGINAL. (The 'check-sync-exceptions' file itself is always
14     # treated as exceptional.) Blank lines and '#' comments in the file
15     # are ignored.
16    
17     import sys
18     import os
19     from os.path import join
20     import filecmp
21     import textwrap
22     import fnmatch
23    
24     if len(sys.argv) != 3:
25     print >> sys.stderr, "Usage: %s COPY ORIGINAL" % sys.argv[0]
26     sys.exit(1)
27    
28     copy = sys.argv[1]
29     original = sys.argv[2]
30    
31     # Ignore detritus left lying around by editing tools.
32     ignored_patterns = ['*~', '.#*', '#*#', '*.orig', '*.rej']
33    
34     # Return the contents of FILENAME, a 'check-sync-exceptions' file, as
35     # a dictionary whose keys are exactly the list of filenames, along
36     # with the basename of FILENAME itself. If FILENAME does not exist,
37     # return the empty dictionary.
38     def read_exceptions(filename):
39     if (os.path.exists(filename)):
40     f = file(filename)
41     exceptions={}
42     for line in f:
43     line = line.strip()
44     if line != '' and line[0] != '#':
45     exceptions[line] = None
46     exceptions[os.path.basename (filename)] = None
47     f.close()
48     return exceptions
49     else:
50     return {}
51    
52     # Return true if FILENAME matches any pattern in the list of filename
53     # patterns PATTERNS.
54     def fnmatch_any(filename, patterns):
55     for pattern in patterns:
56     if fnmatch.fnmatch(filename, pattern):
57     return True
58     return False
59    
60     # Check the contents of the directory tree COPY against ORIGINAL. For each
61     # file that differs, apply REPORT to COPY, ORIGINAL, and the file's
62     # relative path. COPY and ORIGINAL should be absolute. Ignore files
63     # that match patterns given in the list IGNORE.
64     def check(copy, original, ignore, report):
65     os.chdir(copy)
66     for (dirpath, dirnames, filenames) in os.walk('.'):
67     exceptions = read_exceptions(join(dirpath, 'check-sync-exceptions'))
68     for filename in filenames:
69     if filename in exceptions:
70     continue
71     if fnmatch_any(filename, ignore):
72     continue
73     relative_name = join(dirpath, filename)
74     original_name = join(original, relative_name)
75     if (os.path.exists(original_name)
76     and filecmp.cmp(relative_name, original_name)):
77     continue
78     report(copy, original, relative_name)
79    
80    
81     differences_found = False
82    
83     # Print an error message for DIFFERING, which was found to differ
84     # between COPY and ORIGINAL. Set the global variable differences_found.
85     def report(copy, original, differing):
86     global differences_found
87     if not differences_found:
88     print >> sys.stderr, "TEST-FAIL | build file copies are not in sync"
89     print >> sys.stderr, "file(s) found in: %s" % (copy)
90     print >> sys.stderr, ("differ from their originals in: %s"
91     % (original))
92     print >> sys.stderr, "file differs: %s" % (differing)
93     differences_found = True
94    
95     check(os.path.abspath(copy),
96     os.path.abspath(original),
97     ignored_patterns,
98     report)
99    
100     if differences_found:
101     msg=('''In general, the files in '%s' should always be exact copies of
102     originals in '%s'. A change made to one should also be made to the
103     other. See 'check-sync-dirs.py' for more details.'''
104     % (copy, original))
105     print >> sys.stderr, textwrap.fill(msg, 75)
106     sys.exit(1)
107    
108     sys.exit(0)

  ViewVC Help
Powered by ViewVC 1.1.24