diff options
Diffstat (limited to 'subcmds/forall.py')
-rw-r--r-- | subcmds/forall.py | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py index 88b23fbd..b93cd6d0 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
@@ -20,6 +20,7 @@ import multiprocessing | |||
20 | import re | 20 | import re |
21 | import os | 21 | import os |
22 | import select | 22 | import select |
23 | import signal | ||
23 | import sys | 24 | import sys |
24 | import subprocess | 25 | import subprocess |
25 | 26 | ||
@@ -150,11 +151,15 @@ without iterating through the remaining projects. | |||
150 | attributes that we need. | 151 | attributes that we need. |
151 | 152 | ||
152 | """ | 153 | """ |
154 | if not self.manifest.IsMirror: | ||
155 | lrev = project.GetRevisionId() | ||
156 | else: | ||
157 | lrev = None | ||
153 | return { | 158 | return { |
154 | 'name': project.name, | 159 | 'name': project.name, |
155 | 'relpath': project.relpath, | 160 | 'relpath': project.relpath, |
156 | 'remote_name': project.remote.name, | 161 | 'remote_name': project.remote.name, |
157 | 'lrev': project.GetRevisionId(), | 162 | 'lrev': lrev, |
158 | 'rrev': project.revisionExpr, | 163 | 'rrev': project.revisionExpr, |
159 | 'annotations': dict((a.name, a.value) for a in project.annotations), | 164 | 'annotations': dict((a.name, a.value) for a in project.annotations), |
160 | 'gitdir': project.gitdir, | 165 | 'gitdir': project.gitdir, |
@@ -200,6 +205,13 @@ without iterating through the remaining projects. | |||
200 | mirror = self.manifest.IsMirror | 205 | mirror = self.manifest.IsMirror |
201 | rc = 0 | 206 | rc = 0 |
202 | 207 | ||
208 | smart_sync_manifest_name = "smart_sync_override.xml" | ||
209 | smart_sync_manifest_path = os.path.join( | ||
210 | self.manifest.manifestProject.worktree, smart_sync_manifest_name) | ||
211 | |||
212 | if os.path.isfile(smart_sync_manifest_path): | ||
213 | self.manifest.Override(smart_sync_manifest_path) | ||
214 | |||
203 | if not opt.regex: | 215 | if not opt.regex: |
204 | projects = self.GetProjects(args) | 216 | projects = self.GetProjects(args) |
205 | else: | 217 | else: |
@@ -207,14 +219,12 @@ without iterating through the remaining projects. | |||
207 | 219 | ||
208 | os.environ['REPO_COUNT'] = str(len(projects)) | 220 | os.environ['REPO_COUNT'] = str(len(projects)) |
209 | 221 | ||
210 | pool = multiprocessing.Pool(opt.jobs) | 222 | pool = multiprocessing.Pool(opt.jobs, InitWorker) |
211 | try: | 223 | try: |
212 | config = self.manifest.manifestProject.config | 224 | config = self.manifest.manifestProject.config |
213 | results_it = pool.imap( | 225 | results_it = pool.imap( |
214 | DoWorkWrapper, | 226 | DoWorkWrapper, |
215 | ([mirror, opt, cmd, shell, cnt, config, self._SerializeProject(p)] | 227 | self.ProjectArgs(projects, mirror, opt, cmd, shell, config)) |
216 | for cnt, p in enumerate(projects)) | ||
217 | ) | ||
218 | pool.close() | 228 | pool.close() |
219 | for r in results_it: | 229 | for r in results_it: |
220 | rc = rc or r | 230 | rc = rc or r |
@@ -236,12 +246,28 @@ without iterating through the remaining projects. | |||
236 | if rc != 0: | 246 | if rc != 0: |
237 | sys.exit(rc) | 247 | sys.exit(rc) |
238 | 248 | ||
249 | def ProjectArgs(self, projects, mirror, opt, cmd, shell, config): | ||
250 | for cnt, p in enumerate(projects): | ||
251 | try: | ||
252 | project = self._SerializeProject(p) | ||
253 | except Exception as e: | ||
254 | print('Project list error: %r' % e, | ||
255 | file=sys.stderr) | ||
256 | return | ||
257 | except KeyboardInterrupt: | ||
258 | print('Project list interrupted', | ||
259 | file=sys.stderr) | ||
260 | return | ||
261 | yield [mirror, opt, cmd, shell, cnt, config, project] | ||
239 | 262 | ||
240 | class WorkerKeyboardInterrupt(Exception): | 263 | class WorkerKeyboardInterrupt(Exception): |
241 | """ Keyboard interrupt exception for worker processes. """ | 264 | """ Keyboard interrupt exception for worker processes. """ |
242 | pass | 265 | pass |
243 | 266 | ||
244 | 267 | ||
268 | def InitWorker(): | ||
269 | signal.signal(signal.SIGINT, signal.SIG_IGN) | ||
270 | |||
245 | def DoWorkWrapper(args): | 271 | def DoWorkWrapper(args): |
246 | """ A wrapper around the DoWork() method. | 272 | """ A wrapper around the DoWork() method. |
247 | 273 | ||
@@ -263,7 +289,9 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config): | |||
263 | def setenv(name, val): | 289 | def setenv(name, val): |
264 | if val is None: | 290 | if val is None: |
265 | val = '' | 291 | val = '' |
266 | env[name] = val.encode() | 292 | if hasattr(val, 'encode'): |
293 | val = val.encode() | ||
294 | env[name] = val | ||
267 | 295 | ||
268 | setenv('REPO_PROJECT', project['name']) | 296 | setenv('REPO_PROJECT', project['name']) |
269 | setenv('REPO_PATH', project['relpath']) | 297 | setenv('REPO_PATH', project['relpath']) |