1 |
commit: 73168c4a34b2dd4bb7d817ae353b968d5f202485 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jan 3 23:09:27 2016 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jan 29 04:52:58 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=73168c4a |
7 |
|
8 |
repoman: Migrate license checks to a plugin module |
9 |
|
10 |
pym/repoman/checks/ebuilds/variables/license.py | 47 ---------------------- |
11 |
pym/repoman/modules/scan/metadata/__init__.py | 9 +++++ |
12 |
pym/repoman/modules/scan/metadata/license.py | 53 +++++++++++++++++++++++++ |
13 |
pym/repoman/scanner.py | 7 +--- |
14 |
4 files changed, 63 insertions(+), 53 deletions(-) |
15 |
|
16 |
diff --git a/pym/repoman/checks/ebuilds/variables/license.py b/pym/repoman/checks/ebuilds/variables/license.py |
17 |
deleted file mode 100644 |
18 |
index bdc859c..0000000 |
19 |
--- a/pym/repoman/checks/ebuilds/variables/license.py |
20 |
+++ /dev/null |
21 |
@@ -1,47 +0,0 @@ |
22 |
- |
23 |
-'''description.py |
24 |
-Perform checks on the LICENSE variable. |
25 |
-''' |
26 |
- |
27 |
-# import our initialized portage instance |
28 |
-from repoman._portage import portage |
29 |
- |
30 |
- |
31 |
-class LicenseChecks(object): |
32 |
- '''Perform checks on the LICENSE variable.''' |
33 |
- |
34 |
- def __init__(self, qatracker, liclist, liclist_deprecated): |
35 |
- ''' |
36 |
- @param qatracker: QATracker instance |
37 |
- @param liclist: List of licenses. |
38 |
- @param liclist: List of deprecated licenses. |
39 |
- ''' |
40 |
- self.qatracker = qatracker |
41 |
- self.liclist = liclist |
42 |
- self.liclist_deprecated = liclist_deprecated |
43 |
- |
44 |
- def check( |
45 |
- self, pkg, package, ebuild, y_ebuild): |
46 |
- ''' |
47 |
- @param pkg: Package in which we check (object). |
48 |
- @param package: Package in which we check (string). |
49 |
- @param ebuild: Ebuild which we check (object). |
50 |
- @param y_ebuild: Ebuild which we check (string). |
51 |
- ''' |
52 |
- |
53 |
- # Parse the LICENSE variable, remove USE conditions and flatten it. |
54 |
- licenses = portage.dep.use_reduce( |
55 |
- pkg._metadata["LICENSE"], matchall=1, flat=True) |
56 |
- |
57 |
- # Check each entry to ensure that it exists in ${PORTDIR}/licenses/. |
58 |
- for lic in licenses: |
59 |
- # Need to check for "||" manually as no portage |
60 |
- # function will remove it without removing values. |
61 |
- if lic not in self.liclist and lic != "||": |
62 |
- self.qatracker.add_error( |
63 |
- "LICENSE.invalid", |
64 |
- package + "/" + y_ebuild + ".ebuild: %s" % lic) |
65 |
- elif lic in self.liclist_deprecated: |
66 |
- self.qatracker.add_error( |
67 |
- "LICENSE.deprecated", |
68 |
- "%s: %s" % (ebuild.relative_path, lic)) |
69 |
|
70 |
diff --git a/pym/repoman/modules/scan/metadata/__init__.py b/pym/repoman/modules/scan/metadata/__init__.py |
71 |
index 83aac7f..c8f3609 100644 |
72 |
--- a/pym/repoman/modules/scan/metadata/__init__.py |
73 |
+++ b/pym/repoman/modules/scan/metadata/__init__.py |
74 |
@@ -37,6 +37,15 @@ module_spec = { |
75 |
'func_desc': { |
76 |
}, |
77 |
}, |
78 |
+ 'license-metadata': { |
79 |
+ 'name': "license", |
80 |
+ 'sourcefile': "license", |
81 |
+ 'class': "LicenseChecks", |
82 |
+ 'description': doc, |
83 |
+ 'functions': ['check'], |
84 |
+ 'func_desc': { |
85 |
+ }, |
86 |
+ }, |
87 |
} |
88 |
} |
89 |
|
90 |
|
91 |
diff --git a/pym/repoman/modules/scan/metadata/license.py b/pym/repoman/modules/scan/metadata/license.py |
92 |
new file mode 100644 |
93 |
index 0000000..b022b20 |
94 |
--- /dev/null |
95 |
+++ b/pym/repoman/modules/scan/metadata/license.py |
96 |
@@ -0,0 +1,53 @@ |
97 |
+ |
98 |
+'''license.py |
99 |
+Perform checks on the LICENSE variable. |
100 |
+''' |
101 |
+ |
102 |
+# import our initialized portage instance |
103 |
+from repoman._portage import portage |
104 |
+ |
105 |
+ |
106 |
+class LicenseChecks(object): |
107 |
+ '''Perform checks on the LICENSE variable.''' |
108 |
+ |
109 |
+ def __init__(self, **kwargs): |
110 |
+ ''' |
111 |
+ @param qatracker: QATracker instance |
112 |
+ @param repo_metadata: dictionary of various repository items. |
113 |
+ ''' |
114 |
+ self.qatracker = kwargs.get('qatracker') |
115 |
+ self.repo_metadata = kwargs.get('repo_metadata') |
116 |
+ |
117 |
+ def check(self, **kwargs): |
118 |
+ ''' |
119 |
+ @param xpkg: Package in which we check (string). |
120 |
+ @param ebuild: Ebuild which we check (object). |
121 |
+ @param y_ebuild: Ebuild which we check (string). |
122 |
+ ''' |
123 |
+ xpkg = kwargs.get('xpkg') |
124 |
+ ebuild = kwargs.get('ebuild') |
125 |
+ y_ebuild = kwargs.get('y_ebuild') |
126 |
+ if not kwargs.get('badlicsyntax'): |
127 |
+ # Parse the LICENSE variable, remove USE conditions and flatten it. |
128 |
+ licenses = portage.dep.use_reduce( |
129 |
+ ebuild.metadata["LICENSE"], matchall=1, flat=True) |
130 |
+ |
131 |
+ # Check each entry to ensure that it exists in ${PORTDIR}/licenses/. |
132 |
+ for lic in licenses: |
133 |
+ # Need to check for "||" manually as no portage |
134 |
+ # function will remove it without removing values. |
135 |
+ if lic not in self.repo_metadata['liclist'] and lic != "||": |
136 |
+ self.qatracker.add_error("LICENSE.invalid", |
137 |
+ "%s/%s.ebuild: %s" % (xpkg, y_ebuild, lic)) |
138 |
+ elif lic in self.repo_metadata['lic_deprecated']: |
139 |
+ self.qatracker.add_error("LICENSE.deprecated", |
140 |
+ "%s: %s" % (ebuild.relative_path, lic)) |
141 |
+ return {'continue': False} |
142 |
+ |
143 |
+ @property |
144 |
+ def runInPkgs(self): |
145 |
+ return (False, []) |
146 |
+ |
147 |
+ @property |
148 |
+ def runInEbuilds(self): |
149 |
+ return (True, [self.check]) |
150 |
|
151 |
diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py |
152 |
index b330fe0..697724f 100644 |
153 |
--- a/pym/repoman/scanner.py |
154 |
+++ b/pym/repoman/scanner.py |
155 |
@@ -18,7 +18,6 @@ from portage import _unicode_encode |
156 |
from portage.dep import Atom |
157 |
from portage.output import green |
158 |
from repoman.checks.ebuilds.checks import run_checks |
159 |
-from repoman.checks.ebuilds.variables.license import LicenseChecks |
160 |
from repoman.checks.ebuilds.variables.restrict import RestrictChecks |
161 |
from repoman.modules.commit import repochecks |
162 |
from repoman.profile import check_profiles, dev_profile_keywords, setup_profile |
163 |
@@ -213,7 +212,6 @@ class Scanner(object): |
164 |
self.modules[mod_class.__name__] = mod_class(**self.kwargs) |
165 |
|
166 |
# initialize our checks classes here before the big xpkg loop |
167 |
- self.licensecheck = LicenseChecks(self.qatracker, liclist, liclist_deprecated) |
168 |
self.restrictcheck = RestrictChecks(self.qatracker) |
169 |
|
170 |
|
171 |
@@ -300,6 +298,7 @@ class Scanner(object): |
172 |
('description', 'DescriptionChecks'), (None, 'KeywordChecks'), |
173 |
('arches', 'ArchChecks'), ('depend', 'DependChecks'), |
174 |
('use_flags', 'USEFlagChecks'), ('ruby', 'RubyEclassChecks'), |
175 |
+ ('license', 'LicenseChecks'), |
176 |
]: |
177 |
if mod[0]: |
178 |
mod_class = MODULE_CONTROLLER.get_class(mod[0]) |
179 |
@@ -327,10 +326,6 @@ class Scanner(object): |
180 |
if y_ebuild_continue: |
181 |
continue |
182 |
|
183 |
- # license checks |
184 |
- if not dynamic_data['badlicsyntax']: |
185 |
- self.licensecheck.check(dynamic_data['pkg'], xpkg, dynamic_data['ebuild'], y_ebuild) |
186 |
- |
187 |
self.restrictcheck.check(dynamic_data['pkg'], xpkg, dynamic_data['ebuild'], y_ebuild) |
188 |
|
189 |
# Syntax Checks |