-
Notifications
You must be signed in to change notification settings - Fork 25
/
module.py
2956 lines (2296 loc) · 88 KB
/
module.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
#
# Collective Knowledge (checking and installing software)
#
# See CK LICENSE.txt for licensing details
# See CK COPYRIGHT.txt for copyright details
#
# Developer: Grigori Fursin, Grigori.Fursin@cTuning.org, http://fursin.net
#
cfg={} # Will be updated by CK (meta description of this module)
work={} # Will be updated by CK (temporal data)
ck=None # Will be updated by CK (initialized CK kernel)
# Local settings
env_install_path='CK_TOOLS'
env_search='CK_DIRS'
##############################################################################
# Initialize module
def init(i):
"""
Input: {}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""
return {'return':0}
##############################################################################
# detect is given software is already installed and register it in the CK or install it if package exists (the same as 'check')
def detect(i):
"""
Input: {
(host_os) - host OS (detect, if omitted)
(target_os) - target OS (detect, if omitted)
(target_device_id) - target device ID (detect, if omitted)
(data_uoa) or (uoa) - software UOA entry
or
(tags) - search UOA by tags (separated by comma)
(interactive) - if 'yes', and has questions, ask user
(quiet) - if 'yes', do not ask questions but select default value
(skip_help) - if 'yes', skip print help if not detected (when called from env setup)
(deps) - already resolved deps (if called from env)
(extra_version) - add extra version, when registering software
(for example, -trunk-20160421)
(force_env_data_uoa) - force which env UID to use when regstering detect software -
useful when reinstalling broken env entry to avoid breaking
all dependencies of other software ...
(search_dirs) - extra directories where to search soft (string separated by comma)
(soft_name) - name to search explicitly
(version_from) - check version starting from ... (string or list of numbers)
(version_to) - check version up to ... (string list of numbers)
(full_path) - force full path (rather than searching in all directories)
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
path_install - path to the detected software
cus - dict with filled in info for the software
}
"""
return check(i)
##############################################################################
# detect soft (internal function - gradually outdated)
def internal_detect(i):
"""
Input: {
(host_os) - host OS (detect, if omitted)
(target_os) - target OS (detect, if omitted)
(target_device_id) - target device ID (detect, if omitted)
(data_uoa) or (uoa) - software UOA entry
or
(tags) - search UOA by tags (separated by comma)
(tool) - force this tool name
(env) - if !='', use this env string before calling compiler (to set up env)
(show) - if 'yes', show output
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
version_str - version as string
version_lst - version as list of strings
version_raw - raw list of strings (output of --version)
}
"""
import os
o=i.get('out','')
# Check host/target OS/CPU
hos=i.get('host_os','')
tos=i.get('target_os','')
tdid=i.get('target_device_id','')
r=ck.access({'action':'detect',
'module_uoa':cfg['module_deps']['platform.os'],
'host_os':hos,
'target_os':tos,
'target_device_id':tdid,
'skip_info_collection':'yes'})
if r['return']>0: return r
hos=r['host_os_uid']
hosx=r['host_os_uoa']
hosd=r['host_os_dict']
tos=r['os_uid']
tosx=r['os_uoa']
tosd=r['os_dict']
hplat=hosd['ck_name']
tplat=tosd['ck_name']
env=i.get('env','')
ubtr=hosd.get('use_bash_to_run','')
svarb=hosd.get('env_var_start','')
svarb1=hosd.get('env_var_extra1','')
svare=hosd.get('env_var_stop','')
svare1=hosd.get('env_var_extra2','')
sexe=hosd.get('set_executable','')
sbp=hosd.get('bin_prefix','')
envsep=hosd.get('env_separator','')
scall=hosd.get('env_call','')
sext=hosd.get('script_ext','')
# Check soft UOA
duoa=i.get('uoa','')
if duoa=='': duoa=i.get('data_uoa','')
if duoa=='':
# Search
tags=i.get('tags','')
if tags!='':
r=ck.access({'action':'search',
'module_uoa':work['self_module_uid'],
'tags':tags})
if r['return']>0: return r
l=r['lst']
if len(l)>0:
duid=l[0].get('data_uid')
duoa=duid
if duoa=='':
return {'return':1, 'error':'software entry was not found'}
# Load
r=ck.access({'action':'load',
'module_uoa':work['self_module_uid'],
'data_uoa':duoa})
if r['return']>0: return r
d=r['dict']
p=r['path']
duoa=r['data_uoa']
duid=r['data_uid']
if o=='con':
x=duoa
if duid!=duoa: x+=' ('+duid+')'
ck.out('Software description entry found: '+x)
# Check if customize script is redirected into another entry:
#
another_entry_with_customize_script=d.get('use_customize_script_from_another_entry', None)
if another_entry_with_customize_script:
r=ck.access({'action':'find',
'module_uoa': another_entry_with_customize_script.get('module_uoa', work['self_module_uid']),
'data_uoa': another_entry_with_customize_script.get('data_uoa','')
})
if r['return']>0: return r
customization_script_path = r['path']
else:
customization_script_path = p
cs=None
rx=ck.load_module_from_path({'path':customization_script_path, 'module_code_name':cfg['custom_script_name'], 'skip_init':'yes'})
if rx['return']==0:
cs=rx['code']
elif another_entry_with_customize_script or not rx['error'].startswith("can't find module code"):
return rx
# Checking name
cus=d.get('customize',{})
tool=i.get('tool','')
if tool=='':
if cus.get('soft_file_as_env','')!='':
tool=svarb+cus['soft_file_as_env']+svare
if cus.get('soft_file_not_tool','')!='yes':
ry=prepare_target_name({'host_os_dict':hosd,
'target_os_dict':tosd,
'cus':cus})
if ry['return']>0: return ry
tool=ry['tool']
# Preparing CMD
soft_version_cmd=cus.get('soft_version_cmd',{}).get(hplat,'')
if o=='con':
ck.out('')
ck.out('Prepared cmd: '+soft_version_cmd+' ...')
# Check version (via customized script) ...
ver=''
lst=[]
ii={'full_path':tool,
'bat':env,
'host_os_dict':hosd,
'target_os_dict':tosd,
'cmd':soft_version_cmd,
'use_locale':cus.get('use_locale_for_version',''),
'customize':cus,
'custom_script_obj':cs,
'data_uid': duid,
}
rx=get_version(ii)
if rx['return']==0:
ver=rx['version']
lst=rx['version_lst']
if ver=='':
return {'return':16, 'error':'version was not detected'}
# Split version
rx=split_version({'version':ver})
if rx['return']>0: return rx
sver=rx['version_split']
if i.get('show','')=='yes':
ck.out('Output:')
ck.out('')
for q in lst:
ck.out(' '+q)
if o=='con':
ck.out('')
ck.out('Version detected: '+ver)
return {'return':0, 'version_str':ver,
'version_lst':sver,
'version_raw':lst}
##############################################################################
# setup environment for a given software -
# it is a low level routine which ask you the exact path to the tool and its version
def setup(i):
"""
Input: {
(host_os) - host OS (detect, if omitted)
(target_os) - target OS (detect, if omitted)
(target_device_id) - target device ID (detect, if omitted)
(data_uoa) or (uoa) - soft configuration UOA
or
(tags) - search UOA by tags (separated by comma)
(soft_name) - use this user friendly name for environment entry
(soft_add_name) - add extra name to above name (such as anaconda)
(customize) - dict with custom parameters
(usually passed to customize script)
skip_add_dirs
skip_add_to_path
skip_add_to_bin
skip_add_to_ld_path
add_include_path
skip_path - skiping installation path (for local versions)
version - add this version
skip_version - if 'yes', do not add version
(skip_path) - skiping installation path (for local versions)
(env) - update default env with this dict
(deps) - list with dependencies (in special format, possibly resolved (from package))
(install_path) - path with soft is installed
(full_path) - full path to a tool or library (install_path will be calculated automatically)
(bat_file) - if !='', record environment to this bat file,
instead of creating env entry
(quiet) - if 'yes', minimize questions
(env_data_uoa) - use this data UOA to record (new) env
(env_repo_uoa) - use this repo to record new env
(env_new) - if 'yes', do not search for environment (was already done in package, for example)
(package_uoa) - if called from package, record package_uoa just in case
(reset_env) - if 'yes', do not use environment from existing entry, but use original one
(extra_version) - add extra version, when registering software
(for example, -trunk-20160421)
(skip_device_info_collection) - if 'yes', do not collect device info
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
env_data_uoa - environment entry UOA
env_data_uid - environment entry UID
deps - resolved dependencies (if any)
}
"""
import os
import json
o=i.get('out','')
env_new=i.get('env_new','')
########################################################################
# Check host/target OS/CPU
hos=i.get('host_os','')
tos=i.get('target_os','')
tdid=i.get('target_device_id','')
if tdid=='': tdid=i.get('device_id','')
ii={'action':'detect',
'module_uoa':cfg['module_deps']['platform.os'],
'host_os':hos,
'target_os':tos,
'target_device_id':tdid,
'skip_info_collection':'no'}
if i.get('skip_device_info_collection','')=='yes':
ii['skip_info_collection']='yes'
r=ck.access(ii)
if r['return']>0: return r
features=r.get('features',{})
hos=r['host_os_uid']
hosx=r['host_os_uoa']
hosd=r['host_os_dict']
tos=r['os_uid']
tosx=r['os_uoa']
tosd=r['os_dict']
tbits=tosd.get('bits','')
hplat=hosd['ck_name']
tplat=tosd['ck_name']
# Check if base is different
x1=hosd.get('base_uid','')
x2=hosd.get('base_uoa','')
if x1!='' and x2!='':
hos=x1
hosx=x2
x1=tosd.get('base_uid','')
x2=tosd.get('base_uoa','')
if x1!='' and x2!='':
tos=x1
tosx=x2
# Check soft UOA
duoa=i.get('uoa','')
if duoa=='': duoa=i.get('data_uoa','')
tags=i.get('tags','')
if duoa=='':
xcids=i.get('xcids',[])
if len(xcids)>0:
duoa=xcids[0].get('data_uoa','')
duid=duoa
if duoa=='' and tags!='':
r=ck.access({'action':'search',
'module_uoa':work['self_module_uid'],
'tags':tags})
if r['return']>0: return r
l=r['lst']
if len(l)>0:
duid=l[0].get('data_uid')
duoa=duid
d={}
p=''
########################################################################
if duoa=='':
# Try to detect CID in current path
rx=ck.detect_cid_in_current_path({})
if rx['return']==0:
duoa=rx.get('data_uoa','')
if duoa!='':
# Load defined or found soft entry
r=ck.access({'action':'load',
'module_uoa':work['self_module_uid'],
'data_uoa':duoa})
if r['return']>0: return r
d=r['dict']
p=r['path']
duoa=r['data_uoa']
duid=r['data_uid']
if duoa=='':
try:
p=os.getcwd()
except OSError:
os.chdir('..')
p=os.getcwd()
pc=os.path.join(p, ck.cfg['subdir_ck_ext'], ck.cfg['file_meta'])
found=False
if os.path.isfile(pc):
r=ck.load_json_file({'json_file':pc})
if r['return']==0:
d=r['dict']
found=True
if not found:
return {'return':1, 'error':'software UOA (data_uoa) is not defined'}
if o=='con':
if duoa!='' and duid!='':
x=': '+duoa
if duid!=duoa: x+=' ('+duid+')'
else:
x=' in local directory'
ck.out(' Software entry found'+x)
# Check deps, customize, install path
ltags=d.get('tags',[])
deps=d.get('deps',{})
env=d.get('env',{})
cus=d.get('customize',{})
pi=''
envp=cus.get('env_prefix','')
envps=envp+'_SET'
san=i.get('soft_add_name','')
dname=d.get('soft_name','')
if i.get('soft_name','')!='':
dname=i['soft_name']
else:
if cus.get('package_extra_name','')!='':
dname+=cus['package_extra_name']
if san!='':
dname+=san
csp=d.get('can_skip_path','')
ev=i.get('extra_version','')
if ev=='':
ev=cus.get('extra_version','')
# Add tags from the search!
for q in tags.split(','):
q1=q.strip()
if q1!='' and q1 not in ltags: ltags.append(q1)
# Finish tags
tg='host-os-'+hosx
if tg not in ltags: ltags.append(tg)
tg='target-os-'+tosx
if tg not in ltags: ltags.append(tg)
tg=tbits+'bits'
if tg not in ltags: ltags.append(tg)
########################################################################
# Check if environment already set (preload to update)
enduoa=i.get('env_data_uoa','')
enruoa=i.get('env_repo_uoa','')
update=False
if enduoa!='':
rx=ck.access({'action':'load',
'module_uoa':cfg['module_deps']['env'],
'data_uoa':enduoa,
'repo_uoa':enruoa})
if rx['return']==0:
update=True
edx=rx['dict']
cus.update(edx.get('customize',{}))
deps=edx.get('deps',{})
if i.get('reset_env','')!='yes' and 'tmp' not in edx.get('tags',[]):
env=edx.get('env',{})
pi=cus.get('path_install','')
# Update from input
udeps=i.get('deps',{})
deps.update(udeps)
uenv=i.get('env',{})
env.update(uenv)
ucus=i.get('customize',{})
cus.update(ucus)
pi1=i.get('install_path','')
if pi1!='': pi=pi1
fp=i.get('full_path','')
########################################################################
# Check meta
setup={'host_os_uoa':hos,
'target_os_uoa':tos,
'target_os_bits':tbits}
# Resolve deps (if not ignored, such as when installing local version with all dependencies set)
if cus.get('ignore_deps','')=='yes':
deps={}
sdeps=''
sdeps1=''
if len(deps)>0:
ii={'action':'resolve',
'module_uoa':cfg['module_deps']['env'],
'host_os':hos,
'target_os':tos,
'target_device_id':tdid,
'repo_uoa':enruoa,
'deps':deps}
if o=='con': ii['out']='con'
rx=ck.access(ii)
if rx['return']>0: return rx
sdeps=rx['bat']
sdeps1=rx['cut_bat']
deps=rx['deps'] # Update deps (add UOA)
for q in deps:
v=deps[q]
vuoa=v.get('uoa','') # can be undefined if OS specific
if vuoa!='': setup['deps_'+q]=vuoa
# Check if customize script is redirected into another entry:
#
another_entry_with_customize_script=d.get('use_customize_script_from_another_entry', None)
if another_entry_with_customize_script:
r=ck.access({'action':'find',
'module_uoa': another_entry_with_customize_script.get('module_uoa', work['self_module_uid']),
'data_uoa': another_entry_with_customize_script.get('data_uoa','')
})
if r['return']>0: return r
customization_script_path = r['path']
else:
customization_script_path = p
cs=None
rx=ck.load_module_from_path({'path':customization_script_path, 'module_code_name':cfg['custom_script_name'], 'data_uoa':duoa ,'cfg':d, 'skip_init':'yes'})
if rx['return']==0:
cs=rx['code']
elif another_entry_with_customize_script or not rx['error'].startswith("can't find module code"):
return rx
########################################################################
########################################################################
########################################################################
########################################################################
# Starting processing soft
# Check via full path first
if pi=='' and fp=='' and o=='con' and cus.get('skip_path','')!='yes' and i.get('skip_path','')!='yes' and not update:
ck.out('')
ry=prepare_target_name({'host_os_dict':hosd,
'target_os_dict':tosd,
'cus':cus})
if ry['return']>0: return ry
sname=ry['tool']
y0='installed library, tool or script'
if sname!='':
suname=d.get('soft_name','')
if cus.get('skip_soft_file_is_asked','')=='yes':
if suname!='': y0=suname
else:
y0=sname
if suname!='': y0=suname+' ('+sname+')'
y1='full path to '+y0
y2=''
y3=cus.get('soft_path_example',{}).get(hplat,'')
if y3!='': y2=' (example: '+y3+')'
r=ck.inp({'text':'Enter '+y1+y2+': '})
fp=r['string'].strip()
# Check if file really exists and check version if a tool
ver=cus.get('version','')
vercus=ver
if fp!='':
if cus.get('skip_file_check','')!='yes' and not os.path.exists(fp):
return {'return':1, 'error':'software not found in a specified path ('+fp+')'}
skip_existing='no'
if cus.get('force_cmd_version_detection','')=='yes':
skip_existing='yes'
ver=''
if ver=='':
soft_version_cmd=cus.get('soft_version_cmd',{}).get(hplat,'')
if o=='con':
ck.out('')
ck.out(' Attempting to detect version automatically (if supported) ...')
# Check version (via customized script) ...
ii={'full_path':fp,
'bat':sdeps,
'host_os_dict':hosd,
'target_os_dict':tosd,
'cmd':soft_version_cmd,
'customize':cus,
'custom_script_obj':cs,
'skip_existing':skip_existing,
'skip_add_target_file':cus.get('soft_version_skip_add_target_file',''),
'use_locale':cus.get('use_locale_for_version',''),
'data_uid': duid,
}
rx=get_version(ii)
if rx['return']==0:
ver=rx['version']
if o=='con':
ck.out('')
ck.out(' Detected version: '+ver)
elif rx['return']!=16 and rx['return']!=22:
return rx
else:
if o=='con':
ck.out('')
ck.out(' WARNING: didn\'t manage to automatically detect software version!')
########################################################################
# Get various git info ...
ss1=''
ss2=''
ss3=''
ss4=''
ss5=''
ver_to_search=ver
if cus.get('use_git_revision','')=='yes':
import datetime
psrc=cus.get('git_src_dir','')
dfp=i.get('full_path_install','')
if dfp!='':
if psrc!='':
dfp=os.path.join(dfp, psrc)
try:
pwd1=os.getcwd()
except OSError:
os.chdir('..')
pwd1=os.getcwd()
if os.path.isdir(dfp):
os.chdir(dfp)
r=ck.access({'action':'run_and_get_stdout',
'module_uoa':cfg['module_deps']['os'],
'cmd':['git','rev-parse','--short','HEAD']})
if r['return']==0 and r['return_code']==0:
ss1=r['stdout'].strip()
r=ck.access({'action':'run_and_get_stdout',
'module_uoa':cfg['module_deps']['os'],
'cmd':['git','log','-1','--format=%cd']})
if r['return']==0 and r['return_code']==0:
ss2=r['stdout'].strip()
if ss2!='':
ss2x=ss2
j=ss2x.find(' +')
if j<0:
j=ss2x.find(' -')
if j>0:
ss2x=ss2[:j]
x=datetime.datetime.strptime(ss2x, '%a %b %d %H:%M:%S %Y')
ss3=x.isoformat()
ss4=ss3[:10].replace('-','')
if ss1!='':
ss5=ss4+'-'+ss1
if 'git_info' not in cus:
cus['git_info']={}
cus['git_info']['revision']=ss1
cus['git_info']['datetime']=ss2
cus['git_info']['iso_datetime']=ss3
cus['git_info']['iso_datetime_cut']=ss4
cus['git_info']['iso_datetime_cut_revision']=ss5
if o=='con':
ck.out('')
if ss1!='':
ck.out('Detected GIT revision: '+ss1)
if ss2!='':
ck.out('Detected GIT date time of last commit: '+ss2)
os.chdir(pwd1)
ver+='-'+ss1
########################################################################
# Ask for version if was not detected or is not explicitly specified (for example, from a package)
if ver=='' and cus.get('skip_version','')!='yes' and o=='con':
ck.out('')
r=ck.inp({'text':'Enter version of this software (for example, 3.21.6-2 or press Enter if default/unknown): '})
ver=r['string'].strip().lower()
ver_to_search=ver
# Add extra, if needed (useful for changing trunks)
if ev!='':
ver+=ev
ver_to_search+=ev
# If cutomized version has changed, try to check env again ...
if vercus!=ver:
env_new='no'
# Split version
rx=split_version({'version':ver})
if rx['return']>0: return rx
sver=rx['version_split']
# Add version to setup and separate into tags
setup['version']=ver_to_search
setup['version_split']=sver
# Prepare tags from version
if ver!='':
x=''
for q in sver:
if x!='':x+='.'
x+=str(q)
tg='v'+x
if tg not in ltags:
ltags.append(tg)
unsplit_version_tag_prefix = cus.get('unsplit_version_to_tags_prefixed_with')
if unsplit_version_tag_prefix != None: # NB: empty string is treated differently from absence!
ltags.append( unsplit_version_tag_prefix + ver_to_search )
tags_csv = ','.join( [t.strip() for t in ltags if t] )
########################################################################
# Search if environment is already registered for this version
# (to delete or reuse it)
finish=False
if enduoa=='' and env_new!='yes':
if o=='con':
ck.out('')
ck.out('Searching if environment already exists using:')
ck.out(' * Tags: '+tags_csv)
if len(deps)>0:
for q in deps:
v=deps[q]
vuoa=v.get('uoa','')
if vuoa!='':
ck.out(' * Dependency: '+q+'='+v.get('uoa',''))
r=ck.access({'action':'search',
'module_uoa':cfg['module_deps']['env'],
'repo_uoa':enruoa,
'tags':tags_csv,
'search_dict':{'setup':setup}})
if r['return']>0: return r
lst=r['lst']
if len(lst)>0:
fe=lst[0]
enduoa=fe['data_uoa']
enduid=fe['data_uid']
if o=='con':
x=enduoa
if enduid!=enduoa: x+=' ('+enduid+')'
ck.out('')
ck.out('Environment already registered for this version: '+x)
update=False
if i.get('update','')=='yes':
update=True
if not update:
if o=='con':
ck.out('')
r=ck.inp({'text':'Would you like to delete this entry and re-register environment (Y/n): '})
dl=r['string'].strip().lower()
if dl=='' or dl=='y' or dl=='yes':
update=False
rx=ck.access({'action':'delete',
'module_uoa':cfg['module_deps']['env'],
'data_uoa':enduoa,
'repo_uoa':enruoa})
if rx['return']>0: return rx
else:
ck.out('')
r=ck.inp({'text':'Would you like to update this entry (Y/n): '})
upd=r['string'].strip().lower()
if upd=='' or upd=='y' or upd=='yes':
update=True
else:
finish=True
if update:
rx=ck.access({'action':'load',
'module_uoa':cfg['module_deps']['env'],
'data_uoa':enduoa,
'repo_uoa':enruoa})
if rx['return']>0: return rx
edx=rx['dict']
cus1=edx.get('customize',{})
deps1=edx.get('deps',{})
env1=edx.get('env',{})
cus.update(cus1)
deps.update(deps1)
env.update(env1)
pi=cus.get('path_install','')
else:
if o=='con':
ck.out('')
ck.out(' Environment with above tags is not yet registered in CK ...')
############################################################
if not finish:
# Prepare environment and batch
sb=''
if o=='out':
ck.out('')
ck.out('Preparing environment and batch file ...')
sdirs=hosd.get('dir_sep','')
wb=tosd.get('windows_base','')
rem=hosd.get('rem','')
eset=hosd.get('env_set','')
svarb=hosd.get('env_var_start','')
svare=hosd.get('env_var_stop','')
evs=hosd.get('env_var_separator','')
eifs=hosd.get('env_quotes_if_space','')
ellp=hosd.get('env_ld_library_path','')
if ellp=='': ellp='LD_LIBRARY_PATH'
elp=hosd.get('env_library_path','')
if elp=='': elp='LIBRARY_PATH'
# Check installation path
if fp=='' and cus.get('skip_path','')!='yes' and i.get('skip_path','')!='yes' and not update:
if o=='con':
# if update:
# ck.out('')
# ck.out('Current path to installed tool: '+pi)
# r=ck.inp({'text':'Input new path to installed tool or press Enter to keep old: '})
# pix=r['string'].strip()
# if pix!='': pi=pix
if pi=='':
ck.out('')
ye=cus.get('input_path_example','')
if ye!='': y=' (example: '+ye+')'
else: y=''
y1=cus.get('input_path_text','')
if y1=='': y1='path to installed software (root directory possibly pointing to bin, lib, include, etc)'
r=ck.inp({'text':'Enter '+y1+y+': '})
pi=r['string'].strip().strip('"')
ipr=cus.get('input_path_remove','')
if ipr!='' and ipr>0:
for q in range(0,ipr):
try:
pi=os.path.split(pi)[0]
except:
pass
if pi=='' and csp!='yes':
return {'return':1, 'error':'installation path is not specified'}
if fp!='':
cus['full_path']=fp
if pi!='':
cus['path_install']=pi
### OLD start
if cus.get('skip_add_dirs','')!='yes' and pi!='':
if cus.get('add_include_path','')=='yes' and cus.get('path_include','')=='':
pii=pi+sdirs+'include'
cus['path_include']=pii
if cus.get('skip_add_to_bin','')!='yes':
pib=pi
if cus.get('skip_add_bin_ext','')!='yes': pib+=sdirs+'bin'
cus['path_bin']=pib
if cus.get('skip_add_to_ld_path','')!='yes' and cus.get('path_lib','')=='':
plib=pi+sdirs+'lib64'
if not os.path.isdir(plib):
plib=pi+sdirs+'lib32'
if not os.path.isdir(plib):
plib=pi+sdirs+'lib'
if not os.path.isdir(plib):
return {'return':1, 'error':'can\'t find lib path'}
cus['path_lib']=plib
else:
cus['skip_path']='yes'
### OLD stop
# If install path has space, add quotes for some OS ...
xs=''
if pi.find(' ')>=0 and eifs!='':
xs=eifs