-
Notifications
You must be signed in to change notification settings - Fork 10
/
dirac-install.py
executable file
·2755 lines (2397 loc) · 97.2 KB
/
dirac-install.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
#!/usr/bin/env python
"""
The main DIRAC installer script. It can be used to install the main DIRAC software, its
modules, web, rest etc. and DIRAC extensions.
In order to deploy DIRAC you have to provide: globalDefaultsURL, which is by default:
"http://diracproject.web.cern.ch/diracproject/configs/globalDefaults.cfg", but it can be
in the local file system in a separate directory. The content of this file is the following::
Installations
{
DIRAC
{
DefaultsLocation = http://diracproject.web.cern.ch/diracproject/dirac.cfg
LocalInstallation
{
PythonVersion = 27
}
# in case you have a DIRAC extension
LHCb
{
DefaultsLocation = http://lhcb-rpm.web.cern.ch/lhcb-rpm/lhcbdirac/lhcb.cfg
}
}
}
Projects
{
DIRAC
{
DefaultsLocation = http://diracproject.web.cern.ch/diracproject/dirac.cfg
}
# in case you have a DIRAC extension
LHCb
{
DefaultsLocation = http://lhcb-rpm.web.cern.ch/lhcb-rpm/lhcbdirac/lhcb.cfg
}
}
the DefaultsLocation for example::
DefaultsLocation = http://diracproject.web.cern.ch/diracproject/dirac.cfg
must contain a minimal configuration. The following options must be in this
file::
Releases=,UploadCommand=,BaseURL=
In case you want to overwrite the global configuration file, you have to use --defaultsURL
After providing the default configuration files, DIRAC or your extension can be installed from:
1. in a directory you have to be present globalDefaults.cfg, dirac.cfg and all binaries.
For example::
zmathe@dzmathe zmathe]$ ls tars/
dirac.cfg diracos-0.1.md5 diracos-0.1.tar.gz DIRAC-v6r20-pre16.md5 DIRAC-v6r20-pre16.tar.gz
globalDefaults.cfg release-DIRAC-v6r20-pre16.cfg release-DIRAC-v6r20-pre16.md5
zmathe@dzmathe zmathe]$
For example::
dirac-install -r v6r20-pre16 --dirac-os --dirac-os-version=0.0.1 -u /home/zmathe/tars
this command will use /home/zmathe/tars directory for the source code.
It will install DIRAC v6r20-pre16, DIRAC OS 0.1 version
2. You can use your dedicated web server or the official DIRAC web server
for example::
dirac-install -r v6r20-pre16 --dirac-os --dirac-os-version=0.0.1
It will install DIRAC v6r20-pre16
You can install an extension of diracos.
for example::
dirac-install -r v9r4-pre2 -l LHCb --dirac-os --dirac-os-version=LHCb:master
3. You have possibility to install a not-yet-released DIRAC, module or extension using -m or --tag options.
The non release version can be specified.
for example::
dirac-install -l DIRAC -r v6r20-pre16 -g v14r0 -t client -m DIRAC --tag=integration
It will install DIRAC v6r20-pre16, where the DIRAC package based on integration, other other packages will be
the same what is specified in release.cfg file in v6r20-pre16 tarball.
dirac-install -l DIRAC -r v6r20-pre16 -g v14r0 -t client -m DIRAC --tag=v6r20-pre22
It installs a specific tag
Note: If the source is not provided, DIRAC repository is used, which is defined in the global
configuration file.
We can provide the repository url:code repository:::Project:::branch. for example::
dirac-install -l DIRAC -r v6r20-pre16 -g v14r0 -t client \\
-m https://github.com/zmathe/DIRAC.git:::DIRAC:::dev_main_branch, \\
https://github.com/zmathe/WebAppDIRAC.git:::WebAppDIRAC:::extjs6 -e WebAppDIRAC
it will install DIRAC based on dev_main_branch and WebAppDIRAC based on extjs6::
dirac-install -l DIRAC -r v6r20-pre16 -g v14r0 -t client \\
-m WebAppDIRAC --tag=integration -e WebAppDIRAC
it will install DIRAC v6r20-pre16 and WebAppDIRAC integration branch
You can use install.cfg configuration file::
DIRACOS = http://lhcb-rpm.web.cern.ch/lhcb-rpm/dirac/DIRACOS/
WebAppDIRAC = https://github.com/zmathe/WebAppDIRAC.git
DIRAC=https://github.com/DIRACGrid/DIRAC.git
LocalInstallation
{
# Project = LHCbDIRAC
# The project LHCbDIRAC is not defined in the globalsDefaults.cfg
Project = LHCb
Release = v9r2-pre8
Extensions = LHCb
ConfigurationServer = dips://lhcb-conf-dirac.cern.ch:9135/Configuration/Server
Setup = LHCb-Production
SkipCAChecks = True
SkipCADownload = True
WebAppDIRAC=extjs6
DIRAC=rel-v6r20
}
dirac-install -l LHCb -r v9r2-pre8 -t server --dirac-os --dirac-os-version=0.0.6 install.cfg
"""
from __future__ import unicode_literals, absolute_import, division, print_function
import sys
import os
import getopt
import imp
import signal
import time
import stat
import shutil
import subprocess
import ssl
import hashlib
from distutils.version import LooseVersion # pylint: disable=no-name-in-module,import-error
try:
# For Python 3.0 and later
from urllib.request import urlopen, HTTPError, URLError
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen, HTTPError, URLError
try:
str_type = basestring
except NameError:
str_type = str
__RCSID__ = "$Id$"
executablePerms = stat.S_IWUSR | stat.S_IRUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
def S_OK(value=""):
return {'OK': True, 'Value': value}
def S_ERROR(msg=""):
return {'OK': False, 'Message': msg}
############
# Start of CFG
############
class Params(object):
def __init__(self):
self.extensions = []
self.project = 'DIRAC'
self.installation = 'DIRAC'
self.release = ""
self.externalsType = 'client'
self.pythonVersion = '27'
self.platform = ""
self.basePath = os.getcwd()
self.targetPath = os.getcwd()
self.buildExternals = False
self.noAutoBuild = False
self.debug = False
self.externalsOnly = False
self.lcgVer = ''
self.noLcg = False
self.useVersionsDir = False
self.installSource = ""
self.globalDefaults = False
self.timeout = 300
self.diracOSVersion = ''
self.diracOS = False
self.tag = ""
self.modules = {}
self.externalVersion = ""
self.createLink = False
self.scriptSymlink = False
self.userEnvVariables = {}
cliParams = Params()
###
# Release config manager
###
class ReleaseConfig(object):
class CFG(object):
def __init__(self, cfgData=""):
""" c'tor
:param self: self reference
:param str cfgData: the content of the configuration file
"""
self.data = {}
self.children = {}
if cfgData:
self.parse(cfgData)
def parse(self, cfgData):
"""
It parses the configuration file and propagate the data and children
with the content of the cfg file
:param str cfgData: configuration data, which is the content of the configuration file
"""
try:
self.__parse(cfgData)
except BaseException:
import traceback
traceback.print_exc()
raise
return self
def getChild(self, path):
"""
It return the child of a given section
:param str, list, tuple path: for example: Installations/DIRAC, Projects/DIRAC
:return object It returns a CFG instance
"""
child = self
if isinstance(path, (list, tuple)):
pathList = path
else:
pathList = [sec.strip() for sec in path.split("/") if sec.strip()]
for childName in pathList:
if childName not in child.children:
return False
child = child.children[childName]
return child
def __parse(self, cfgData, cIndex=0):
"""
It parse a given DIRAC cfg file and store the result in self.data variable.
:param str cfgData: the content of the configuration file
:param int cIndex: it is the new line counter
"""
childName = ""
numLine = 0
while cIndex < len(cfgData):
eol = cfgData.find("\n", cIndex)
if eol < cIndex:
# End?
return cIndex
numLine += 1
if eol == cIndex:
cIndex += 1
continue
line = cfgData[cIndex: eol].strip()
# Jump EOL
cIndex = eol + 1
if not line or line[0] == "#":
continue
if line.find("+=") > -1:
fields = line.split("+=")
opName = fields[0].strip()
if opName in self.data:
self.data[opName] += ', %s' % '+='.join(fields[1:]).strip()
else:
self.data[opName] = '+='.join(fields[1:]).strip()
continue
if line.find("=") > -1:
fields = line.split("=")
self.data[fields[0].strip()] = "=".join(fields[1:]).strip()
continue
opFound = line.find("{")
if opFound > -1:
childName += line[:opFound].strip()
if not childName:
raise Exception("No section name defined for opening in line %s" % numLine)
childName = childName.strip()
self.children[childName] = ReleaseConfig.CFG()
eoc = self.children[childName].__parse(cfgData, cIndex)
cIndex = eoc
childName = ""
continue
if line == "}":
return cIndex
# Must be name for section
childName += line.strip()
return cIndex
def createSection(self, name, cfg=None):
"""
It creates a subsection for an existing CS section.
:param str name: the name of the section
:param object cfg: the ReleaseConfig.CFG object loaded into memory
"""
if isinstance(name, (list, tuple)):
pathList = name
else:
pathList = [sec.strip() for sec in name.split("/") if sec.strip()]
parent = self
for lev in pathList[:-1]:
if lev not in parent.children:
parent.children[lev] = ReleaseConfig.CFG()
parent = parent.children[lev]
secName = pathList[-1]
if secName not in parent.children:
if not cfg:
cfg = ReleaseConfig.CFG()
parent.children[secName] = cfg
return parent.children[secName]
def isSection(self, obList):
"""
Checks if a given path is a section
:param str objList: is a path: for example: Releases/v6r20-pre16
"""
return self.__exists([ob.strip() for ob in obList.split("/") if ob.strip()]) == 2
def sections(self):
"""
Returns all sections
"""
return [k for k in self.children]
def isOption(self, obList):
return self.__exists([ob.strip() for ob in obList.split("/") if ob.strip()]) == 1
def options(self):
"""
Returns the options
"""
return [k for k in self.data]
def __exists(self, obList):
"""
Check the existence of a certain element
:param list obList: the list of cfg element names.
for example: [Releases,v6r20-pre16]
"""
if len(obList) == 1:
if obList[0] in self.children:
return 2
elif obList[0] in self.data:
return 1
else:
return 0
if obList[0] in self.children:
return self.children[obList[0]].__exists(obList[1:])
return 0
def get(self, opName, defaultValue=None):
"""
It return the value of a certain option
:param str opName: the name of the option
:param str defaultValue: the default value of a given option
"""
try:
value = self.__get([op.strip() for op in opName.split("/") if op.strip()])
except KeyError:
if defaultValue is not None:
return defaultValue
raise
if defaultValue is None:
return value
defType = type(defaultValue)
if isinstance(defType, bool):
return value.lower() in ("1", "true", "yes")
try:
return defType(value)
except ValueError:
return defaultValue
def __get(self, obList):
"""
It return a given section
:param list obList: the list of cfg element names.
"""
if len(obList) == 1:
if obList[0] in self.data:
return self.data[obList[0]]
raise KeyError("Missing option %s" % obList[0])
if obList[0] in self.children:
return self.children[obList[0]].__get(obList[1:])
raise KeyError("Missing section %s" % obList[0])
def toString(self, tabs=0):
"""
It return the configuration file as a string
:param int tabs: the number of tabs used to format the CS string
"""
lines = ["%s%s = %s" % (" " * tabs, opName, self.data[opName]) for opName in self.data]
for secName in self.children:
lines.append("%s%s" % (" " * tabs, secName))
lines.append("%s{" % (" " * tabs))
lines.append(self.children[secName].toString(tabs + 1))
lines.append("%s}" % (" " * tabs))
return "\n".join(lines)
def getOptions(self, path=""):
"""
Rturns the options for a given path
:param str path: the path to the CS element
"""
parentPath = [sec.strip() for sec in path.split("/") if sec.strip()][:-1]
if parentPath:
parent = self.getChild(parentPath)
else:
parent = self
if not parent:
return []
return tuple(parent.data)
def delPath(self, path):
"""
It deletes a given CS element
:param str path: the path to the CS element
"""
path = [sec.strip() for sec in path.split("/") if sec.strip()]
if not path:
return
keyName = path[-1]
parentPath = path[:-1]
if parentPath:
parent = self.getChild(parentPath)
else:
parent = self
if parent:
parent.data.pop(keyName)
def update(self, path, cfg):
"""
Used to update the CS
:param str path: path to the CS element
:param object cfg: the CS object
"""
parent = self.getChild(path)
if not parent:
self.createSection(path, cfg)
return
parent.__apply(cfg)
def __apply(self, cfg):
"""
It adds a certain cfg subsection to a given section
:param object cfg: the CS object
"""
for k in cfg.sections():
if k in self.children:
self.children[k].__apply(cfg.getChild(k))
else:
self.children[k] = cfg.getChild(k)
for k in cfg.options():
self.data[k] = cfg.get(k)
############################################################################
# END OF CFG CLASS
############################################################################
def __init__(self, instName='DIRAC', projectName='DIRAC', globalDefaultsURL=None):
""" c'tor
:param str instName: the name of the installation
:param str projectName: the name of the project
:param str globalDefaultsURL: the default url
"""
self.user_globalDefaultsURL = globalDefaultsURL
self.globalDefaults = ReleaseConfig.CFG()
self.loadedCfgs = []
self.prjDepends = {}
self.diracBaseModules = {}
self.prjRelCFG = {}
self.projectsLoadedBy = {}
self.cfgCache = {}
self.debugCB = False
self.instName = instName
self.projectName = projectName
def setDebugCB(self, debFunc):
"""
It is used by the dirac-distribution. It sets the debug function
"""
self.debugCB = debFunc
def __dbgMsg(self, msg):
"""
:param str msg: the debug message
"""
if self.debugCB:
self.debugCB(msg)
def __loadCFGFromURL(self, urlcfg, checkHash=False):
"""
It is used to load the configuration file
:param str urlcfg: the location of the source repository and
where the default configuration file is exists.
:param bool checkHash: check if the file is corrupted.
"""
# This can be a local file
if os.path.exists(urlcfg):
with open(urlcfg, 'r') as relFile:
cfgData = relFile.read()
else:
if urlcfg in self.cfgCache:
return S_OK(self.cfgCache[urlcfg])
try:
cfgData = urlretrieveTimeout(urlcfg, timeout=cliParams.timeout)
if not cfgData:
return S_ERROR("Could not get data from %s" % urlcfg)
except BaseException:
return S_ERROR("Could not open %s" % urlcfg)
try:
# cfgData = cfgFile.read()
cfg = ReleaseConfig.CFG(cfgData)
except Exception as excp:
return S_ERROR("Could not parse %s: %s" % (urlcfg, excp))
# cfgFile.close()
if not checkHash:
self.cfgCache[urlcfg] = cfg
return S_OK(cfg)
try:
md5path = urlcfg[:-4] + ".md5"
if os.path.exists(md5path):
md5File = open(md5path, 'r')
md5Data = md5File.read()
md5File.close()
else:
md5Data = urlretrieveTimeout(md5path, timeout=60)
md5Hex = md5Data.strip()
# md5File.close()
if md5Hex != hashlib.md5(cfgData.encode('utf-8')).hexdigest():
return S_ERROR("Hash check failed on %s" % urlcfg)
except Exception as excp:
return S_ERROR("Hash check failed on %s: %s" % (urlcfg, excp))
self.cfgCache[urlcfg] = cfg
return S_OK(cfg)
def loadInstallationDefaults(self):
"""
Load the default configurations
"""
result = self.__loadGlobalDefaults()
if not result['OK']:
return result
return self.__loadObjectDefaults("Installations", self.instName)
def loadProjectDefaults(self):
"""
Load default configurations
"""
result = self.__loadGlobalDefaults()
if not result['OK']:
return result
return self.__loadObjectDefaults("Projects", self.projectName)
def __loadGlobalDefaults(self):
"""
It loads the default configuration files
"""
globalDefaultsURL = self.user_globalDefaultsURL or "/cvmfs/dirac.egi.eu/admin/globalDefaults.cfg"
self.__dbgMsg("Loading global defaults from: %s" % globalDefaultsURL)
result = self.__loadCFGFromURL(globalDefaultsURL)
if not result['OK']:
default_globalDefaultsURL = "http://diracproject.web.cern.ch/diracproject/configs/globalDefaults.cfg"
self.__dbgMsg("Loading global defaults from: %s" % default_globalDefaultsURL)
result = self.__loadCFGFromURL(default_globalDefaultsURL)
if not result['OK']:
return result
self.globalDefaults = result['Value']
for k in ("Installations", "Projects"):
if not self.globalDefaults.isSection(k):
self.globalDefaults.createSection(k)
self.__dbgMsg("Loaded global defaults")
return S_OK()
def __loadObjectDefaults(self, rootPath, objectName):
"""
It loads the CFG, if it is not loaded.
:param str rootPath: the main section. for example: Installations
:param str objectName: The name of the section. for example: DIRAC
"""
basePath = "%s/%s" % (rootPath, objectName)
if basePath in self.loadedCfgs:
return S_OK()
# Check if it's a direct alias
try:
aliasTo = self.globalDefaults.get(basePath)
except KeyError:
aliasTo = False
if aliasTo:
self.__dbgMsg("%s is an alias to %s" % (objectName, aliasTo))
result = self.__loadObjectDefaults(rootPath, aliasTo)
if not result['OK']:
return result
cfg = result['Value']
self.globalDefaults.update(basePath, cfg)
return S_OK()
# Load the defaults
if self.globalDefaults.get("%s/SkipDefaults" % basePath, False):
defaultsLocation = ""
else:
defaultsLocation = self.globalDefaults.get("%s/DefaultsLocation" % basePath, "")
if not defaultsLocation:
self.__dbgMsg("No defaults file defined for %s %s" % (rootPath.lower()[:-1], objectName))
else:
self.__dbgMsg("Defaults for %s are in %s" % (basePath, defaultsLocation))
result = self.__loadCFGFromURL(defaultsLocation)
if not result['OK']:
return result
cfg = result['Value']
self.globalDefaults.update(basePath, cfg)
# Check if the defaults have a sub alias
try:
aliasTo = self.globalDefaults.get("%s/Alias" % basePath)
except KeyError:
aliasTo = False
if aliasTo:
self.__dbgMsg("%s is an alias to %s" % (objectName, aliasTo))
result = self.__loadObjectDefaults(rootPath, aliasTo)
if not result['OK']:
return result
cfg = result['Value']
self.globalDefaults.update(basePath, cfg)
self.loadedCfgs.append(basePath)
return S_OK(self.globalDefaults.getChild(basePath))
def loadInstallationLocalDefaults(self, args):
"""
Load the configuration file from a file
:param str args: the arguments in which to look for configuration file names
"""
# at the end we load the local configuration and merge it with the global cfg
argList = list(args)
if os.path.exists('etc/dirac.cfg') and 'etc/dirac.cfg' not in args:
argList = ['etc/dirac.cfg'] + argList
for arg in argList:
if arg.endswith(".cfg") and ':::' not in arg:
fileName = arg
else:
continue
logNOTICE("Defaults for LocalInstallation are in %s" % fileName)
try:
fd = open(fileName, "r")
cfg = ReleaseConfig.CFG().parse(fd.read())
fd.close()
except Exception as excp:
logERROR("Could not load %s: %s" % (fileName, excp))
continue
self.globalDefaults.update("Installations/%s" % self.instName, cfg)
self.globalDefaults.update("Projects/%s" % self.instName, cfg)
if self.projectName:
# we have an extension and have a local cfg file
self.globalDefaults.update("Projects/%s" % self.projectName, cfg)
logNOTICE("Loaded %s" % arg)
def getModuleVersionFromLocalCfg(self, moduleName):
"""
It returns the version of a certain module defined in the LocalInstallation section
:param str moduleName:
:return str: the version of a certain module
"""
return self.globalDefaults.get("Installations/%s/LocalInstallation/%s" % (self.instName, moduleName), "")
def getInstallationCFG(self, instName=None):
"""
Returns the installation name
:param str instName: the installation name
"""
if not instName:
instName = self.instName
return self.globalDefaults.getChild("Installations/%s" % instName)
def getInstallationConfig(self, opName, instName=None):
"""
It returns the configurations from the Installations section.
This is usually provided in the local configuration file
:param str opName: the option name for example: LocalInstallation/Release
:param str instName:
"""
if not instName:
instName = self.instName
return self.globalDefaults.get("Installations/%s/%s" % (instName, opName))
def isProjectLoaded(self, project):
"""
Checks if the project is loaded.
:param str project: the name of the project
"""
return project in self.prjRelCFG
def getTarsLocation(self, project, module=None):
"""
Returns the location of the binaries for a given project for example: LHCb or DIRAC, etc...
:param str project: the name of the project
"""
sourceUrl = self.globalDefaults.get("Projects/%s/BaseURL" % project, "")
if module:
# in case we define a different URL in the CS
differntSourceUrl = self.globalDefaults.get("Projects/%s/%s" % (project, module), "")
if differntSourceUrl:
sourceUrl = differntSourceUrl
if sourceUrl:
return S_OK(sourceUrl)
return S_ERROR("Don't know how to find the installation tarballs for project %s" % project)
def getDiracOsLocation(self, useVanillaDiracOS=False):
"""
Returns the location of the DIRAC os binary for a given project for example: LHCb or DIRAC, etc...
:param bool useVanillaDiracOS: flag to take diracos distribution from the default location
:return: the location of the tar balls
"""
keysToConsider = []
if not useVanillaDiracOS:
keysToConsider += [
"Installations/%s/DIRACOS" % self.projectName,
"Projects/%s/DIRACOS" % self.projectName,
]
keysToConsider += [
"Installations/DIRAC/DIRACOS",
"Projects/DIRAC/DIRACOS",
]
for key in keysToConsider:
location = self.globalDefaults.get(key, "")
if location:
logDEBUG("Using DIRACOS tarball URL from configuration key %s" % key)
return location
def getUploadCommand(self, project=None):
"""
It returns the command used to upload the binary
:param str project: the name of the project
"""
if not project:
project = self.projectName
defLoc = self.globalDefaults.get("Projects/%s/UploadCommand" % project, "")
if defLoc:
return S_OK(defLoc)
return S_ERROR("No UploadCommand for %s" % project)
def __loadReleaseConfig(self, project, release, releaseMode, sourceURL=None, relLocation=None):
"""
It loads the release configuration file
:param str project: the name of the project
:param str release: the release version
:param str releaseMode: the type of the release server/client
:param str sourceURL: the source of the binary
:param str relLocation: the release configuration file
"""
if project not in self.prjRelCFG:
self.prjRelCFG[project] = {}
if release in self.prjRelCFG[project]:
self.__dbgMsg("Release config for %s:%s has already been loaded" % (project, release))
return S_OK()
if relLocation:
relcfgLoc = relLocation
else:
if releaseMode:
try:
relcfgLoc = self.globalDefaults.get("Projects/%s/Releases" % project)
except KeyError:
return S_ERROR("Missing Releases file for project %s" % project)
else:
if not sourceURL:
result = self.getTarsLocation(project)
if not result['OK']:
return result
siu = result['Value']
else:
siu = sourceURL
relcfgLoc = "%s/release-%s-%s.cfg" % (siu, project, release)
self.__dbgMsg("Releases file is %s" % relcfgLoc)
result = self.__loadCFGFromURL(relcfgLoc, checkHash=not releaseMode)
if not result['OK']:
return result
self.prjRelCFG[project][release] = result['Value']
self.__dbgMsg("Loaded releases file %s" % relcfgLoc)
return S_OK(self.prjRelCFG[project][release])
def getReleaseCFG(self, project, release):
"""
Returns the release configuration object
:param str project: the name of the project
:param str release: the release version
"""
return self.prjRelCFG[project][release]
def dumpReleasesToPath(self):
"""
It dumps the content of the loaded configuration (memory content) to
a given file
"""
for project in self.prjRelCFG:
prjRels = self.prjRelCFG[project]
for release in prjRels:
self.__dbgMsg("Dumping releases file for %s:%s" % (project, release))
fd = open(
os.path.join(
cliParams.targetPath, "releases-%s-%s.cfg" %
(project, release)), "w")
fd.write(prjRels[release].toString())
fd.close()
def __checkCircularDependencies(self, key, routePath=None):
"""
Check the dependencies
:param str key: the name of the project and the release version
:param list routePath: it stores the software packages, used to check the
dependency
"""
if not routePath:
routePath = []
if key not in self.projectsLoadedBy:
return S_OK()
routePath.insert(0, key)
for lKey in self.projectsLoadedBy[key]:
if lKey in routePath:
routePath.insert(0, lKey)
route = "->".join(["%s:%s" % sKey for sKey in routePath])
return S_ERROR("Circular dependency found for %s: %s" % ("%s:%s" % lKey, route))
result = self.__checkCircularDependencies(lKey, routePath)
if not result['OK']:
return result
routePath.pop(0)
return S_OK()
def loadProjectRelease(self, releases,
project=None,
sourceURL=None,
releaseMode=None,
relLocation=None):
"""
This method loads all project configurations (*.cfg). If a project is an extension of DIRAC,
it will load the extension and after will load the base DIRAC module.
:param list releases: list of releases, which will be loaded: for example: v6r19
:param str project: the name of the project, if it is given. For example: DIRAC
:param str sourceURL: the code repository
:param str releaseMode:
:param str relLocation: local configuration file,
which contains the releases. for example: file:///`pwd`/releases.cfg
"""
if not project:
project = self.projectName
if not isinstance(releases, (list, tuple)):
releases = [releases]
# Load defaults
result = self.__loadObjectDefaults("Projects", project)
if not result['OK']:
self.__dbgMsg("Could not load defaults for project %s" % project)
return result
if project not in self.prjDepends:
self.prjDepends[project] = {}
for release in releases:
self.__dbgMsg("Processing dependencies for %s:%s" % (project, release))
result = self.__loadReleaseConfig(project, release, releaseMode, sourceURL, relLocation)
if not result['OK']:
return result
relCFG = result['Value']
# Calculate dependencies and avoid circular deps
self.prjDepends[project][release] = [(project, release)]
relDeps = self.prjDepends[project][release]
if not relCFG.getChild("Releases/%s" % (release)): # pylint: disable=no-member
return S_ERROR(
"Release %s is not defined for project %s in the release file" %
(release, project))
initialDeps = self.getReleaseDependencies(project, release)
if initialDeps:
self.__dbgMsg("%s %s depends on %s" %
(project, release, ", ".join(["%s:%s" %
(k, initialDeps[k]) for k in initialDeps])))
relDeps.extend([(p, initialDeps[p]) for p in initialDeps])
for depProject in initialDeps:
depVersion = initialDeps[depProject]
# Check if already processed
dKey = (depProject, depVersion)
if dKey not in self.projectsLoadedBy:
self.projectsLoadedBy[dKey] = []
self.projectsLoadedBy[dKey].append((project, release))
result = self.__checkCircularDependencies(dKey)
if not result['OK']:
return result
# if it has already been processed just return OK
if len(self.projectsLoadedBy[dKey]) > 1:
return S_OK()
# Load dependencies and calculate incompatibilities
result = self.loadProjectRelease(depVersion, project=depProject)
if not result['OK']:
return result
subDep = self.prjDepends[depProject][depVersion]
# Merge dependencies
for sKey in subDep:
if sKey not in relDeps:
relDeps.append(sKey)
continue
prj, vrs = sKey
for pKey in relDeps:
if pKey[0] == prj and pKey[1] != vrs:
errMsg = "%s is required with two different versions ( %s and %s ) \
starting with %s:%s" % (prj,
pKey[1], vrs,
project, release)
return S_ERROR(errMsg)
# Same version already required
if project in relDeps and relDeps[project] != release:
errMsg = "%s:%s requires itself with a different version through dependencies ( %s )" % (
project, release, relDeps[project])
return S_ERROR(errMsg)
# we have now all dependencies, let's retrieve the resources (code repository)
for project, version in relDeps:
if project in self.diracBaseModules:
continue
modules = self.getModulesForRelease(version, project)
if modules['OK']:
for dependency in modules['Value']:
self.diracBaseModules.setdefault(dependency, {})
self.diracBaseModules[dependency]['Version'] = modules['Value'][dependency]
res = self.getModSource(version, dependency, project)
if not res['OK']:
self.__dbgMsg(
"Unable to found the source URL for %s : %s" %
(dependency, res['Message']))
else:
self.diracBaseModules[dependency]['sourceUrl'] = res['Value'][1]
return S_OK()