-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuilder.py
858 lines (720 loc) · 33.3 KB
/
builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
#coding: utf-8
#
##
# Class builder - queues commands to execute and performs them
#
import copy
import curses
import curses.wrapper
import os
import shutil
import subprocess
import sys
import tempfile
import threading
import time
from config import Configuration
from config import MachineItem
from project import *
##
# Buildhost class - oversees the build process for a particular host
#
class BuildHost(threading.Thread):
##
# Ctor
# \param[in] Key to machines hash (to uniquely identify this host entry)
# \param[in] Configuration class (for pbuild configuration)
def __init__(self, machineKey, config):
threading.Thread.__init__(self)
self.display_line = 0
self.finished = False
self.config = config
self.tag = config.machines[machineKey].GetTag()
self.hostname = config.machines[machineKey].GetHost()
self.path = config.machines[machineKey].GetPath()
self.project = config.machines[machineKey].GetProject()
self.logPrefix = config.GetLogfilePrefix()
self.deleteLogfiles = config.GetSetting('DeleteLogfiles')
self.diagnoseErrors = config.GetSetting('DiagnoseErrors')
self.renameLogfiles = config.GetSetting('LogfileRename')
self.showProgress = config.GetSetting('Progress')
# Construct the generic project definitions
factory = ProjectFactory(self.project)
assert factory.Validate()
self.projectDefs = factory.Create()
# And build the queue of commands to run for the project
self.queue = []
self.BuildQueue(self.queue)
# Initialize variables for status handling
#
# Flag meaning:
# bLogActivity: Set to True whenever activity to the log has occurred
# cLogSubLines: Total number of lines written in this section
# sActivityText: Text showing current activity of subprocess
# cActivityTime: Time of last update (maintained by display code)
self.bLogActivity = True
self.cLogSubLines = 0
self.sActivityText = 'starting up'
self.tActivityTime = 0
# Support for setting 'LogfileSelect'
#
# If 'LogfileSelect' is specified, then logfiles are named with the
# selector name (if a selector name is known). This will allow several
# instances of pbuild to be run concurrently against independent
# selectors by not conflicting in the log file naming conventions.
self.selectSpec = ''
if config.GetSetting('LogfileSelect'):
self.selectSpec = '-None'
# If we have a selector specification, use it
if config.GetSelectSpecification() != '':
self.selectSpec = '-%s' % config.GetSelectSpecification()
##
# Build queue of operations to initialize the environment on destination
#
def BuildQueueInitialize(self, queue):
# Build a command script to execute on remote system
queue.append('# Try to find login profile to execute')
queue.append('if [ -f /etc/profile ]; then')
queue.append(' echo "Sourcing /etc/profile"')
queue.append(' . /etc/profile')
queue.append('fi')
queue.append('if [ -f ~/.bash_profile ]; then')
queue.append(' echo "Sourcing ~/.bash_profile"')
queue.append(' . ~/.bash_profile')
queue.append('elif [ -f ~/.bash_login ]; then')
queue.append(' echo "Sourcing ~/.bash_login"')
queue.append(' . ~/.bash_login')
queue.append('elif [ -f ~/.profile ]; then')
queue.append(' echo "Sourcing ~/.profile"')
queue.append(' . ~/.profile')
queue.append('else')
queue.append(' echo "ERROR: Unable to find login files to source!"')
queue.append('fi')
queue.append('')
queue.append('# Hacks for the HP platform (normally dealt with by /etc/profile)')
queue.append('set +u')
queue.append('[ -e /etc/PATH ] && export PATH=$PATH:`cat /etc/PATH`')
queue.append('if [ -z "$PKG_CONFIG_PATH" -a -d /usr/local/lib/pkgconfig ]; then')
queue.append(' export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig')
queue.append('fi')
queue.append('')
queue.append('echo')
commandLine = ' '
commandLine.join(sys.argv)
queue.append('echo \'Command line: %s\'' % commandLine.join(sys.argv).replace('\'', '"'))
queue.append('echo "Starting at: `date`"')
queue.append('EXITSTATUS=0')
# Support the -command qualifier
if self.config.options.command:
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing custom command')
queue.append('echo "Command: %s"' % self.config.options.command)
queue.append('cd %s || exit $?' % self.path)
queue.append(self.config.options.command)
queue.append('EXITSTATUS=$?')
queue.append('exit $EXITSTATUS')
return
##
# Build queue of operations to clean up writable files on destination
#
# Note: "paths" should generally NOT be a list with new project-based clean mechanism
# (although, technically, it will work)
#
def BuildQueueCleanup(self, queue):
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing git cleanup')
queue.append('date')
# Basic steps are:
# 1. git stash (in each subproject)
# 2. git fetch (in each subproject)
queue.append('git stash')
queue.append('git submodule foreach git stash')
#
queue.append('git fetch --recurse-submodules')
##
# Build queue of operations to perform on the remote systems
#
def BuildQueue(self, queue):
self.BuildQueueInitialize(queue)
# Normally done by 'pbuild --init', but verify in case --init disabled
# Note that some hosts don't support "-o HashKnownHosts=no", so try twice
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing git validation')
queue.append('date')
queue.append('grep github.com, ~/.ssh/known_hosts > /dev/null 2> /dev/null || ssh -o StrictHostKeyChecking=no -o HashKnownHosts=no -T [email protected]')
queue.append('grep github.com, ~/.ssh/known_hosts > /dev/null 2> /dev/null || ssh -o StrictHostKeyChecking=no -T [email protected]')
# If directory doesn't exist, automatically clone
queue.append('create_repo_clone()')
queue.append('{')
queue.append(' echo')
queue.append(' echo ========================= Performing git clone')
queue.append(' date')
queue.append(' echo \'Cloning project %s\'' % self.projectDefs.GetCloneSource())
queue.append(' mkdir -p %s' % self.path)
queue.append(' sudo rm -rf %s' % self.path)
queue.append(' git clone --recursive %s %s || exit $?'
% (self.projectDefs.GetCloneSource(), self.path))
queue.append(' DID_WE_CLONE=1')
queue.append('}')
queue.append('DID_WE_CLONE=0')
queue.append('')
queue.append('if [ ! -d %s -o ! -d %s/.git ]; then' % (self.path, self.path))
queue.append(' create_repo_clone')
if self.config.options.clone:
queue.append('else')
queue.append(' create_repo_clone')
queue.append('fi')
# Change into the user directory for build purposes (it better exist by now!)
queue.append('cd %s || exit $?' % self.path)
# We only need to clean up the repo if we didn't just clone it ...
queue.append('if [ $DID_WE_CLONE -eq 0 ]; then')
self.BuildQueueCleanup(queue)
queue.append('fi')
# One way or another, we have a clean repository, so get it in a known state:
#
# 1. git checkout origin/master (in each subproject)
# 2. Apply --branch and --subproject as needed
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing git checkout origin/master')
queue.append('date')
queue.append('git checkout origin/master')
queue.append('git submodule foreach git checkout origin/master')
if self.config.options.branch:
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing Applying --branch qualifier')
queue.append('date')
queue.append('# Applying branch \'origin/%s\' to project' % self.config.options.branch)
queue.append('git checkout origin/%s || exit $?' % self.config.options.branch)
queue.append('git submodule update --init || exit $?')
if self.config.options.subproject:
subprojectList = self.config.options.subproject.split(',')
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing Applying --subproject qualifier')
queue.append('date')
for subproject in subprojectList:
# Subproject spec looks like: <dir>:<branch>
subproject_dir, subproject_branch = subproject.split(':')
queue.append('echo "Applying branch \'origin/%s\' to subproject \'%s\'"'
% (subproject_branch, subproject_dir))
queue.append('if [ ! -d "%s" ]; then' % subproject_dir)
queue.append(' echo "Directory \'%s\' not found for subproject spec \'%s\'"'
% (subproject_dir, subproject))
queue.append(' exit 1')
queue.append('fi')
queue.append('cd %s || exit $?' % subproject_dir)
queue.append('git checkout origin/%s || exit $?' % subproject_branch)
queue.append('cd %s || exit $?' % self.path)
queue.append('echo')
# Clean up the repostories of any existing (unnecessary files)
# We do this step here to properly handle any changes to .gitignore
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing git clean')
queue.append('date')
queue.append('sudo git clean -fdx || exit $?')
queue.append('sudo git submodule foreach git clean -fdx || exit $?')
# Get ready to build
queue.append('cd %s || exit $?' % self.projectDefs.GetBuildDirectory())
# Now generate the remainder of the command script
# If we don't support configure, then we don't support debug/release semantics
if self.projectDefs.UsesConfigureScript():
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing Determining debug/release')
queue.append('date')
config_options = self.projectDefs.GetConfigureQualifiers()
if self.projectDefs.GetProjectName() in self.config.configure_options:
config_options = self.config.configure_options[self.projectDefs.GetProjectName()]
if self.config.options.debug:
queue.append('echo "Performing DEBUG build"')
if config_options:
queue.append('echo " (Configuration options: %s --enable-debug)"' % config_options)
queue.append('./configure %s --enable-debug' % config_options)
queue.append('EXITSTATUS=$?')
else:
queue.append('echo "Performing RELEASE build"')
if config_options:
queue.append('echo " (Configuration options: %s)"' % config_options)
queue.append('./configure %s' % config_options)
queue.append('EXITSTATUS=$?')
queue.append('[ $EXITSTATUS != 0 ] && exit $EXITSTATUS')
if self.projectDefs.GetMakeDependencies():
queue.append('')
queue.append('echo')
queue.append('echo ========================= Performing make depend')
queue.append('date')
queue.append('make depend')
queue.append('echo')
if len(self.config.options.target) != 0:
# Our target is?
target = self.projectDefs.GetTargets()
if self.config.options.target != "target_default":
target = self.config.options.target
queue.append('')
queue.append('echo')
queue.append('echo \'========================= Performing make ' + target + '\'')
queue.append('date')
# Set up test restrictions if appropriate
if self.config.GetTestAttributes() != '':
queue.append('SCX_TESTRUN_ATTRS=\"%s\"; export SCX_TESTRUN_ATTRS' % self.config.GetTestAttributes())
if self.config.GetTestList() != '':
queue.append('SCX_TESTRUN_NAMES=\"%s\"; export SCX_TESTRUN_NAMES' % self.config.GetTestList())
queue.append('echo \'========================= Performing make %s ' % target + '\'')
queue.append('make %s ' % target)
queue.append('MAKE_STATUS=$?')
queue.append('if [ $MAKE_STATUS -ne 0 ]; then')
queue.append(' EXITSTATUS=$MAKE_STATUS')
queue.append('fi')
queue.append('')
if len(self.projectDefs.GetPostBuildCommands()) > 0:
queue.append('echo \'========================= Performing post build steps\'')
queue.append('POSTSTATUS=0')
for command in self.projectDefs.GetPostBuildCommands():
queue.append('if [ $POSTSTATUS -eq 0 ]; then')
queue.append(' echo \'========================= Performing Executing %s ' % command + '\'')
queue.append(' ' + command)
queue.append(' POSTSTATUS=$?')
queue.append('fi')
queue.append('if [ $POSTSTATUS -ne 0 ]; then')
queue.append(' EXITSTATUS=$POSTSTATUS')
queue.append('fi')
queue.append('echo')
queue.append('echo Ending at: `date`')
##
# Perform a build on a remote system (execute the command script already copied).
#
# Upon completion, <object>.process.returncode will contain the exit status for
# the remote build.
def DoBuild(self):
# If we're doing logfile renaming, active logs start as 'active-'
if self.renameLogfiles:
activeStr = 'active-'
else:
activeStr = ''
outfname = '%s%s%s%s.log' % (self.logPrefix, activeStr, self.tag, self.selectSpec)
if self.deleteLogfiles:
for prefix in [ '', 'active-', 'done-', 'failed-' ]:
try:
os.remove('%s%s%s%s.log' % (self.logPrefix, prefix, self.tag, self.selectSpec))
except OSError:
# If the file doesn't exist, that's fine
pass
else:
try:
os.remove(outfname)
except OSError:
# If the file doesn't exist, that's fine
pass
# Open the output file and launch the subprocess
#
# Slightly different behavior based on "ShowProgress" setting
# (solely for performance benefit - otherwise not really needed)
if self.showProgress:
outf = open(outfname, 'a+', 1)
self.process = subprocess.Popen(
['ssh', '-A', self.hostname, 'chmod 755 ' + self.destinationName + '; bash ' + self.destinationName],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
# Handle output from the subprocess
while True:
line = self.process.stdout.readline()
if line == '':
break
# Track out line count, save off any "state" lines, and save output
self.bLogActivity = True
self.cLogSubLines += 1
if line.startswith('========================= Performing '):
self.sActivityText = line.rstrip()[37:]
self.cLogSubLines = 0
outf.write(line)
if line.startswith("make: warning: Clock skew detected."):
outf.write("FATAL ERROR: Terminating process due to clock skew!");
outf.write("*** Check destination system to verify remote build was killed! ***")
self.process.terminate()
self.process.communicate()
else:
outf = open(outfname, 'a+')
self.process = subprocess.Popen(
['ssh', self.hostname, 'chmod 755 ' + self.destinationName + '; bash ' + self.destinationName],
stdin=subprocess.PIPE,
stdout=outf,
stderr=outf
)
self.process.wait()
outf.close()
if self.renameLogfiles:
# Determine the final name for the logfile
if self.process.returncode == 0:
completionStr = 'done-'
else:
completionStr = 'failed-'
newfname = '%s%s%s%s.log' % (self.logPrefix, completionStr, self.tag, self.selectSpec)
os.rename(outfname, newfname)
##
# Generate a command script to execute a remote build and copy it to the remote system.
# This is done by creating a local temporary file, then copying that file to the remote
# host. Upon exit from this function, the local temporary file is deleted.
#
# \returns
# Status from copy of command script to remote system (normally zero)
def GenerateCommandScript(self):
self.destinationName = '/tmp/%(LOGNAME)s_%(HOST)s_%(PID)d.sh' \
% {'LOGNAME': os.environ['LOGNAME'], 'HOST': self.tag, 'PID': os.getpid() }
# Prepend commands to go to the proper directory and delete our
# temporary command script.
#
# Add nice support for the emacs editor along the way ...
# Note: Disabled for now. Causes performance issues with some verisons of
# emacs. Disable, maybe enable via option if requested.
#self.queue.insert(0, 'echo \'-*- mode: compilation -*-\'')
# In case of internal errors, leave temporary command script around
if not self.diagnoseErrors:
self.queue.insert(1, 'rm ' + self.destinationName)
else:
self.queue.insert(1, 'echo \'Executing script %s\'' % self.destinationName)
self.queue.insert(2, 'echo "Executing on host $HOSTNAME (%(TAG)s: %(HOST)s)"' \
% {'TAG' : self.tag, 'HOST' : self.hostname } )
self.queue.insert(3, '')
# We assume that $EXITSTATUS was previously set by project-specific queue code
self.queue.append('echo ========================= Performing Finishing up\; status=$EXITSTATUS')
self.queue.append('exit $EXITSTATUS')
# Generate a temporary file with all of our commands
tmpfile = tempfile.NamedTemporaryFile()
for command in self.queue:
tmpfile.write(command + '\n')
tmpfile.flush()
# Copy the temporary command file to the destination host
self.process = subprocess.Popen(
['scp', '-q', tmpfile.name, self.hostname + ':' + self.destinationName],
stdin=subprocess.PIPE
)
# If the process isn't running yet, the wait() will fail - handle that
waitComplete = False
for i in range(60):
try:
self.process.wait()
waitComplete = True
break
except OSError:
time.sleep(1)
# Last try - if this fails, we get a stack trace (which is fine)
if waitComplete == False:
self.process.wait()
# Temporary file deleted on exit of this function ...
return self.process.returncode
def run(self):
if self.GenerateCommandScript() == 0:
self.DoBuild()
else:
# We aren't going to run, so create an empty log file with an error in it
if self.renameLogfiles:
completionStr = 'failed-'
else:
completionStr = ''
outfname = '%s%s%s%s.log' % (self.logPrefix, completionStr, self.tag, self.selectSpec)
outf = open(outfname, 'w+')
outf.write("ERROR: SCP process did not properly copy script for host: %s\n" % self.hostname)
outf.close()
return
##
# Builder class - oversees the overall build process
#
class Builder:
##
# Ctor.
# \param[in] Configuration class
def __init__(self, config):
self.config = config;
##
# Formats and returns command line to fit within a list
# where no one string exceeds a length
#
def FormatCommandLine(self, width):
stringList = []
curStr = ""
for item in sys.argv:
# Deal with spaces within the argument
if item.find(' ') != -1:
if item.find('=') != -1:
item = item.replace('=', '="', 1)
else:
item = item.replace(' ', ' "', 1)
item = item + '"'
if len(curStr) + len(item) >= width:
stringList.append(curStr)
curStr = " "
curStr = curStr + item + " "
stringList.append(curStr)
return stringList
##
# Move log files to prior log directory if desired
#
def MoveLogfiles(self):
# Just return if we're not doing logfile moving
if self.config.GetLogfilePriorPrefix() == '':
return
# Figure out the log file prefixes based on configuration
if self.config.GetSetting('LogfileRename'):
prefixStr = [ 'active-', 'done-', 'failed-' ]
else:
prefixStr = [ '' ]
# For each machine/prefix combination, move the log file
for machine in sorted(self.config.machines.keys()):
# To keep the prior log directory from becoming a garbage dump, we
# delete prior logs if we'll be moving any existing logs (based on
# configuration setting 'DeleteLogFiles')
if self.config.GetSetting('DeleteLogfiles'):
# Do we have any existing log files to move for this host?
existingLogs = False
for prefix in prefixStr:
srcfname = '%s%s%s.log' % (self.config.GetLogfilePrefix(), prefix, machine)
try:
os.stat(srcfname)
existingLogs = True
break
except OSError:
# If the file doesn't exist, that's fine
pass
# If so, then delete all variations of the log file from prior ...
if existingLogs:
for prefix in prefixStr:
dstfname = '%s%s%s.log' % (self.config.GetLogfilePriorPrefix(), prefix, machine)
try:
os.remove(dstfname)
except OSError:
# If the file doesn't exist, that's fine
pass
# And finally, move the 'current' logs to the prior directory
for prefix in prefixStr:
srcfname = '%s%s%s.log' % (self.config.GetLogfilePrefix(), prefix, machine)
dstfname = '%s%s%s.log' % (self.config.GetLogfilePriorPrefix(), prefix, machine)
try:
os.rename(srcfname, dstfname)
except OSError:
# If the file doesn't exist, that's fine
pass
##
# Perform processing (and screen updates)
#
def ProcessUpdates(self, stdscr, hosts):
startTime = time.time()
stdscr.nodelay(1)
(height, width) = stdscr.getmaxyx()
# Verify that our screen is large enough. Account for:
# . Three blank lines (after header, after host list, and before elapsed time)
# . "Host Count"
# . "Selector"
# . "Command Line" * 2
# . "Elapsed Time"
# . A "home" line for the cursor
lastLine = 0
hostCount = 0
for host in hosts:
lastLine = max(lastLine, host.display_line)
hostCount = hostCount + 1
lastLine += 9
if height < lastLine or width < 80:
return -1
# Indentation locations:
IndentTag = 0
IndentHost = 20
IndentStatus = 45
statusLen = width - IndentStatus - 1
# Print the headings on the screen
stdscr.addstr(0, IndentTag, "Tag", curses.A_UNDERLINE)
stdscr.addstr(0, IndentHost, "Host Name", curses.A_UNDERLINE)
stdscr.addstr(0, IndentStatus, "Status", curses.A_UNDERLINE)
# Begin processing on each of our hosts
lastLine = 0
for host in hosts:
host.start()
stdscr.addstr(host.display_line, IndentTag, host.tag[0:IndentHost-IndentTag-1])
stdscr.addstr(host.display_line, IndentHost, host.hostname[0:IndentStatus-IndentHost-1])
lastLine = max(lastLine, host.display_line)
lastLine = lastLine + 2
stdscr.addstr(lastLine, 0, 'Host Count:')
stdscr.addstr(lastLine, 15, '%d' % hostCount)
lastLine = lastLine + 1
stdscr.addstr(lastLine, 0, 'Selector:')
if self.config.GetSelectSpecification() != '':
stdscr.addstr(lastLine, 15, self.config.GetSelectSpecification())
else:
stdscr.addstr(lastLine, 15, '<None>')
lastLine = lastLine + 1
stdscr.addstr(lastLine, 0, 'Command Line:')
for line in self.FormatCommandLine(width - 15):
stdscr.addstr(lastLine, 15, line)
lastLine = lastLine + 1
lastLine = lastLine + 1
stdscr.addstr(lastLine, 0, 'Elapsed Time:')
stdscr.addstr(lastLine, 15, '00:00')
stdscr.addstr(lastLine + 1, 0, '')
stdscr.refresh()
# Wait for each of the hosts to complete processing
failCount = 0
while True:
time.sleep(1)
# See if we have some user input
# "r": Refresh screen
c = stdscr.getch()
if c == ord('R') or c == ord('r'):
stdscr.clearok(1)
# Come up with a pretty way to display elapsed time
currentTime = hostTime = (time.time() - startTime) + 0.5
hostHH = int(hostTime / 60 / 60)
hostTime = hostTime - (hostHH * 60 * 60)
hostMM = int(hostTime / 60)
hostSS = hostTime - (hostMM * 60)
if hostHH:
timeDisplay = '%02d:%02d:%02d' % (hostHH, hostMM, hostSS)
else:
timeDisplay = '%02d:%02d' % (hostMM, hostSS)
# See if we can finish up any threads
threadsLeft = False
for host in hosts:
if not host.finished and not host.isAlive():
host.join()
host.finished = True
if host.process.returncode == 0:
host.completionStatus = "Done (%s)" % timeDisplay
stdscr.addstr(host.display_line, IndentStatus,
"%-*.*s" % (statusLen, statusLen, host.completionStatus))
else:
failCount += 1
host.completionStatus = "Failed (%s)" % timeDisplay
stdscr.addstr(host.display_line, IndentTag, host.tag, curses.A_BOLD)
stdscr.addstr(host.display_line, IndentHost, host.hostname, curses.A_BOLD)
stdscr.addstr(host.display_line, IndentStatus,
"%-*.*s" % (statusLen, statusLen, host.completionStatus),
curses.A_BOLD)
if not host.finished:
threadsLeft = True
# Any activity on host? Update display if requested ...
if host.showProgress:
if host.bLogActivity:
host.bLogActivity = False
host.tActivityTime = currentTime
displayString = "%s (%d)" % (host.sActivityText, host.cLogSubLines)
stdscr.addstr(host.display_line, IndentStatus,
"- %-*.*s" % (statusLen-2, statusLen-2, displayString))
elif currentTime > (host.tActivityTime + 30):
# No activity for a long time? Indicate that ...
stdscr.addstr(host.display_line, IndentStatus, "?")
stdscr.addstr(lastLine, 15, timeDisplay)
stdscr.addstr(lastLine + 1, 0, '')
stdscr.refresh()
# Support --abortOnError behavior
if self.config.options.abort and failCount != 0:
# Mark all remaining hosts as "Aborted"
for host in hosts:
if not host.finished:
host.completionStatus = "Aborted (%s)" % timeDisplay
stdscr.addstr(host.display_line, IndentStatus,
"%-*.*s" % (statusLen, statusLen, host.completionStatus))
host.process.terminate()
stdscr.refresh()
return failCount
# Check if any threads are left
if not threadsLeft:
break
# All done
return failCount
##
# Perform processing (without curses)
#
def ProcessUpdatesWithoutCurses(self, hosts):
# Begin processing on each of our hosts
lastLine = 0
for host in hosts:
host.start()
print "Starting host %s (%s)" % (host.hostname, host.tag)
# Wait for each of the hosts to complete processing
failCount = 0
while True:
time.sleep(1)
# See if we can finish up any threads
threadsLeft = False
for host in hosts:
if not host.finished and not host.isAlive():
host.join()
host.finished = True
if host.process.returncode == 0:
print "Completed host %s (%s)" % (host.hostname, host.tag)
host.completionStatus = "Done"
else:
failCount += 1
print "FAILED: Host %s (%s)" % (host.hostname, host.tag)
host.completionStatus = "Failed"
if not host.finished:
threadsLeft = True
# Support --abortOnError behavior
if self.config.options.abort and failCount != 0:
print "ABORTING due to failed build and --abortOnError"
# Mark all remaining hosts as "Aborted"
for host in hosts:
if not host.finished:
host.completionStatus = "Aborted"
host.process.terminate()
return failCount
# Check if any threads are left
if not threadsLeft:
break
# All done
return failCount
##
# Perform a build across remote systems
#
def StartBuild(self):
# Build the host list:
# Either the one specified at launch, or all of the machines in configuraiton
hosts = []
if len(self.config.machineKeys):
for entry in sorted(self.config.machineKeys):
hosts.append( BuildHost(entry, self.config) )
else:
for key in sorted(self.config.machines.keys()):
hosts.append( BuildHost(key, self.config) )
# Figure out where each host will display it's data (sort by tag)
tags = []
for host in hosts:
tags.append( host.tag )
tags = sorted(tags)
for host in hosts:
host.display_line = tags.index(host.tag) + 2
# Sanity check - each host should have a non-zero display line
for host in hosts:
assert host.display_line != 0
# Move the log files to the prior log file directory
self.MoveLogfiles()
#
# Go perform the build (and update the screen with progress)
#
failCount = 0
if not self.config.options.nocurses:
failCount = curses.wrapper(self.ProcessUpdates, hosts)
if failCount == -1:
print "ABORTING - Screen size is too small to use curses"
return failCount
else:
failCount = self.ProcessUpdatesWithoutCurses(hosts)
print
# Print final completion status if configured
if self.config.GetSetting('SummaryScreen'):
print "Final status:\n"
# We really prefer to list sorted by tags, so do so
hosts_byTag = {}
for host in hosts:
hosts_byTag[host.tag] = host
for key in sorted(hosts_byTag.keys()):
print "%-19s %-25s %s" % (hosts_byTag[key].tag, hosts_byTag[key].hostname, hosts_byTag[key].completionStatus)
print
# All done
return failCount