View | Details | Raw Unified | Return to bug 33255 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-join/umc/python/join/__init__.py (-11 / +31 lines)
 Lines 40-45    Link Here 
40
import re
40
import re
41
import dns.resolver
41
import dns.resolver
42
import dns.exception
42
import dns.exception
43
import fcntl
44
import errno
43
45
44
import notifier.threads
46
import notifier.threads
45
import apt_pkg
47
import apt_pkg
 Lines 197-209   def run(cmd, stepsPerScript, info_handler = _dummyFunc, error_handler = _dummyFu Link Here 
197
		process = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
199
		process = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
198
200
199
		failedJoinScripts = []
201
		failedJoinScripts = []
200
		while True:
202
		def parse(line):
201
			# get the next line
203
			MODULE.process(repr(line.strip()).strip('"\''))
202
			line = process.stdout.readline()
203
			if not line:
204
				# no more text from stdout
205
				break
206
			MODULE.process(line.strip())
207
204
208
			# parse output... first check for errors
205
			# parse output... first check for errors
209
			m = regError.match(line)
206
			m = regError.match(line)
 Lines 214-221   def run(cmd, stepsPerScript, info_handler = _dummyFunc, error_handler = _dummyFu Link Here 
214
					# invalid credentials or non existent user
211
					# invalid credentials or non existent user
215
					# do a critical error, the script will stop here
212
					# do a critical error, the script will stop here
216
					critical_handler(True)
213
					critical_handler(True)
217
214
				return
218
				continue
219
215
220
			# check for currently called join script
216
			# check for currently called join script
221
			m = regJoinScript.match(line)
217
			m = regJoinScript.match(line)
 Lines 225-238   def run(cmd, stepsPerScript, info_handler = _dummyFunc, error_handler = _dummyFu Link Here 
225
				step_handler(stepsPerScript)
221
				step_handler(stepsPerScript)
226
				if 'failed' in line:
222
				if 'failed' in line:
227
					failedJoinScripts.append(m.groupdict().get('script'))
223
					failedJoinScripts.append(m.groupdict().get('script'))
228
				continue
224
				return
229
225
230
			# check for other information
226
			# check for other information
231
			m = regInfo.match(line)
227
			m = regInfo.match(line)
232
			if m:
228
			if m:
233
				info_handler(m.groupdict().get('message'))
229
				info_handler(m.groupdict().get('message'))
234
				step_handler(stepsPerScript/10)
230
				step_handler(stepsPerScript/10)
235
				continue
231
				return
232
233
		# make stdout file descriptor of the process non-blocking
234
		fd = process.stdout.fileno()
235
		fl = fcntl.fcntl(fd, fcntl.F_GETFL)
236
		fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
237
238
		unfinished_line = ''
239
		while True:
240
			# get the next line
241
			try:
242
				line = process.stdout.read()
243
			except IOError as exc:
244
				if exc.errno == errno.EAGAIN:
245
					continue
246
				raise
247
248
			if not line:
249
				break # no more text from stdout
250
251
			unfinished_line = '' if line.endswith('\n') else '%s%s' % (unfinished_line, line.rsplit('\n', 1)[-1])
252
			for line in line.splitlines():
253
				parse(line)
254
			if unfinished_line:
255
				parse(unfinished_line)
236
256
237
		# get all remaining output
257
		# get all remaining output
238
		stdout, stderr = process.communicate()
258
		stdout, stderr = process.communicate()

Return to bug 33255