summaryrefslogtreecommitdiffstats
path: root/subcmds
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds')
-rw-r--r--subcmds/forall.py27
-rw-r--r--subcmds/init.py4
2 files changed, 24 insertions, 7 deletions
diff --git a/subcmds/forall.py b/subcmds/forall.py
index 88b23fbd..ebc8beca 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -20,6 +20,7 @@ import multiprocessing
20import re 20import re
21import os 21import os
22import select 22import select
23import signal
23import sys 24import sys
24import subprocess 25import subprocess
25 26
@@ -207,14 +208,12 @@ without iterating through the remaining projects.
207 208
208 os.environ['REPO_COUNT'] = str(len(projects)) 209 os.environ['REPO_COUNT'] = str(len(projects))
209 210
210 pool = multiprocessing.Pool(opt.jobs) 211 pool = multiprocessing.Pool(opt.jobs, InitWorker)
211 try: 212 try:
212 config = self.manifest.manifestProject.config 213 config = self.manifest.manifestProject.config
213 results_it = pool.imap( 214 results_it = pool.imap(
214 DoWorkWrapper, 215 DoWorkWrapper,
215 ([mirror, opt, cmd, shell, cnt, config, self._SerializeProject(p)] 216 self.ProjectArgs(projects, mirror, opt, cmd, shell, config))
216 for cnt, p in enumerate(projects))
217 )
218 pool.close() 217 pool.close()
219 for r in results_it: 218 for r in results_it:
220 rc = rc or r 219 rc = rc or r
@@ -236,12 +235,28 @@ without iterating through the remaining projects.
236 if rc != 0: 235 if rc != 0:
237 sys.exit(rc) 236 sys.exit(rc)
238 237
238 def ProjectArgs(self, projects, mirror, opt, cmd, shell, config):
239 for cnt, p in enumerate(projects):
240 try:
241 project = self._SerializeProject(p)
242 except Exception as e:
243 print('Project list error: %r' % e,
244 file=sys.stderr)
245 return
246 except KeyboardInterrupt:
247 print('Project list interrupted',
248 file=sys.stderr)
249 return
250 yield [mirror, opt, cmd, shell, cnt, config, project]
239 251
240class WorkerKeyboardInterrupt(Exception): 252class WorkerKeyboardInterrupt(Exception):
241 """ Keyboard interrupt exception for worker processes. """ 253 """ Keyboard interrupt exception for worker processes. """
242 pass 254 pass
243 255
244 256
257def InitWorker():
258 signal.signal(signal.SIGINT, signal.SIG_IGN)
259
245def DoWorkWrapper(args): 260def DoWorkWrapper(args):
246 """ A wrapper around the DoWork() method. 261 """ A wrapper around the DoWork() method.
247 262
@@ -263,7 +278,9 @@ def DoWork(project, mirror, opt, cmd, shell, cnt, config):
263 def setenv(name, val): 278 def setenv(name, val):
264 if val is None: 279 if val is None:
265 val = '' 280 val = ''
266 env[name] = val.encode() 281 if hasattr(val, 'encode'):
282 val = val.encode()
283 env[name] = val
267 284
268 setenv('REPO_PROJECT', project['name']) 285 setenv('REPO_PROJECT', project['name'])
269 setenv('REPO_PATH', project['relpath']) 286 setenv('REPO_PATH', project['relpath'])
diff --git a/subcmds/init.py b/subcmds/init.py
index b73de71c..dbb6ddda 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -27,7 +27,7 @@ else:
27 import imp 27 import imp
28 import urlparse 28 import urlparse
29 urllib = imp.new_module('urllib') 29 urllib = imp.new_module('urllib')
30 urllib.parse = urlparse.urlparse 30 urllib.parse = urlparse
31 31
32from color import Coloring 32from color import Coloring
33from command import InteractiveCommand, MirrorSafeCommand 33from command import InteractiveCommand, MirrorSafeCommand
@@ -153,7 +153,7 @@ to update the working directory files.
153 # server where this git is located, so let's save that here. 153 # server where this git is located, so let's save that here.
154 mirrored_manifest_git = None 154 mirrored_manifest_git = None
155 if opt.reference: 155 if opt.reference:
156 manifest_git_path = urllib.parse(opt.manifest_url).path[1:] 156 manifest_git_path = urllib.parse.urlparse(opt.manifest_url).path[1:]
157 mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path) 157 mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path)
158 if not mirrored_manifest_git.endswith(".git"): 158 if not mirrored_manifest_git.endswith(".git"):
159 mirrored_manifest_git += ".git" 159 mirrored_manifest_git += ".git"