-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
1652 lines (1441 loc) · 69.9 KB
/
config.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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import os
import sys
import shutil
import subprocess
import argparse
import yaml
import logging
import hashlib
import string
import atexit
from lockfile import LockFile, LockTimeout
from subprocess import Popen
from distutils.version import LooseVersion
if sys.version_info[0] < 3:
reload(sys)
sys.setdefaultencoding('utf8')
class Config:
def __init__(self):
self.__cmdline_read = 0
self.__configfile_read = 0
self.__fully_initiated = 0
self.arguments = False
self.argument_parser = False
self.configfile = False
self.config = False
self.output_help = True
self.lockfile_handle = False
self.lockfile_name = False
if (os.environ.get('HOME') is None):
logging.error("$HOME is not set!")
sys.exit(1)
if (os.path.isdir(os.environ.get('HOME')) is False):
logging.error("$HOME does not point to a directory!")
sys.exit(1)
atexit.register(self.exit_handler)
def exit_handler(self):
if (self.__fully_initiated == 1 and self.lockfile_name is not False):
if (hasattr(self.lockfile_handle, 'release') is True):
self.lockfile_handle.release()
logging.debug("lock on " + self.lockfile_name + " released")
# config_help()
#
# flag if help shall be printed
#
# parameter:
# - self
# - True/False
# return:
# none
def config_help(self, config):
if (config is False or config is True):
self.output_help = config
else:
print("")
print("invalid setting for config_help()")
sys.exit(1)
# print_help()
#
# print the help
#
# parameter:
# - self
# return:
# none
def print_help(self):
if (self.output_help is True):
self.argument_parser.print_help()
# parse_parameters()
#
# parse commandline parameters, fill in array with arguments
#
# parameter:
# - self
# return:
# none
def parse_parameters(self):
parser = argparse.ArgumentParser(description = 'PostgreSQL & Greenplum Buildfarm Client',
epilog = 'For questions, please see http://greenplum.org/',
add_help = False)
self.argument_parser = parser
parser.add_argument('--help', default = False, dest = 'help', action = 'store_true', help = 'show this help')
parser.add_argument('-c', '--config', default = '', dest = 'config', help = 'configuration file')
parser.add_argument('--animal', default = '', dest = 'animal', help = 'build farm animal name')
parser.add_argument('--secret', default = '', dest = 'secret', help = 'build farm animal secret')
parser.add_argument('--source', default = '', dest = 'source', help = 'path/URL to git repository')
parser.add_argument('--target', default = '', dest = 'target', help = 'URL to build farm server')
parser.add_argument('--cache-dir', default = '', dest = 'cache_dir', help = 'path to cache directory for git clone')
parser.add_argument('--build-dir', default = '', dest = 'build_dir', help = 'path to build directory for build')
parser.add_argument('--install-dir', default = '', dest = 'install_dir', help = 'path to install directory for tests')
parser.add_argument('--git-bin', default = '', dest = 'git_bin', help = 'git binary, default: search in $PATH')
parser.add_argument('--git-depth', default = '', dest = 'git_depth', help = 'depth for a shallow git clode, default: everything')
parser.add_argument('--ccache-bin', default = '', dest = 'ccache_bin', help = 'compiler cache binary, default: none')
# store_true: store "True" if specified, otherwise store "False"
# store_false: store "False" if specified, otherwise store "True"
parser.add_argument('--no-clean-on-failure', default = True, dest = 'clean_on_failure', action = 'store_false', help = 'do not clean up the build dir if there was an error')
parser.add_argument('--no-clean-at-all', default = True, dest = 'clean_everything', action = 'store_false', help = 'do not clean up the build')
parser.add_argument('--run-all', default = False, dest = 'run_all', action = 'store_true', help = 'run everything (update, configure, make, install, tests)')
parser.add_argument('--run-update', default = False, dest = 'run_update', action = 'store_true', help = 'fetch latest updates from git repository')
parser.add_argument('--run-configure', default = False, dest = 'run_configure', action = 'store_true', help = 'run configure step')
parser.add_argument('--run-make', default = False, dest = 'run_make', action = 'store_true', help = 'run make step')
parser.add_argument('--run-install', default = False, dest = 'run_install', action = 'store_true', help = 'run install step')
parser.add_argument('--run-tests', default = False, dest = 'run_tests', action = 'store_true', help = 'run tests step')
parser.add_argument('--buildfarm', default = False, dest = 'buildfarm', action = 'store_true', help = 'run in buildfarm mode')
parser.add_argument('--add-jobs-only', default = False, dest = 'add_jobs_only', action = 'store_true', help = 'only add new buildfarm jobs, do not execute them')
parser.add_argument('--enable-orca', default = False, dest = 'enable_orca', action = 'store_true', help = 'build Orca as part of Greenplum Database')
parser.add_argument('--extra-configure', default = '', dest = 'extra_configure', help = 'extra configure options')
parser.add_argument('--extra-make', default = '', dest = 'extra_make', help = 'extra make options')
parser.add_argument('--extra-install', default = '', dest = 'extra_install', help = 'extra make install options')
parser.add_argument('--extra-tests', default = '', dest = 'extra_tests', help = 'extra make installcheck-good options')
parser.add_argument('--patch', dest = 'patch', action = 'append', help = 'additional patch(es) to apply')
parser.add_argument('--make-parallel', default = '', dest = 'make_parallel', help = 'number of parallel make jobs (default: 1)')
parser.add_argument('--list-results', default = False, dest = 'list_results', action = 'store_true', help = 'list all locally stored results of previous runs')
parser.add_argument('--show-result', default = '', dest = 'show_result', help = 'show results of a specific build (use "last" for latest build)')
parser.add_argument('--show-id', default = False, dest = 'show_id', action = 'store_true', help = 'list only the ID for the specified build (requires --show-result)')
parser.add_argument('--show-repository', default = False, dest = 'show_repository', action = 'store_true', help = 'list only the repository for the specified build (requires --show-result)')
parser.add_argument('--show-branch', default = False, dest = 'show_branch', action = 'store_true', help = 'list only the branch for the specified build (requires --show-result)')
parser.add_argument('--show-revision', default = False, dest = 'show_revision', action = 'store_true', help = 'list only the revision for the specified build (requires --show-result)')
parser.add_argument('--show-build-dir', default = False, dest = 'show_build_dir', action = 'store_true', help = 'list only the build dir for the specified build (requires --show-result)')
parser.add_argument('--show-install-dir', default = False, dest = 'show_install_dir', action = 'store_true', help = 'list only the install dir for the specified build (requires --show-result)')
parser.add_argument('--list-jobs', default = False, dest = 'list_jobs', action = 'store_true', help = 'list all pending buildfarm jobs, then exit')
parser.add_argument('--list-all-jobs', default = False, dest = 'list_all_jobs', action = 'store_true', help = 'list all pending and finished buildfarm jobs, then exit')
parser.add_argument('--requeue-job', default = '', dest = 'requeue_job', help = 'requeue a buildfarm job')
parser.add_argument('--no-send-results', default = True, dest = 'send_results', action = 'store_false', help = 'do not send test results to server')
parser.add_argument('--build-branch', default = '', dest = 'build_branch', help = 'build this branch (or list of branches, separated by comma)')
parser.add_argument('--build-revision', default = '', dest = 'build_revision', help = 'build this revision (defaults to HEAD)')
parser.add_argument('--support-bin', default = '', dest = 'support_bin', help = "'buildclient_support.py' in the same directoy as the buildfarm client")
parser.add_argument('--disable-support', default = False, dest = 'disable_support', action = 'store_true', help = 'do not create a support package (nothing will be uploaded)')
parser.add_argument('--support-dir', default = '', dest = 'support_dir', help = 'optional directory for support files')
parser.add_argument('--support-file', default = '', dest = 'support_file', help = 'optional filename for support file, must end in .zip or .tar')
parser.add_argument('--support-archive-type', default = '', dest = 'support_archive_type', help = 'type of support archive: zip or tar')
parser.add_argument('--lockfile', default = '', dest = 'lockfile', help = 'optional lockfile name (required for buildfarm mode)')
parser.add_argument('--cleanup-builds', default = False, dest = 'cleanup_builds', action = 'store_true', help = 'cleanup all previous build and install directories')
parser.add_argument('--cleanup-patches', default = False, dest = 'cleanup_patches', action = 'store_true', help = 'cleanup all previous patches in cache directory')
parser.add_argument('--cleanup-support-files', default = False, dest = 'cleanup_support_files', action = 'store_true', help = 'cleanup all previous support files in build directory')
parser.add_argument('--test-locales', default = '', dest = 'test_locales', help = 'comma-separated list of locales to test (PostgreSQL only)')
parser.add_argument('--test-extra-targets', default = '', dest = 'test_extra_targets', help = 'space separated extra test targets (additional to "make check" in PostgreSQL or "make installcheck-good" in Greenplum"')
parser.add_argument('-v', '--verbose', default = False, dest = 'verbose', action = 'store_true', help = 'be more verbose')
parser.add_argument('-q', '--quiet', default = False, dest = 'quiet', action = 'store_true', help = 'run quietly')
# parse parameters
args = parser.parse_args()
if (args.help is True):
self.print_help()
sys.exit(0)
if (args.verbose is True and args.quiet is True):
self.print_help()
print("")
print("Error: --verbose and --quiet can't be set at the same time")
sys.exit(1)
if (args.verbose is True):
logging.getLogger().setLevel(logging.DEBUG)
if (args.quiet is True):
logging.getLogger().setLevel(logging.ERROR)
self.__cmdline_read = 1
self.arguments = args
return
# load_config()
#
# load configuration file (YAML)
#
# parameter:
# - self
# return:
# none
def load_config(self):
if not (self.arguments.config):
self.__configfile_read = 1
self.configfile = False
return
logging.debug("config file: " + self.arguments.config)
if (self.arguments.config and os.path.isfile(self.arguments.config) is False):
self.print_help()
print("")
print("Error: --config is not a file")
sys.exit(1)
try:
with open(self.arguments.config, 'r') as ymlcfg:
config_file = yaml.safe_load(ymlcfg)
except:
print("")
print("Error loading config file")
sys.exit(1)
#print(config_file['git']['executable'])
self.configfile = config_file
# prepopulate values, avoid nasty 'KeyError" later on
self.pre_set_configfile_value('git', 'executable', None)
self.pre_set_configfile_value('git', 'depth', None)
self.pre_set_configfile_value('buildfarm', 'animal', None)
self.pre_set_configfile_value('buildfarm', 'secret', None)
self.pre_set_configfile_value('buildfarm', 'url', None)
self.pre_set_configfile_value('buildfarm', 'send-results', None)
self.pre_set_configfile_value('buildfarm', 'enabled', None)
self.pre_set_configfile_value('buildfarm', 'add-jobs-only', None)
self.pre_set_configfile_value('repository', 'url', None)
# top-dir can only be present in the config file
# pathnames on the commandline need to be fully specified
self.pre_set_configfile_value('build', 'dirs', 'top-dir')
self.pre_set_configfile_value('build', 'dirs', 'cache-dir')
self.pre_set_configfile_value('build', 'dirs', 'build-dir')
self.pre_set_configfile_value('build', 'dirs', 'install-dir')
self.pre_set_configfile_value('build', 'patch', None)
self.pre_set_configfile_value('build', 'options', 'no-clean-on-failure')
self.pre_set_configfile_value('build', 'options', 'no-clean-at-all')
self.pre_set_configfile_value('build', 'options', 'enable-orca')
self.pre_set_configfile_value('build', 'options', 'extra-configure')
self.pre_set_configfile_value('build', 'options', 'extra-make')
self.pre_set_configfile_value('build', 'options', 'extra-install')
self.pre_set_configfile_value('build', 'options', 'extra-tests')
self.pre_set_configfile_value('build', 'options', 'ccache-bin')
self.pre_set_configfile_value('build', 'options', 'make-parallel')
self.pre_set_configfile_value('build', 'work', 'branch')
self.pre_set_configfile_value('build', 'work', 'revision')
self.pre_set_configfile_value('build', 'cleanup', 'cleanup-builds')
self.pre_set_configfile_value('build', 'cleanup', 'cleanup-patches')
self.pre_set_configfile_value('build', 'cleanup', 'cleanup-support-files')
self.pre_set_configfile_value('support', 'executable', None)
self.pre_set_configfile_value('support', 'disable-support', None)
self.pre_set_configfile_value('support', 'support-dir', None)
self.pre_set_configfile_value('support', 'support-file', None)
self.pre_set_configfile_value('support', 'archive-type', None)
self.pre_set_configfile_value('locking', 'lockfile', None)
self.pre_set_configfile_value('test', 'locales', None)
self.pre_set_configfile_value('test', 'extra-targets', None)
self.__configfile_read = 1
return
# pre_set_configfile_value()
#
# make sure that the specified configfile parameter is initialized
#
# parameter:
# - name of first level
# - name of second level (or None)
# - name of third level (or None)
def pre_set_configfile_value(self, pos1, pos2, pos3):
if (pos1 is None):
print("Error setting configfile value")
sys.exit(1)
if (pos3 is not None and pos2 is None):
print("Error setting configfile value")
sys.exit(1)
if (pos2 is None):
# just pos1 is specified, this makes pos1 an actual key
# not a container for more config elements
if not (pos1 in self.configfile):
self.configfile[pos1] = ''
if (self.configfile[pos1] is None):
self.configfile[pos1] = ''
return
if (pos3 is None):
# pos1 is a dictionary
if not (pos1 in self.configfile):
self.configfile[pos1] = {}
if not (pos2 in self.configfile[pos1]):
self.configfile[pos1][pos2] = ''
if (self.configfile[pos1][pos2] is None):
self.configfile[pos1][pos2] = ''
return
# pos1 and pos2 are dictionaries
if not (pos1 in self.configfile):
self.configfile[pos1] = {}
if not (pos2 in self.configfile[pos1]):
self.configfile[pos1][pos2] = {}
if not (pos3 in self.configfile[pos1][pos2]):
self.configfile[pos1][pos2][pos3] = ''
if (self.configfile[pos1][pos2][pos3] is None):
self.configfile[pos1][pos2][pos3] = ''
return
# replace_home_env()
#
# replace placeholder for home directory with actual directory name
#
# parameter:
# - self
# - directory name
# return:
# - directory name
def replace_home_env(self, dir):
#dir = string.replace(dir, '$HOME', os.environ.get('HOME'))
dir = dir.replace('$HOME', os.environ.get('HOME'))
dir = dir.replace('$TOPDIR', self.configfile['build']['dirs']['top-dir'])
dir = dir.replace('$HOME', os.environ.get('HOME'))
return dir
# build_and_verify_config()
#
# verify configuration,
# create config from commandline and config file
#
# parameter:
# - self
# return:
# none
def build_and_verify_config(self):
ret = {}
if (self.arguments.verbose is True and self.arguments.quiet is True):
self.print_help()
print("")
print("Error: --verbose and --quiet can't be set at the same time")
sys.exit(1)
if (self.arguments.verbose is True):
logging.getLogger().setLevel(logging.DEBUG)
ret['verbose'] = True
ret['quiet'] = False
if (self.arguments.quiet is True):
logging.getLogger().setLevel(logging.ERROR)
ret['verbose'] = False
ret['quiet'] = True
if (self.arguments.list_jobs is True):
if (len(self.arguments.show_result) > 0 or
self.arguments.list_results is True or
self.arguments.list_all_jobs is True or
len(self.arguments.requeue_job) > 0 or
self.arguments.run_all is True or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --list-jobs can't be combined with another run option")
sys.exit(1)
if (self.arguments.list_all_jobs is True):
if (len(self.arguments.show_result) > 0 or
self.arguments.list_results is True or
self.arguments.list_jobs is True or
len(self.arguments.requeue_job) > 0 or
self.arguments.run_all is True or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --list-all-jobs can't be combined with another run option")
sys.exit(1)
if (len(self.arguments.requeue_job) > 0):
if (len(self.arguments.show_result) > 0 or
self.arguments.list_results is True or
self.arguments.list_jobs is True or
self.arguments.list_all_jobs is True or
self.arguments.run_all is True or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --requeue-job can't be combined with another run option")
sys.exit(1)
if (self.arguments.list_results is True):
if (len(self.arguments.show_result) > 0 or
self.arguments.list_jobs is True or
self.arguments.list_all_jobs is True or
len(self.arguments.requeue_job) > 0 or
self.arguments.run_all is True or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --list-results can't be combined with another run option")
sys.exit(1)
if (len(self.arguments.show_result) > 0):
if (self.arguments.list_results is True or
self.arguments.list_jobs is True or
self.arguments.list_all_jobs is True or
len(self.arguments.requeue_job) > 0 or
self.arguments.run_all is True or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --show-result can't be combined with another run option")
sys.exit(1)
if (len(self.arguments.show_result) > 0):
number_show_args = 0
if (self.arguments.show_id is True):
number_show_args += 1
if (self.arguments.show_repository is True):
number_show_args += 1
if (self.arguments.show_branch is True):
number_show_args += 1
if (self.arguments.show_revision is True):
number_show_args += 1
if (self.arguments.show_build_dir is True):
number_show_args += 1
if (self.arguments.show_install_dir is True):
number_show_args += 1
if (number_show_args > 1):
print("")
print("Error: --show-result only allows one extra argument")
sys.exit(1)
else:
if (self.arguments.show_id is True or
self.arguments.show_repository is True or
self.arguments.show_branch is True or
self.arguments.show_revision is True or
self.arguments.show_build_dir is True or
self.arguments.show_install_dir is True):
print("")
print("Error: extra argument specified, but --show-result is missing")
sys.exit(1)
if (self.arguments.run_all is True):
if (len(self.arguments.show_result) > 0 or
self.arguments.list_results is True or
self.arguments.list_jobs is True or
self.arguments.list_all_jobs is True or
len(self.arguments.requeue_job) > 0 or
self.arguments.run_update is True or
self.arguments.run_configure is True or
self.arguments.run_make is True or
self.arguments.run_install is True or
self.arguments.run_tests is True):
self.print_help()
print("")
print("Error: --run-all can't be combined with another run option")
sys.exit(1)
if (self.arguments.run_all is True):
ret['show-result'] = ''
ret['list-results'] = False
ret['list-jobs'] = False
ret['list-all-jobs'] = False
ret['requeue-job'] = ''
ret['run-update'] = True
ret['run-configure'] = True
ret['run-make'] = True
ret['run-install'] = True
ret['run-tests'] = True
ret['show-id'] = False
ret['show-repository'] = False
ret['show-branch'] = False
ret['show-revision'] = False
ret['show-build-dir'] = False
ret['show-install-dir'] = False
else:
ret['show-result'] = self.arguments.show_result if (len(self.arguments.show_result) > 0) else ''
ret['list-results'] = True if (self.arguments.list_results is True) else False
ret['list-jobs'] = True if (self.arguments.list_jobs is True) else False
ret['list-all-jobs'] = True if (self.arguments.list_all_jobs is True) else False
ret['requeue-job'] = self.arguments.requeue_job if (len(self.arguments.requeue_job) > 0) else ''
ret['run-update'] = True if (self.arguments.run_update is True) else False
ret['run-configure'] = True if (self.arguments.run_configure is True) else False
ret['run-make'] = True if (self.arguments.run_make is True) else False
ret['run-install'] = True if (self.arguments.run_install is True) else False
ret['run-tests'] = True if (self.arguments.run_tests is True) else False
ret['show-id'] = True if (self.arguments.show_id is True) else False
ret['show-repository'] = True if (self.arguments.show_repository is True) else False
ret['show-branch'] = True if (self.arguments.show_branch is True) else False
ret['show-revision'] = True if (self.arguments.show_revision is True) else False
ret['show-build-dir'] = True if (self.arguments.show_build_dir is True) else False
ret['show-install-dir'] = True if (self.arguments.show_install_dir is True) else False
# do not require --run-update
#if (ret['run-configure'] is True and ret['run-update'] is False):
# self.print_help()
# print("")
# print("Error: --run-configure requires --run-update")
# sys.exit(1)
if (ret['run-make'] is True and ret['run-configure'] is False):
self.print_help()
print("")
print("Error: --run-make requires --run-configure")
sys.exit(1)
if (ret['run-install'] is True and ret['run-make'] is False):
self.print_help()
print("")
print("Error: --run-install requires --run-make")
sys.exit(1)
if (ret['run-tests'] is True and ret['run-install'] is False):
self.print_help()
print("")
print("Error: --run-tests requires --run-install")
sys.exit(1)
if (self.arguments.cache_dir and os.path.isdir(self.arguments.cache_dir) is False):
self.print_help()
print("")
print("Error: --cache-dir is not a directory")
print("Argument: " + self.arguments.cache_dir)
sys.exit(1)
if (self.configfile is not False):
if (len(self.configfile['build']['dirs']['cache-dir']) > 0 and os.path.isdir(self.replace_home_env(self.configfile['build']['dirs']['cache-dir'])) is False):
self.print_help()
print("")
print("Error: cache-dir is not a directory")
print("Argument: " + self.configfile['build']['dirs']['cache-dir'])
sys.exit(1)
if (self.arguments.cache_dir):
ret['cache-dir'] = self.arguments.cache_dir
elif (self.configfile is not False and self.configfile['build']['dirs']['cache-dir']):
ret['cache-dir'] = self.replace_home_env(self.configfile['build']['dirs']['cache-dir'])
else:
self.print_help()
print("")
print("Error: cache-dir is not defined")
sys.exit(1)
if (ret['cache-dir'].find("'") != -1 or ret['cache-dir'].find('"') != -1):
self.print_help()
print("")
print("Error: Invalid cache-dir name")
print("Argument: " + ret['cache-dir'])
sys.exit(1)
if (self.arguments.build_dir and os.path.isdir(self.arguments.build_dir) is False):
self.print_help()
print("")
print("Error: --build-dir is not a directory")
print("Argument: " + self.arguments.build_dir)
sys.exit(1)
if (self.configfile is not False):
if (len(self.configfile['build']['dirs']['build-dir']) > 0 and os.path.isdir(self.replace_home_env(self.configfile['build']['dirs']['build-dir'])) is False):
self.print_help()
print("")
print("Error: build-dir is not a directory")
print("Argument: " + self.configfile['build']['dirs']['build-dir'])
sys.exit(1)
if (self.arguments.build_dir):
ret['build-dir'] = self.arguments.build_dir
elif (self.configfile is not False and self.configfile['build']['dirs']['build-dir']):
ret['build-dir'] = self.replace_home_env(self.configfile['build']['dirs']['build-dir'])
else:
self.print_help()
print("")
print("Error: build-dir is not defined")
sys.exit(1)
if (ret['build-dir'].find("'") != -1 or ret['build-dir'].find('"') != -1):
self.print_help()
print("")
print("Error: Invalid build-dir name")
print("Argument: " + ret['build-dir'])
sys.exit(1)
if (self.arguments.install_dir and os.path.isdir(self.arguments.install_dir) is False):
self.print_help()
print("")
print("Error: --install-dir is not a directory")
print("Argument: " + self.arguments.install_dir)
sys.exit(1)
if (self.configfile is not False):
if (len(self.configfile['build']['dirs']['install-dir']) > 0 and os.path.isdir(self.replace_home_env(self.configfile['build']['dirs']['install-dir'])) is False):
self.print_help()
print("")
print("Error: install-dir is not a directory")
print("Argument: " + self.configfile['build']['dirs']['install-dir'])
sys.exit(1)
if (self.arguments.install_dir):
ret['install-dir'] = self.arguments.install_dir
elif (self.configfile is not False and self.configfile['build']['dirs']['install-dir']):
ret['install-dir'] = self.replace_home_env(self.configfile['build']['dirs']['install-dir'])
else:
self.print_help()
print("")
print("Error: install-dir is not defined")
sys.exit(1)
if (ret['install-dir'].find("'") != -1 or ret['install-dir'].find('"') != -1):
self.print_help()
print("")
print("Error: Invalid install-dir name")
print("Argument: " + ret['install-dir'])
sys.exit(1)
stat_cache = os.stat(ret['cache-dir'])
stat_build = os.stat(ret['build-dir'])
if (stat_cache.st_dev != stat_build.st_dev):
self.print_help()
print("")
print("Error: cache-dir and build-dir must be on the same filesystem")
sys.exit(1)
if (self.arguments.git_bin == ''):
if (self.configfile is not False and len(self.configfile['git']['executable']) > 0):
# use the executable from the configuration file
if (self.binary_is_executable(self.configfile['git']['executable']) is False):
self.print_help()
print("")
print("Error: --git-bin is not an executable")
print("Argument: " + self.configfile['git']['executable'])
sys.exit(1)
ret['git-bin'] = self.configfile['git']['executable']
else:
# find git binary in $PATH
tmp_bin = self.find_in_path('git')
if (tmp_bin is False):
self.print_help()
print("")
print("Error: no 'git' executable found")
sys.exit(1)
ret['git-bin'] = tmp_bin
else:
if (self.binary_is_executable(self.arguments.git_bin) is False):
self.print_help()
print("")
print("Error: --git-bin is not an executable")
print("Argument: " + self.arguments.git_bin)
sys.exit(1)
ret['git-bin'] = self.arguments.git_bin
# check 'git' version number
null_file = open(os.devnull, 'w')
v = subprocess.check_output([ret['git-bin'], '--version'], stderr=null_file)
null_file.close()
# make sure the extract ends in a number, this will cut of things like "rc..."
v_r = re.match(b'git version ([\d\.]+\d)', v)
if (v_r):
logging.debug("'" + str(ret['git-bin']) + "' version: " + v_r.group(1).decode())
self.arguments.git_version = v_r.group(1).decode()
else:
self.print_help()
print("")
print("Error: cannot identify 'git' version")
sys.exit(1)
# 'git' version must be 2.x.x, or greater
v_v = self.arguments.git_version.split('.')
try:
v_v2 = int(v_v[0])
except ValueError:
self.print_help()
print("")
print("Error: cannot identify 'git' version")
sys.exit(1)
if (v_v2 < 2):
self.print_help()
print("")
print("Error: minimum required 'git' version is 2")
print("Found: " + self.arguments.git_version)
sys.exit(1)
# all git versions below 2.7.1 are vulnerable
if (LooseVersion(self.arguments.git_version) <= LooseVersion('2.7.1')):
logging.warning("git version (" + self.arguments.git_version + ") is vulnerable!")
if (self.arguments.git_depth == ''):
# read value from configfile
if (self.configfile is not False and len(str(self.configfile['git']['depth'])) > 0):
ret['git-depth'] = self.configfile['git']['depth']
else:
# default value (everything)
ret['git-depth'] = 0
else:
# use input from commandline
ret['git-depth'] = self.arguments.git_depth
try:
t = int(ret['git-depth'])
except ValueError:
self.print_help()
print("")
print("Error: git-depth is not an integer")
sys.exit(1)
if (t < 0):
self.print_help()
print("")
print("Error: git-depth must be a positive integer")
sys.exit(1)
ret['git-depth'] = t
if (self.arguments.send_results is False):
# --no-send-results specified on commandline, honor the flag
ret['send-results'] = False
elif (self.arguments.send_results is True):
# see if the configuration overrides this flag
# FIXME: deal with non-integer values
if (self.configfile is not False and self.configfile['buildfarm']['send-results'] == 1):
ret['send-results'] = True
else:
ret['send-results'] = False
if (self.arguments.animal):
ret['buildfarm-animal'] = self.arguments.animal
elif (self.configfile is not False and len(self.configfile['buildfarm']['animal']) > 0):
ret['buildfarm-animal'] = self.configfile['buildfarm']['animal']
else:
if (ret['send-results'] == True):
self.print_help()
print("")
print("Error: No buildfarm animal name specified")
sys.exit(1)
if (self.arguments.secret):
ret['buildfarm-secret'] = self.arguments.secret
elif (self.configfile is not False and len(self.configfile['buildfarm']['secret']) > 0):
ret['buildfarm-secret'] = self.configfile['buildfarm']['secret']
else:
if (ret['send-results'] == True):
self.print_help()
print("")
print("Error: No buildfarm animal secret specified")
sys.exit(1)
if (self.arguments.target):
ret['buildfarm-url'] = self.arguments.target
elif (self.configfile is not False and len(self.configfile['buildfarm']['url']) > 0):
ret['buildfarm-url'] = self.configfile['buildfarm']['url']
else:
if (ret['send-results'] == True):
self.print_help()
print("")
print("Error: No buildfarm url specified")
sys.exit(1)
if (self.arguments.buildfarm is True):
# --buildfarm specified on commandline, honor the flag
ret['buildfarm'] = True
elif (self.arguments.buildfarm is False):
# see if the configuration overrides this flag
# FIXME: deal with non-integer values
if (self.configfile is not False and self.configfile['buildfarm']['enabled'] == 1):
ret['buildfarm'] = True
else:
ret['buildfarm'] = False
if (self.arguments.add_jobs_only is True):
# --add-jobs-only specified on commandline, honor the flag
ret['add-jobs-only'] = True
elif (self.arguments.add_jobs_only is False):
# see if the configuration overrides this flag
# FIXME: deal with non-integer values
if (self.configfile is not False and self.configfile['buildfarm']['add-jobs-only'] == 1):
ret['add-jobs-only'] = True
else:
ret['add-jobs-only'] = False
if (ret['buildfarm'] is True):
# certain options are not valid in buildfarm mode
if (len(ret['show-result']) > 0):
self.print_help()
print("")
print("Error: --show-result cannot be combined with --buildfarm")
sys.exit(1)
if (ret['list-results'] is True):
self.print_help()
print("")
print("Error: --list-results cannot be combined with --buildfarm")
sys.exit(1)
if (ret['list-jobs'] is True):
self.print_help()
print("")
print("Error: --list-jobs cannot be combined with --buildfarm")
sys.exit(1)
if (ret['list-all-jobs'] is True):
self.print_help()
print("")
print("Error: --list-all-jobs cannot be combined with --buildfarm")
sys.exit(1)
if (len(ret['requeue-job']) > 0):
self.print_help()
print("")
print("Error: --requeue-job cannot be combined with --buildfarm")
sys.exit(1)
if (ret['run-update'] is False):
self.print_help()
print("")
print("Error: --run-update must be set when combined with --buildfarm")
sys.exit(1)
if (ret['run-configure'] is False):
self.print_help()
print("")
print("Error: --run-configure must be set when combined with --buildfarm")
sys.exit(1)
if (ret['run-make'] is False):
self.print_help()
print("")
print("Error: --run-make must be set when combined with --buildfarm")
sys.exit(1)
if (ret['run-install'] is False):
self.print_help()
print("")
print("Error: --run-install must be set when combined with --buildfarm")
sys.exit(1)
if (ret['run-tests'] is False):
self.print_help()
print("")
print("Error: --run-tests must be set when combined with --buildfarm")
sys.exit(1)
if (ret['add-jobs-only'] is True and ret['buildfarm'] is False):
self.print_help()
print("")
print("Error: --add-jobs-only requires --buildfarm")
sys.exit(1)
if (ret['buildfarm'] is True):
# need a 'tar' binary
# the original buildfarm, by default, uses the one provided by the system
# find tar binary in $PATH
tmp_bin = self.find_in_path('tar')
if (tmp_bin is False):
self.print_help()
print("")
print("Error: no 'tar' executable found")
sys.exit(1)
ret['tar-bin'] = tmp_bin
# do not really check if a valid repository is specified, let git deal with it
if (self.arguments.source):
ret['repository-url'] = self.arguments.source
elif (self.configfile is not False and len(self.configfile['repository']['url'])) > 0:
ret['repository-url'] = self.configfile['repository']['url']
else:
#self.print_help()
#print("")
#print("Error: No repository url specified")
#sys.exit(1)
# do not check for a repository here
# there are certain actions which do not require a repository
ret['repository-url'] = ""
if (self.arguments.clean_on_failure is False):
# --no-clean-on-failure specified on commandline, honor the flag
ret['clean-on-failure'] = False
elif (self.arguments.clean_on_failure is True):
# see if the configuration overrides this flag
if (self.configfile is not False and self.configfile['build']['options']['no-clean-on-failure'] == 1):
ret['clean-on-failure'] = True
else:
ret['clean-on-failure'] = False
if (self.arguments.clean_everything is False):
# --no-clean-at-all specified on commandline, honor the flag
ret['clean-everything'] = False
elif (self.arguments.clean_everything is True):
# see if the configuration overrides this flag
if (self.configfile is not False and self.configfile['build']['options']['no-clean-at-all'] == 1):
ret['clean-everything'] = True
else:
ret['clean-everything'] = False
if (self.arguments.build_branch == ''):
if (self.configfile is not False and len(self.configfile['build']['work']['branch']) > 0):
ret['build-branch'] = self.configfile['build']['work']['branch']
else:
# set to reasonable default value
ret['build-branch'] = 'master'
else:
ret['build-branch'] = self.arguments.build_branch
if (ret['build-branch'].find(',') != -1):
# more than one branch specified
ret['build-branch'] = ret['build-branch'].split(',')
else:
# only one branch
ret['build-branch'] = [ ret['build-branch'] ]
for branch in ret['build-branch']:
if (branch.find('/') != -1):
self.print_help()
print("")
print("Error: Invalid branch name (only local branches allowed)")
print("Argument: " + branch)
sys.exit(1)
if (branch.find("'") != -1 or branch.find('"') != -1):
self.print_help()
print("")
print("Error: Invalid branch name")
print("Argument: " + branch)
sys.exit(1)
if (self.arguments.build_revision == ''):
if (self.configfile is not False and len(self.configfile['build']['work']['revision']) > 0):
ret['build-revision'] = self.configfile['build']['work']['revision']
else:
# set to reasonable default value
ret['build-revision'] = 'HEAD'
else:
ret['build-revision'] = self.arguments.build_revision
if (len(ret['build-branch']) > 1 and len(ret['build-revision']) > 0 and ret['build-revision'] != 'HEAD'):
self.print_help()
print("")
print("Error: Multiple branches specified, not possible to specify a revision")
sys.exit(1)
if not (re.match("^[a-zA-Z0-9]+$", ret['build-revision'])):
self.print_help()
print("")
print("Error: Invalid revision name")
print("Argument: " + ret['build-revision'])
sys.exit(1)
if (self.arguments.extra_configure == ''):
if (self.configfile is not False and len(self.configfile['build']['options']['extra-configure']) > 0):
ret['extra-configure'] = self.configfile['build']['options']['extra-configure']
else:
ret['extra-configure'] = ''
else:
ret['extra-configure'] = self.arguments.extra_configure
if (self.arguments.extra_make == ''):
if (self.configfile is not False and len(self.configfile['build']['options']['extra-make']) > 0):
ret['extra-make'] = self.configfile['build']['options']['extra-make']
else:
ret['extra-make'] = ''
else:
ret['extra-make'] = self.arguments.extra_make
if (self.arguments.extra_install == ''):
if (self.configfile is not False and len(self.configfile['build']['options']['extra-install']) > 0):
ret['extra-install'] = self.configfile['build']['options']['extra-install']
else:
ret['extra-install'] = ''
else:
ret['extra-install'] = self.arguments.extra_install