Merge lp:~stevanr/linaro-license-protection/enhance-validation-script into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Stevan Radaković
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 108
Merged at revision: 112
Proposed branch: lp:~stevanr/linaro-license-protection/enhance-validation-script
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 210 lines (+148/-17)
2 files modified
README (+5/-2)
scripts/validation.py (+143/-15)
To merge this branch: bzr merge lp:~stevanr/linaro-license-protection/enhance-validation-script
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+120940@code.launchpad.net

Description of the change

Enhance validation script to include all *origen* and *snowball* builds with OPEN-EULA present and list all the files with BUILD-INFO file present but which are not covered by build-info patterns.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

While I think I may have confused the spec a bit, this is functional so lets land it and use it. I think it would be good to use the license processing code in the django app - it would show up which files won't be protected on the live site and we get shared enhancements and bug fixes. Will discuss in another thread though.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-08-21 08:08:34 +0000
3+++ README 2012-08-23 08:51:32 +0000
4@@ -160,8 +160,11 @@
5 Validation
6 ..........
7
8-The validation script only purpose is to discover and print the list of
9+The validation script purpose is to discover and print the list of
10 directories which contain a build but do not have any kind of licensing
11-protection. Usage:
12+protection. Furthermore, it will list all *origen* and *snowball* build
13+paths which contain OPEN-EULA license and print out all the build paths where
14+the BUILD-INFO is used but which are not covered by build info patterns.
15+Usage:
16
17 ./validation.py root_builds_dir
18
19=== modified file 'scripts/validation.py'
20--- scripts/validation.py 2012-08-21 08:24:49 +0000
21+++ scripts/validation.py 2012-08-23 08:51:32 +0000
22@@ -3,6 +3,7 @@
23
24 import sys
25 import os
26+import fnmatch
27
28
29 class Validation():
30@@ -17,38 +18,165 @@
31 pass
32
33 @classmethod
34- def find_non_protected_dirs(cls, rootdir):
35-
36- non_handled_dirs = []
37+ def has_license_handling(cls, dir_path):
38+ """Check if there is any form of license handling in directory."""
39+ for fname in os.listdir(dir_path):
40+ if os.path.isfile(os.path.join(dir_path, fname)):
41+ for mode in cls.LICENSE_FILE_LIST:
42+ if mode in fname:
43+ return True
44+ return False
45+
46+ @classmethod
47+ def has_open_eula(cls, dir_path):
48+ """Check if there is OPEN-EULA file in a directory."""
49+ for fname in os.listdir(dir_path):
50+ if os.path.isfile(os.path.join(dir_path, fname)):
51+ if "OPEN-EULA" in fname:
52+ return True
53+ return False
54+
55+ @classmethod
56+ def has_build_info(cls, dir_path):
57+ """Check if there is BUILD-INFO file in a directory."""
58+ for fname in os.listdir(dir_path):
59+ if os.path.isfile(os.path.join(dir_path, fname)):
60+ if "BUILD-INFO.txt" in fname:
61+ return True
62+ return False
63+
64+ @classmethod
65+ def get_regular_files(cls, dir_path):
66+ """Returns all non-meta files in a directory."""
67+ result_files = []
68+
69+ for fname in os.listdir(dir_path):
70+ is_meta = False
71+ file_path = os.path.join(dir_path, fname)
72+ if os.path.isfile(file_path):
73+ for mode in cls.LICENSE_FILE_LIST:
74+ if mode in fname:
75+ is_meta = True
76+ if not is_meta:
77+ result_files.append(fname)
78+
79+ return result_files
80+
81+ @classmethod
82+ def get_build_info_patterns(cls, build_info_path):
83+ """Get all patterns from BUILD-INFO file."""
84+ patterns = []
85+
86+ with open(build_info_path, "r") as infile:
87+ lines = infile.readlines()
88+
89+ for line in lines:
90+ line = line.strip()
91+ if line != '' and "Files-Pattern" in line:
92+ values = line.split(":", 1)
93+ patterns.append(values[1].strip())
94+
95+ return patterns
96+
97+ @classmethod
98+ def get_dirs_with_build(cls, rootdir):
99+ """Get only bottom level directories which contain builds."""
100+
101+ result_paths = []
102
103 for root, subFolders, files in os.walk(rootdir):
104
105 for dir in subFolders:
106 dir_path = os.path.join(root, dir)
107- has_build = False
108 for fname in os.listdir(dir_path):
109 if os.path.isfile(os.path.join(dir_path, fname)):
110 if "gz" in os.path.splitext(fname)[1] or \
111 "bz2" in os.path.splitext(fname)[1]:
112- has_build = True
113+ result_paths.append(dir_path)
114 break
115- if has_build:
116- if not cls.has_license_handling(dir_path):
117- non_handled_dirs.append(dir_path)
118+ return result_paths
119+
120+ @classmethod
121+ def get_dirs_with_build_info(cls, rootdir):
122+ """Get only bottom level directories which contain builds."""
123+
124+ build_info_dirs = []
125+ dirs_with_build = cls.get_dirs_with_build(rootdir)
126+
127+ for dir_path in dirs_with_build:
128+ if cls.has_build_info(dir_path):
129+ build_info_dirs.append(dir_path)
130+
131+ return build_info_dirs
132+
133+ @classmethod
134+ def find_non_protected_dirs(cls, rootdir):
135+
136+ non_handled_dirs = []
137+ dirs_with_build = cls.get_dirs_with_build(rootdir)
138+
139+ for dir_path in dirs_with_build:
140+ if not cls.has_license_handling(dir_path):
141+ non_handled_dirs.append(dir_path)
142
143 return non_handled_dirs
144
145 @classmethod
146- def has_license_handling(cls, dir_path):
147- for fname in os.listdir(dir_path):
148- if os.path.isfile(os.path.join(dir_path, fname)):
149- for mode in cls.LICENSE_FILE_LIST:
150- if mode in fname:
151- return True
152- return False
153+ def find_licensed_with_open_eula(cls, rootdir):
154+
155+ result_dirs = []
156+ dirs_with_build = cls.get_dirs_with_build(rootdir)
157+
158+ for dir_path in dirs_with_build:
159+ if "origen" in dir_path or "snowball" in dir_path:
160+ if cls.has_open_eula(dir_path):
161+ result_dirs.append(dir_path)
162+
163+ return result_dirs
164+
165+ @classmethod
166+ def find_non_matched_build_info_files(cls, rootdir):
167+
168+ result_files = []
169+ dirs_with_build_info = cls.get_dirs_with_build_info(rootdir)
170+
171+ for dir_path in dirs_with_build_info:
172+ buildinfo_path = os.path.join(dir_path, "BUILD-INFO.txt")
173+
174+ if os.path.isfile(buildinfo_path):
175+ patterns = cls.get_build_info_patterns(buildinfo_path)
176+ for fname in cls.get_regular_files(dir_path):
177+ file_matched = False
178+
179+ for pattern in patterns:
180+ if fnmatch.fnmatch(fname, pattern):
181+ file_matched = True
182+ continue
183+
184+ if not file_matched:
185+ result_files.append(os.path.join(dir_path, fname))
186+
187+ return result_files
188
189 if __name__ == '__main__':
190
191+ print "-" * 31
192+ print "Non protected paths with builds"
193+ print "-" * 31
194 result_dirs = Validation.find_non_protected_dirs(sys.argv[1])
195 for dir in result_dirs:
196 print dir
197+
198+ print "-" * 50
199+ print "Origen and snowball builds licensed with Open EULA"
200+ print "-" * 50
201+ result_dirs = Validation.find_licensed_with_open_eula(sys.argv[1])
202+ for dir in result_dirs:
203+ print dir
204+
205+ print "-" * 62
206+ print "Builds with BUILD INFO file not covered by build info patterns"
207+ print "-" * 62
208+ result_files = Validation.find_non_matched_build_info_files(sys.argv[1])
209+ for file in result_files:
210+ print file

Subscribers

People subscribed via source and target branches