1 |
commit: 750404bb3e8ab5bccdf9d653e8587610fd034e89 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue May 27 07:13:32 2014 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Tue May 27 07:13:32 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=750404bb |
7 |
|
8 |
repoman/main.py: Break out a new ebuild check, ThirdPartyMirrors |
9 |
|
10 |
Consolodate the code from 2 locations into one class. |
11 |
|
12 |
--- |
13 |
pym/repoman/checks/ebuilds/thirdpartymirrors.py | 40 +++++++++++++++++++++++++ |
14 |
pym/repoman/main.py | 32 +++++--------------- |
15 |
2 files changed, 47 insertions(+), 25 deletions(-) |
16 |
|
17 |
diff --git a/pym/repoman/checks/ebuilds/thirdpartymirrors.py b/pym/repoman/checks/ebuilds/thirdpartymirrors.py |
18 |
new file mode 100644 |
19 |
index 0000000..976a62c |
20 |
--- /dev/null |
21 |
+++ b/pym/repoman/checks/ebuilds/thirdpartymirrors.py |
22 |
@@ -0,0 +1,40 @@ |
23 |
+ |
24 |
+import portage |
25 |
+ |
26 |
+ |
27 |
+class ThirdPartyMirrors(object): |
28 |
+ |
29 |
+ def __init__(self, repoman_settings): |
30 |
+ # Build a regex from thirdpartymirrors for the SRC_URI.mirror check. |
31 |
+ self.thirdpartymirrors = {} |
32 |
+ for k, v in repoman_settings.thirdpartymirrors().items(): |
33 |
+ for v in v: |
34 |
+ if not v.endswith("/"): |
35 |
+ v += "/" |
36 |
+ self.thirdpartymirrors[v] = k |
37 |
+ self.stats = 0 |
38 |
+ self.fails = [] |
39 |
+ |
40 |
+ |
41 |
+ def check(self, myaux, relative_path): |
42 |
+ # reset our stats in case this is a repeat run |
43 |
+ self.stats = 0 |
44 |
+ self.fails = [] |
45 |
+ # Check that URIs don't reference a server from thirdpartymirrors. |
46 |
+ for uri in portage.dep.use_reduce( |
47 |
+ myaux["SRC_URI"], matchall=True, is_src_uri=True, |
48 |
+ eapi=myaux["EAPI"], flat=True): |
49 |
+ contains_mirror = False |
50 |
+ for mirror, mirror_alias in self.thirdpartymirrors.items(): |
51 |
+ if uri.startswith(mirror): |
52 |
+ contains_mirror = True |
53 |
+ break |
54 |
+ if not contains_mirror: |
55 |
+ continue |
56 |
+ |
57 |
+ new_uri = "mirror://%s/%s" % (mirror_alias, uri[len(mirror):]) |
58 |
+ self.stats += 1 |
59 |
+ self.fails.append( |
60 |
+ "%s: '%s' found in thirdpartymirrors, use '%s'" % |
61 |
+ (relative_path, mirror, new_uri)) |
62 |
+ return |
63 |
|
64 |
diff --git a/pym/repoman/main.py b/pym/repoman/main.py |
65 |
index 49ad79d..158323e 100755 |
66 |
--- a/pym/repoman/main.py |
67 |
+++ b/pym/repoman/main.py |
68 |
@@ -65,6 +65,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use |
69 |
|
70 |
from repoman.argparser import parse_args |
71 |
from repoman.checks.ebuilds.checks import run_checks, checks_init |
72 |
+from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors |
73 |
from repoman.checks.herds.herdbase import make_herd_base |
74 |
from repoman.errors import err |
75 |
from repoman.metadata import (metadata_xml_encoding, metadata_doctype_name, |
76 |
@@ -303,14 +304,6 @@ if options.include_arches: |
77 |
check_ebuild_notadded = not \ |
78 |
(vcs_settings.vcs == "svn" and repolevel < 3 and options.mode != "commit") |
79 |
|
80 |
-# Build a regex from thirdpartymirrors for the SRC_URI.mirror check. |
81 |
-thirdpartymirrors = {} |
82 |
-for k, v in repoman_settings.thirdpartymirrors().items(): |
83 |
- for v in v: |
84 |
- if not v.endswith("/"): |
85 |
- v += "/" |
86 |
- thirdpartymirrors[v] = k |
87 |
- |
88 |
try: |
89 |
herd_base = make_herd_base( |
90 |
os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml")) |
91 |
@@ -887,23 +880,12 @@ for x in effective_scanlist: |
92 |
(relative_path, k, m.start() + 1)) |
93 |
|
94 |
if not src_uri_error: |
95 |
- # Check that URIs don't reference a server from thirdpartymirrors. |
96 |
- for uri in portage.dep.use_reduce( |
97 |
- myaux["SRC_URI"], matchall=True, is_src_uri=True, eapi=eapi, flat=True): |
98 |
- contains_mirror = False |
99 |
- for mirror, mirror_alias in thirdpartymirrors.items(): |
100 |
- if uri.startswith(mirror): |
101 |
- contains_mirror = True |
102 |
- break |
103 |
- if not contains_mirror: |
104 |
- continue |
105 |
- |
106 |
- new_uri = "mirror://%s/%s" % (mirror_alias, uri[len(mirror):]) |
107 |
- stats["SRC_URI.mirror"] += 1 |
108 |
- fails["SRC_URI.mirror"].append( |
109 |
- "%s: '%s' found in thirdpartymirrors, use '%s'" % |
110 |
- (relative_path, mirror, new_uri)) |
111 |
- |
112 |
+ ####################### |
113 |
+ thirdparty = ThirdPartyMirrors(repoman_settings) |
114 |
+ thirdparty.check(myaux, relative_path) |
115 |
+ stats["SRC_URI.mirror"] = thirdparty.stats |
116 |
+ fails["SRC_URI.mirror"] = thirdparty.fails |
117 |
+ ####################### |
118 |
if myaux.get("PROVIDE"): |
119 |
stats["virtual.oldstyle"] += 1 |
120 |
fails["virtual.oldstyle"].append(relative_path) |