1 |
commit: fc8b6617dfc742e683af929de7ad6d8ab70d9dc6 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jun 2 05:31:45 2014 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Mon Jun 2 05:31:45 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=fc8b6617 |
7 |
|
8 |
repoman/main.py: Create FetchChecks class |
9 |
|
10 |
Create the new class in checks/ebuilds/fetches.py. |
11 |
|
12 |
--- |
13 |
pym/repoman/checks/ebuilds/fetches.py | 132 ++++++++++++++++++++++++++++++++++ |
14 |
pym/repoman/main.py | 96 ++----------------------- |
15 |
2 files changed, 139 insertions(+), 89 deletions(-) |
16 |
|
17 |
diff --git a/pym/repoman/checks/ebuilds/fetches.py b/pym/repoman/checks/ebuilds/fetches.py |
18 |
new file mode 100644 |
19 |
index 0000000..3d59339 |
20 |
--- /dev/null |
21 |
+++ b/pym/repoman/checks/ebuilds/fetches.py |
22 |
@@ -0,0 +1,132 @@ |
23 |
+ |
24 |
+'''fetches.py |
25 |
+Performs the src_uri fetchlist and files checks |
26 |
+''' |
27 |
+ |
28 |
+from stat import S_ISDIR |
29 |
+ |
30 |
+import portage |
31 |
+from portage import os |
32 |
+ |
33 |
+ |
34 |
+class FetchChecks(object): |
35 |
+ '''Performs checks on the files needed for the ebuild''' |
36 |
+ |
37 |
+ def __init__(self, qatracker, repoman_settings, repo_settings, portdb, |
38 |
+ vcs_settings, vcs_new_changed): |
39 |
+ ''' |
40 |
+ @param qatracker: QATracker instance |
41 |
+ @param repoman_settings: settings instance |
42 |
+ @param repo_settings: repository settings instance |
43 |
+ @param portdb: portdb instance |
44 |
+ ''' |
45 |
+ self.portdb = portdb |
46 |
+ self.qatracker = qatracker |
47 |
+ self.repo_settings = repo_settings |
48 |
+ self.repoman_settings = repoman_settings |
49 |
+ self.vcs_settings = vcs_settings |
50 |
+ self.vcs_new_changed = vcs_new_changed |
51 |
+ self._digests = None |
52 |
+ |
53 |
+ |
54 |
+ def check(self, xpkg, checkdir, checkdir_relative): |
55 |
+ '''Checks the ebuild sources and files for errors |
56 |
+ |
57 |
+ @param xpkg: the pacakge being checked |
58 |
+ @param checkdir: string, directory path |
59 |
+ @param checkdir_relative: repolevel determined path |
60 |
+ ''' |
61 |
+ self.checkdir = checkdir |
62 |
+ fetchlist_dict = portage.FetchlistDict(checkdir, self.repoman_settings, self.portdb) |
63 |
+ myfiles_all = [] |
64 |
+ self.src_uri_error = False |
65 |
+ for mykey in fetchlist_dict: |
66 |
+ try: |
67 |
+ myfiles_all.extend(fetchlist_dict[mykey]) |
68 |
+ except portage.exception.InvalidDependString as e: |
69 |
+ self.src_uri_error = True |
70 |
+ try: |
71 |
+ self.portdb.aux_get(mykey, ["SRC_URI"]) |
72 |
+ except KeyError: |
73 |
+ # This will be reported as an "ebuild.syntax" error. |
74 |
+ pass |
75 |
+ else: |
76 |
+ self.qatracker.add_error("SRC_URI.syntax", |
77 |
+ "%s.ebuild SRC_URI: %s" % (mykey, e)) |
78 |
+ del fetchlist_dict |
79 |
+ if not self.src_uri_error: |
80 |
+ # This test can produce false positives if SRC_URI could not |
81 |
+ # be parsed for one or more ebuilds. There's no point in |
82 |
+ # producing a false error here since the root cause will |
83 |
+ # produce a valid error elsewhere, such as "SRC_URI.syntax" |
84 |
+ # or "ebuild.sytax". |
85 |
+ myfiles_all = set(myfiles_all) |
86 |
+ for entry in self.digests: |
87 |
+ if entry not in myfiles_all: |
88 |
+ self.qatracker.add_error("digest.unused", checkdir + "::" + entry) |
89 |
+ for entry in myfiles_all: |
90 |
+ if entry not in self.digests: |
91 |
+ self.qatracker.add_error("digest.missing", checkdir + "::" + entry) |
92 |
+ del myfiles_all |
93 |
+ |
94 |
+ if os.path.exists(checkdir + "/files"): |
95 |
+ filesdirlist = os.listdir(checkdir + "/files") |
96 |
+ |
97 |
+ # Recurse through files directory, use filesdirlist as a stack; |
98 |
+ # appending directories as needed, |
99 |
+ # so people can't hide > 20k files in a subdirectory. |
100 |
+ while filesdirlist: |
101 |
+ y = filesdirlist.pop(0) |
102 |
+ relative_path = os.path.join(xpkg, "files", y) |
103 |
+ full_path = os.path.join(self.repo_settings.repodir, relative_path) |
104 |
+ try: |
105 |
+ mystat = os.stat(full_path) |
106 |
+ except OSError as oe: |
107 |
+ if oe.errno == 2: |
108 |
+ # don't worry about it. it likely was removed via fix above. |
109 |
+ continue |
110 |
+ else: |
111 |
+ raise oe |
112 |
+ if S_ISDIR(mystat.st_mode): |
113 |
+ # !!! VCS "portability" alert! Need some function isVcsDir() or alike !!! |
114 |
+ if y == "CVS" or y == ".svn": |
115 |
+ continue |
116 |
+ for z in os.listdir(checkdir + "/files/" + y): |
117 |
+ if z == "CVS" or z == ".svn": |
118 |
+ continue |
119 |
+ filesdirlist.append(y + "/" + z) |
120 |
+ # Current policy is no files over 20 KiB, these are the checks. |
121 |
+ # File size between 20 KiB and 60 KiB causes a warning, |
122 |
+ # while file size over 60 KiB causes an error. |
123 |
+ elif mystat.st_size > 61440: |
124 |
+ self.qatracker.add_error("file.size.fatal", |
125 |
+ "(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y)) |
126 |
+ elif mystat.st_size > 20480: |
127 |
+ self.qatracker.add_error("file.size", |
128 |
+ "(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y)) |
129 |
+ |
130 |
+ index = self.repo_settings.repo_config.find_invalid_path_char(y) |
131 |
+ if index != -1: |
132 |
+ y_relative = os.path.join(checkdir_relative, "files", y) |
133 |
+ if self.vcs_settings.vcs is not None and not self.vcs_new_changed(y_relative): |
134 |
+ # If the file isn't in the VCS new or changed set, then |
135 |
+ # assume that it's an irrelevant temporary file (Manifest |
136 |
+ # entries are not generated for file names containing |
137 |
+ # prohibited characters). See bug #406877. |
138 |
+ index = -1 |
139 |
+ if index != -1: |
140 |
+ self.qatracker.add_error("file.name", |
141 |
+ "%s/files/%s: char '%s'" % (checkdir, y, y[index])) |
142 |
+ |
143 |
+ |
144 |
+ @property |
145 |
+ def digests(self): |
146 |
+ '''Property function, returns the saved digests or |
147 |
+ loads them for the test''' |
148 |
+ if not self._digests: |
149 |
+ mf = self.repoman_settings.repositories.get_repo_for_location( |
150 |
+ os.path.dirname(os.path.dirname(self.checkdir))) |
151 |
+ mf = mf.load_manifest(self.checkdir, self.repoman_settings["DISTDIR"]) |
152 |
+ self._digests = mf.getTypeDigests("DIST") |
153 |
+ del mf |
154 |
+ return self._digests |
155 |
|
156 |
diff --git a/pym/repoman/main.py b/pym/repoman/main.py |
157 |
index d80cf59..ffb9929 100755 |
158 |
--- a/pym/repoman/main.py |
159 |
+++ b/pym/repoman/main.py |
160 |
@@ -16,7 +16,6 @@ import sys |
161 |
import tempfile |
162 |
import platform |
163 |
from itertools import chain |
164 |
-from stat import S_ISDIR |
165 |
|
166 |
from os import path as osp |
167 |
pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__)))) #, "pym") |
168 |
@@ -47,6 +46,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use |
169 |
|
170 |
from repoman.argparser import parse_args |
171 |
from repoman.checks.ebuilds.checks import run_checks, checks_init |
172 |
+from repoman.checks.ebuilds.fetches import FetchChecks |
173 |
from repoman.checks.ebuilds.isebuild import IsEbuild |
174 |
from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors |
175 |
from repoman.checks.ebuilds.manifests import Manifests |
176 |
@@ -369,93 +369,11 @@ for xpkg in effective_scanlist: |
177 |
status_check.check(check_ebuild_notadded) |
178 |
eadded.extend(status_check.eadded) |
179 |
############### |
180 |
- |
181 |
- mf = repoman_settings.repositories.get_repo_for_location( |
182 |
- os.path.dirname(os.path.dirname(checkdir))) |
183 |
- mf = mf.load_manifest(checkdir, repoman_settings["DISTDIR"]) |
184 |
- mydigests = mf.getTypeDigests("DIST") |
185 |
- |
186 |
- fetchlist_dict = portage.FetchlistDict(checkdir, repoman_settings, portdb) |
187 |
- myfiles_all = [] |
188 |
- src_uri_error = False |
189 |
- for mykey in fetchlist_dict: |
190 |
- try: |
191 |
- myfiles_all.extend(fetchlist_dict[mykey]) |
192 |
- except portage.exception.InvalidDependString as e: |
193 |
- src_uri_error = True |
194 |
- try: |
195 |
- portdb.aux_get(mykey, ["SRC_URI"]) |
196 |
- except KeyError: |
197 |
- # This will be reported as an "ebuild.syntax" error. |
198 |
- pass |
199 |
- else: |
200 |
- qatracker.add_error("SRC_URI.syntax", |
201 |
- "%s.ebuild SRC_URI: %s" % (mykey, e)) |
202 |
- del fetchlist_dict |
203 |
- if not src_uri_error: |
204 |
- # This test can produce false positives if SRC_URI could not |
205 |
- # be parsed for one or more ebuilds. There's no point in |
206 |
- # producing a false error here since the root cause will |
207 |
- # produce a valid error elsewhere, such as "SRC_URI.syntax" |
208 |
- # or "ebuild.sytax". |
209 |
- myfiles_all = set(myfiles_all) |
210 |
- for entry in mydigests: |
211 |
- if entry not in myfiles_all: |
212 |
- qatracker.add_error("digest.unused", checkdir + "::" + entry) |
213 |
- for entry in myfiles_all: |
214 |
- if entry not in mydigests: |
215 |
- qatracker.add_error("digest.missing", checkdir + "::" + entry) |
216 |
- del myfiles_all |
217 |
- |
218 |
- if os.path.exists(checkdir + "/files"): |
219 |
- filesdirlist = os.listdir(checkdir + "/files") |
220 |
- |
221 |
- # Recurse through files directory, use filesdirlist as a stack; |
222 |
- # appending directories as needed, |
223 |
- # so people can't hide > 20k files in a subdirectory. |
224 |
- while filesdirlist: |
225 |
- y = filesdirlist.pop(0) |
226 |
- relative_path = os.path.join(xpkg, "files", y) |
227 |
- full_path = os.path.join(repo_settings.repodir, relative_path) |
228 |
- try: |
229 |
- mystat = os.stat(full_path) |
230 |
- except OSError as oe: |
231 |
- if oe.errno == 2: |
232 |
- # don't worry about it. it likely was removed via fix above. |
233 |
- continue |
234 |
- else: |
235 |
- raise oe |
236 |
- if S_ISDIR(mystat.st_mode): |
237 |
- # !!! VCS "portability" alert! Need some function isVcsDir() or alike !!! |
238 |
- if y == "CVS" or y == ".svn": |
239 |
- continue |
240 |
- for z in os.listdir(checkdir + "/files/" + y): |
241 |
- if z == "CVS" or z == ".svn": |
242 |
- continue |
243 |
- filesdirlist.append(y + "/" + z) |
244 |
- # Current policy is no files over 20 KiB, these are the checks. |
245 |
- # File size between 20 KiB and 60 KiB causes a warning, |
246 |
- # while file size over 60 KiB causes an error. |
247 |
- elif mystat.st_size > 61440: |
248 |
- qatracker.add_error("file.size.fatal", |
249 |
- "(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y)) |
250 |
- elif mystat.st_size > 20480: |
251 |
- qatracker.add_error("file.size", |
252 |
- "(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y)) |
253 |
- |
254 |
- index = repo_settings.repo_config.find_invalid_path_char(y) |
255 |
- if index != -1: |
256 |
- y_relative = os.path.join(checkdir_relative, "files", y) |
257 |
- if vcs_settings.vcs is not None and not vcs_new_changed(y_relative): |
258 |
- # If the file isn't in the VCS new or changed set, then |
259 |
- # assume that it's an irrelevant temporary file (Manifest |
260 |
- # entries are not generated for file names containing |
261 |
- # prohibited characters). See bug #406877. |
262 |
- index = -1 |
263 |
- if index != -1: |
264 |
- qatracker.add_error("file.name", |
265 |
- "%s/files/%s: char '%s'" % (checkdir, y, y[index])) |
266 |
- del mydigests |
267 |
+################# |
268 |
+ fetchcheck = FetchChecks(qatracker, repoman_settings, repo_settings, portdb, |
269 |
+ vcs_settings, vcs_new_changed) |
270 |
+ fetchcheck.check(xpkg, checkdir, checkdir_relative) |
271 |
+################# |
272 |
|
273 |
if check_changelog and "ChangeLog" not in checkdirlist: |
274 |
qatracker.add_error("changelog.missing", xpkg + "/ChangeLog") |
275 |
@@ -535,7 +453,7 @@ for xpkg in effective_scanlist: |
276 |
"character at position %s" % |
277 |
(ebuild.relative_path, k, m.start() + 1)) |
278 |
|
279 |
- if not src_uri_error: |
280 |
+ if not fetchcheck.src_uri_error: |
281 |
####################### |
282 |
thirdparty = ThirdPartyMirrors(repoman_settings, qatracker) |
283 |
thirdparty.check(myaux, ebuild.relative_path) |