release_diff.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import difflib
4 import os
5 import sys
6 import argparse
7 
8 def getPackageDirAndMake(path, base, outDir):
9  packageDir = os.path.dirname(path).replace(base, "")
10  outPackageDir = os.path.join(outDir, packageDir)
11  if not os.path.isdir(outPackageDir):
12  os.makedirs(outPackageDir)
13  return outPackageDir
14 
15 
16 
17 parser = argparse.ArgumentParser("""
18 Take two release directories and analyze the contents to find differences.
19 Input: later release, earlier release, output directory
20 Output: A directory structure in --out which contains directories for packages
21 which have differences. Sub-directory structure is maintained. Three types of
22 files will exist in the structure. The later type is _diff.txt which shows
23 the differences in unified diff format. The other two types end with _added and
24 _removed for files which were added/removed between the earlier and later
25 releases.
26 """)
27 parser.add_argument('--later', '-L', type=str, required=True, help="""
28  "Later" of the two releases, files in this release but not the earlier
29  will show up as _added""")
30 parser.add_argument('--earlier', '-E', type=str, required=True, help="""
31  "Earlier" of the two releases, files in this release but not the earlier
32  will show up as _removed.""")
33 parser.add_argument('--out', '-o', type=str, required=True, help="""
34  Output directory for all differences. Output will mirror release directory
35  structure""")
36 
37 
38 ignoreStrings = ["CMakeLists.txt", "_dict.cc"]
39 
40 args = parser.parse_args()
41 
42 
43 later = os.path.join(args.later, "")
44 earlier = os.path.join(args.earlier, "")
45 
46 outDir = args.out
47 
48 laterBase = os.path.basename(os.path.dirname(later))
49 earlierBase = os.path.basename(os.path.dirname(earlier))
50 
51 
52 for directory in [later,earlier]:
53  if not os.path.isdir(directory):
54  raise Exception("Error -- directory not found: " + directory)
55 
56 for root, dirs, files in os.walk(later, topdown=True):
57  if ".svn" in root:
58  continue
59  if "Linux2.6" in root:
60  continue
61 
62  for name in files:
63  ignore = False
64  for string in ignoreStrings:
65  if string in name: ignore = True
66  if ignore: continue
67 
68 
69  laterPath = os.path.join(root, name)
70  earlierPath = laterPath.replace(later, earlier)
71  if not os.path.isfile(earlierPath):
72  outPackageDir = getPackageDirAndMake(laterPath, later, outDir)
73  outFilePath = os.path.join(outPackageDir, name + "_added")
74  open(outFilePath,'w').write(open(laterPath, 'r').read())
75  continue
76 
77  laterLines = open(laterPath, 'r').readlines()
78  earlierLines = open(earlierPath, 'r').readlines()
79 
80  diff = list(difflib.unified_diff(earlierLines, laterLines,
81  fromfile=earlierBase, tofile=laterBase))
82  if len(diff) > 0:
83  outPackageDir = getPackageDirAndMake(laterPath, later, outDir)
84  outFilePath = os.path.join(outPackageDir, name + "_diff")
85  open(outFilePath, 'w').writelines(diff)
86 
87 
88 
89 
90 
91 for root, dirs, files in os.walk(earlier, topdown=True):
92  if ".svn" in root:
93  continue
94  if "Linux2.6" in root:
95  continue
96 
97 
98  for name in files:
99  ignore = False
100  for string in ignoreStrings:
101  if string in name: ignore = True
102  if ignore: continue
103 
104 
105  earlierPath = os.path.join(root, name)
106  laterPath = earlierPath.replace(earlier, later)
107  if not os.path.isfile(laterPath):
108  outPackageDir = getPackageDirAndMake(earlierPath, earlier, outDir)
109  outFilePath = os.path.join(outPackageDir, name + "_removed")
110  open(outFilePath,'w').write(open(earlierPath, 'r').read())
111 
112 
113 
def getPackageDirAndMake(path, base, outDir)
Definition: release_diff.py:8
write
Run ND cosmics.
procfile open("FD_BRL_v0.txt")
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66