1 |
On Wed, Feb 19, 2014 at 3:20 PM, Brian Dolbec <dolsen@g.o> wrote: |
2 |
|
3 |
> On Wed, 19 Feb 2014 14:32:02 -0800 |
4 |
> Alec Warner <antarus@g.o> wrote: |
5 |
> |
6 |
> > On Wed, Feb 19, 2014 at 12:31 PM, Pavel Kazakov <nullishzero@g.o |
7 |
> >wrote: |
8 |
> > |
9 |
> > > --- |
10 |
> > > pym/portage/emaint/modules/merges/__init__.py | 20 ++++++++ |
11 |
> > > pym/portage/emaint/modules/merges/merges.py | 70 |
12 |
> > > +++++++++++++++++++++++++++ |
13 |
> > > 2 files changed, 90 insertions(+) |
14 |
> > > create mode 100644 pym/portage/emaint/modules/merges/__init__.py |
15 |
> > > create mode 100644 pym/portage/emaint/modules/merges/merges.py |
16 |
> > > |
17 |
> > > diff --git a/pym/portage/emaint/modules/merges/__init__.py |
18 |
> > > b/pym/portage/emaint/modules/merges/__init__.py |
19 |
> > > new file mode 100644 |
20 |
> > > index 0000000..2cd79af |
21 |
> > > --- /dev/null |
22 |
> > > +++ b/pym/portage/emaint/modules/merges/__init__.py |
23 |
> > > @@ -0,0 +1,20 @@ |
24 |
> > > +# Copyright 2005-2014 Gentoo Foundation |
25 |
> > > +# Distributed under the terms of the GNU General Public License v2 |
26 |
> > > + |
27 |
> > > +"""Scan for failed merges and fix them. |
28 |
> > > +""" |
29 |
> > > |
30 |
> > |
31 |
> Correct ^^ |
32 |
> |
33 |
> > """Scan for failed merges fix them.""" |
34 |
> |
35 |
> No, your grammar is wrong |
36 |
> |
37 |
|
38 |
I didn't mean grammar, I meant. |
39 |
|
40 |
"""foo.""" |
41 |
|
42 |
not |
43 |
|
44 |
"""foo. |
45 |
""" |
46 |
|
47 |
|
48 |
> |
49 |
> > |
50 |
> > |
51 |
> > > + |
52 |
> > > + |
53 |
> > > +module_spec = { |
54 |
> > > + 'name': 'merges', |
55 |
> > > + 'description': __doc__, |
56 |
> > > + 'provides':{ |
57 |
> > > |
58 |
> > |
59 |
> > 'module1' ? |
60 |
> > |
61 |
> |
62 |
> It is just an identifier, not used other than to group together |
63 |
> everything for that module. The plugin system can handle multiple |
64 |
> sub-modules within the same general module directory. See the |
65 |
> emaint/modules/move/__init__.py. Move supplies 2 submodules. |
66 |
> |
67 |
> The new websync sync module (emerge-webrsync replacement) we started |
68 |
> roughing in also has 2 sub-modules, the 1st will be the module that |
69 |
> runs the original bash script. |
70 |
> The 2nd will be the new python converted code to replace it. |
71 |
> |
72 |
> > |
73 |
> > > + 'module1': { |
74 |
> > > + 'name': "merges", |
75 |
> > > + 'class': "MergesHandler", |
76 |
> > > + 'description': __doc__, |
77 |
> > > + 'functions': ['check', 'fix',], |
78 |
> > > + 'func_desc': {} |
79 |
> > > + } |
80 |
> > > + } |
81 |
> > > + } |
82 |
> > > diff --git a/pym/portage/emaint/modules/merges/merges.py |
83 |
> > > b/pym/portage/emaint/modules/merges/merges.py |
84 |
> > > new file mode 100644 |
85 |
> > > index 0000000..b243082 |
86 |
> > > --- /dev/null |
87 |
> > > +++ b/pym/portage/emaint/modules/merges/merges.py |
88 |
> > > @@ -0,0 +1,70 @@ |
89 |
> > > +# Copyright 2005-2014 Gentoo Foundation |
90 |
> > > +# Distributed under the terms of the GNU General Public License v2 |
91 |
> > > + |
92 |
> > > +import portage |
93 |
> > > +from portage import os |
94 |
> > > +from portage.const import PRIVATE_PATH, VDB_PATH |
95 |
> > > +from portage.util import writemsg |
96 |
> > > + |
97 |
> > > +import shutil |
98 |
> > > +import sys |
99 |
> > > + |
100 |
> > > +if sys.hexversion >= 0x3000000: |
101 |
> > > + # pylint: disable=W0622 |
102 |
> > > + long = int |
103 |
> > > |
104 |
> > |
105 |
> > What is this little guy? Can we just do this in a library someplace? |
106 |
> > |
107 |
> > |
108 |
> > > + |
109 |
> > > +class MergesHandler(object): |
110 |
> > > + |
111 |
> > > + short_desc = "Remove failed merges" |
112 |
> > > + |
113 |
> > > |
114 |
> > |
115 |
> > @staticmethod decorator? |
116 |
> |
117 |
> Yeah, that is copying legacy emaint code from the original module |
118 |
> classes. |
119 |
> |
120 |
> |
121 |
> > |
122 |
> > > + def name(): |
123 |
> > > + return "merges" |
124 |
> > > + name = staticmethod(name) |
125 |
> > > + |
126 |
> > > + def __init__(self): |
127 |
> > > |
128 |
> > |
129 |
> > Generally you want to be able to change these later, so you might do |
130 |
> > something like: |
131 |
> > |
132 |
> > def __init__(self, eroot=None, vardb=None, vardb_path=None): |
133 |
> > self._eroot = error or portage.settings['EROOT'] |
134 |
> > ... and so forth. |
135 |
> > |
136 |
> |
137 |
> The emaint code was not setup to handle init variable assignments. |
138 |
> None of the original module classes used any. The plugin system |
139 |
> doesn't care. But the TaskHandler class in main.py would need to be |
140 |
> modified. Also, all modules must use the same method of initializing, |
141 |
> regardless whether they need it or not. In the new sync modules all |
142 |
> relevant data is passed in using kwargs, then it saves any info it |
143 |
> needs. |
144 |
> |
145 |
|
146 |
So use kwargs here? |
147 |
|
148 |
|
149 |
> |
150 |
> > Also..why can't self._vardb_path be queried from the vardb? |
151 |
> > |
152 |
> > |
153 |
> > > + self._eroot = portage.settings['EROOT'] |
154 |
> > > + self._vardb = portage.db[self._eroot]["vartree"].dbapi |
155 |
> > > + self._vardb_path = os.path.join(self._eroot, VDB_PATH) |
156 |
> + |
157 |
> > > os.path.sep |
158 |
> > > + |
159 |
> > > + def can_progressbar(self, func): |
160 |
> > > + return True |
161 |
> > > + |
162 |
> > > + def _failed_packages(self, onProgress): |
163 |
> > > + for cat in os.listdir(self._vardb_path): |
164 |
> > > |
165 |
> > os.listdir(os.path.join(...)) ? |
166 |
> > |
167 |
> > > + pkgs = os.listdir(self._vardb_path + cat) |
168 |
> > > + maxval = len(pkgs) |
169 |
> > > + for i, pkg in enumerate(pkgs): |
170 |
> > > + if onProgress: |
171 |
> > > + onProgress(maxval, i+1) |
172 |
> > > + |
173 |
> > > + if '-MERGING-' in pkg: |
174 |
> > > + yield cat + os.path.sep + pkg |
175 |
> |
176 |
|
177 |
os.path.join here as well. |
178 |
|
179 |
|
180 |
> > > + |
181 |
> > > + def check(self, **kwargs): |
182 |
> > > + onProgress = kwargs.get('onProgress', None) |
183 |
> > > + failed_pkgs = [] |
184 |
> > > + for pkg in self._failed_packages(onProgress): |
185 |
> > > + failed_pkgs.append(pkg) |
186 |
> |
187 |
|
188 |
I think we want a set() here, not a list. |
189 |
|
190 |
|
191 |
> > > + |
192 |
> > > + errors = ["'%s' failed to merge." % x for x in |
193 |
> failed_pkgs] |
194 |
> > > + return errors |
195 |
> > > + |
196 |
> > > + def fix(self, **kwargs): |
197 |
> > > + onProgress = kwargs.get('onProgress', None) |
198 |
> > > + tracking_path = os.path.join(self._eroot, PRIVATE_PATH, |
199 |
> > > 'failed-merges'); |
200 |
> > > + try: |
201 |
> > > + with open(tracking_path, 'w') as tracking_file: |
202 |
> > > |
203 |
> > |
204 |
> > is this unicode safe? |
205 |
> |
206 |
> you can turn on the unicode option. |
207 |
> |
208 |
> > |
209 |
> > |
210 |
> > > + for failed_pkg in |
211 |
> > > self._failed_packages(onProgress): |
212 |
> > > + |
213 |
> > > tracking_file.write(failed_pkg + '\n') |
214 |
> > > + pkg_path = |
215 |
> > > self._vardb_path + failed_pkg |
216 |
> > > |
217 |
> > |
218 |
> > os.path.join(...) |
219 |
> > |
220 |
> > |
221 |
> > > + # Delete failed merge |
222 |
> > > directory |
223 |
> > > + # XXX: Would be a good |
224 |
> > > idea to attempt try removing |
225 |
> > > + # package contents to |
226 |
> > > prevent orphaned files |
227 |
> > > |
228 |
> > |
229 |
> > # XXX is terrible style. I realize a bunch of code does that, and it is |
230 |
> > stupid. |
231 |
> > # use |
232 |
> > # TODO: foo |
233 |
> > |
234 |
> > |
235 |
> > |
236 |
> > |
237 |
> > > + shutil.rmtree(pkg_path) |
238 |
> > > + # Re-emerge package |
239 |
> > > |
240 |
> > + pkg_name = '=' + |
241 |
> > > failed_pkg.replace('-MERGING-', '') |
242 |
> > > + |
243 |
> > > features='FEATURES="-collision-detect -protect-owned"' |
244 |
> > > + emerge_cmd="emerge |
245 |
> > > --verbose --oneshot --complete-graph=y" |
246 |
> > > + os.system('%s %s %s' % |
247 |
> > > (features, emerge_cmd, pkg_name)) |
248 |
> > > |
249 |
> > |
250 |
> > This is a security vulnerability :) |
251 |
> > |
252 |
> > -A |
253 |
> > |
254 |
> |
255 |
> Yeah, but it is the only way to actually fix a failed merge. You must |
256 |
> turn off collision protect so it can overwrite the stray files from |
257 |
> the previously failed merge. There often is not a valid CONTENTS file. |
258 |
> Plus it may not be accurate as to the files actually merged. This |
259 |
> module is for fixing pkgs that fail during the merge phase to the live |
260 |
> filesystem. |
261 |
> |
262 |
|
263 |
Thats not what I meant ;) |
264 |
|
265 |
|
266 |
> |
267 |
> |
268 |
> |
269 |
> |
270 |
> -- |
271 |
> Brian Dolbec <dolsen> |
272 |
> |
273 |
> |
274 |
> |