PageRenderTime 22ms CodeModel.GetById 8ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/Scripts/CompareDirs.py

#
Python | 46 lines | 26 code | 6 blank | 14 comment | 11 complexity | 37ecaa985c3630f28feee88a900fc034 MD5 | raw file
 1#####################################################################################
 2#
 3#  Copyright (c) Microsoft Corporation. All rights reserved.
 4#
 5# This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6# copy of the license can be found in the License.html file at the root of this distribution. If 
 7# you cannot locate the  Apache License, Version 2.0, please send an email to 
 8# ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9# by the terms of the Apache License, Version 2.0.
10#
11# You must not remove this notice, or any other, from this software.
12#
13#
14#####################################################################################
15
16import sys,nt
17sys.path.append(nt.environ['IP_ROOT'] + '\\External\\Regress\\Python24\\Lib')
18import filecmp
19
20def compare_dirs(dir1, dir2):
21    "Tests whether two folders, including all their contents and subdirectories are identical or not (True == they're the same, False == they are not the same)"
22    dc = filecmp.dircmp(dir1,dir2)
23    if len(dc.funny_files) > 0 or len(dc.left_only) > 0 or len(dc.right_only) > 0 or len(dc.diff_files) > 0:
24        dc.report()
25        return False
26    else:
27        for subdir in dc.common_dirs:
28            if not compare_dirs(dir1 + "\\" + subdir, dir2 + "\\" + subdir):
29                return False
30        return True
31
32
33def main():
34    if len(sys.argv)!=3:
35        print 'Usage: CompareDirs <dir1> <dir2>'
36        sys.exit(-1)
37        
38    if compare_dirs(sys.argv[1],sys.argv[2]):
39        print "The directories are identical"
40        sys.exit(0)
41    else: #the part that differed is explained via dircmp.report() above
42        print "The directories differ"
43        sys.exit(1)
44
45if __name__=="__main__":
46    main()