1- """ Definitions of a standard set of pilot commands
1+ """Definitions of a standard set of pilot commands
22
3- Each command is represented by a class inheriting from CommandBase class.
4- The command class constructor takes PilotParams object which is a data
5- structure which keeps common parameters across all the pilot commands.
3+ Each command is represented by a class inheriting from CommandBase class.
4+ The command class constructor takes PilotParams object which is a data
5+ structure which keeps common parameters across all the pilot commands.
66
7- The constructor must call the superclass constructor with the PilotParams
8- object and the command name as arguments, e.g.::
7+ The constructor must call the superclass constructor with the PilotParams
8+ object and the command name as arguments, e.g.::
99
10- class InstallDIRAC(CommandBase):
10+ class InstallDIRAC(CommandBase):
1111
12- def __init__(self, pilotParams):
13- CommandBase.__init__(self, pilotParams, 'Install')
14- ...
12+ def __init__(self, pilotParams):
13+ CommandBase.__init__(self, pilotParams, 'Install')
14+ ...
1515
16- The command class must implement execute() method for the actual command
17- execution.
16+ The command class must implement execute() method for the actual command
17+ execution.
1818"""
1919
2020from __future__ import absolute_import , division , print_function
@@ -65,7 +65,7 @@ def __init__(self, pilotParams):
6565
6666def logFinalizer (func ):
6767 """
68- PilotCammand decorator. It marks a log file as final so no more messages should be written to it .
68+ PilotCommand decorator. It marks a log file as final so no more messages should be written to it.
6969 Finalising is triggered by a return statement or any sys.exit() call, so a file might be incomplete
7070 if a command throws SystemExit exception with a code =! 0.
7171
@@ -104,6 +104,7 @@ def wrapper(self):
104104 raise
105105 finally :
106106 self .log .buffer .cancelTimer ()
107+
107108 return wrapper
108109
109110
@@ -206,17 +207,15 @@ def execute(self):
206207
207208
208209class InstallDIRAC (CommandBase ):
209- """ Source from CVMFS, or install locally
210- """
210+ """Source from CVMFS, or install locally"""
211211
212212 def __init__ (self , pilotParams ):
213213 """c'tor"""
214214 super (InstallDIRAC , self ).__init__ (pilotParams )
215215 self .pp .rootPath = self .pp .pilotRootPath
216216
217217 def _sourceEnvironmentFile (self ):
218- """source the $DIRAC_RC_FILE and save the created environment in self.pp.installEnv
219- """
218+ """Source the $DIRAC_RC_FILE and save the created environment in self.pp.installEnv"""
220219
221220 retCode , output = self .executeAndGetOutput ("bash -c 'source $DIRAC_RC_PATH && env'" , self .pp .installEnv )
222221 if retCode :
@@ -249,12 +248,12 @@ def _saveEnvInFile(self, eFile="environmentSourceDirac"):
249248 fd .write (bl )
250249
251250 def _getPreinstalledEnvScript (self ):
252- """ Get preinstalled environment script if any """
251+ """Get preinstalled environment script if any"""
253252
254253 self .log .debug ("self.pp.preinstalledEnv = %s" % self .pp .preinstalledEnv )
255254 self .log .debug ("self.pp.preinstalledEnvPrefix = %s" % self .pp .preinstalledEnvPrefix )
256255 self .log .debug ("self.pp.CVMFS_locations = %s" % self .pp .CVMFS_locations )
257-
256+
258257 preinstalledEnvScript = self .pp .preinstalledEnv
259258 if not preinstalledEnvScript and self .pp .preinstalledEnvPrefix :
260259 version = self .pp .releaseVersion or "pro"
@@ -265,7 +264,9 @@ def _getPreinstalledEnvScript(self):
265264 for CVMFS_location in self .pp .CVMFS_locations :
266265 version = self .pp .releaseVersion or "pro"
267266 arch = platform .system () + "-" + platform .machine ()
268- preinstalledEnvScript = os .path .join (CVMFS_location , self .pp .releaseProject .lower () + "dirac" , version , arch , "diracosrc" )
267+ preinstalledEnvScript = os .path .join (
268+ CVMFS_location , self .pp .releaseProject .lower () + "dirac" , version , arch , "diracosrc"
269+ )
269270 if os .path .isfile (preinstalledEnvScript ):
270271 break
271272
@@ -280,11 +281,11 @@ def _getPreinstalledEnvScript(self):
280281 self .pp .preinstalledEnv = preinstalledEnvScript
281282 self .pp .installEnv ["DIRAC_RC_PATH" ] = preinstalledEnvScript
282283
283-
284284 def _localInstallDIRAC (self ):
285+ """Install python3 version of DIRAC client"""
286+
285287 self .log .info ("Installing DIRAC locally" )
286288
287- """Install python3 version of DIRAC client"""
288289 # default to limit the resources used during installation to what the pilot owns
289290 installEnv = {
290291 # see https://github.com/DIRACGrid/Pilot/issues/189
@@ -353,7 +354,7 @@ def _localInstallDIRAC(self):
353354 self .pp .installEnv ["DIRAC_RC_PATH" ] = os .path .join (os .getcwd (), "diracos/diracosrc" )
354355 self ._sourceEnvironmentFile ()
355356 self ._saveEnvInFile ()
356-
357+
357358 # 7. pip install DIRAC[pilot]
358359 pipInstalling = "pip install %s " % self .pp .pipInstallOptions
359360
@@ -401,7 +402,7 @@ def execute(self):
401402 self .log .info ("NOT sourcing: starting traditional DIRAC installation" )
402403 self ._localInstallDIRAC ()
403404 return
404-
405+
405406 # Try sourcing from CVMFS
406407 self ._getPreinstalledEnvScript ()
407408 if not self .pp .preinstalledEnv :
@@ -413,10 +414,8 @@ def execute(self):
413414 # environment variables to add?
414415 if self .pp .userEnvVariables :
415416 # User-requested environment variables (comma-separated, name and value separated by ":::")
416- newEnvVars = dict (
417- name .split (":::" , 1 ) for name in self .pp .userEnvVariables .replace (" " , "" ).split ("," )
418- )
419- self .log .info ("Adding env variable(s) to the environment" , newEnvVars )
417+ newEnvVars = dict (name .split (":::" , 1 ) for name in self .pp .userEnvVariables .replace (" " , "" ).split ("," ))
418+ self .log .info ("Adding env variable(s) to the environment : %s" % newEnvVars )
420419 self .pp .installEnv .update (newEnvVars )
421420
422421 except OSError as e :
@@ -524,8 +523,7 @@ def _getBasicsCFG(self):
524523 self .cfg .append ('-o "/Resources/Computing/CEDefaults/VirtualOrganization=%s"' % self .pp .wnVO )
525524
526525 def _getSecurityCFG (self ):
527- """ Sets security-related env variables, if needed
528- """
526+ """Sets security-related env variables, if needed"""
529527 # Need to know host cert and key location in case they are needed
530528 if self .pp .useServerCertificate :
531529 self .cfg .append ("--UseServerCertificate" )
@@ -765,9 +763,13 @@ def execute(self):
765763
766764 batchSystemParams = self .pp .batchSystemInfo .get ("Parameters" , {})
767765 self .cfg .append ("-o /LocalSite/BatchSystemInfo/Parameters/Queue=%s" % batchSystemParams .get ("Queue" , "Unknown" ))
768- self .cfg .append ("-o /LocalSite/BatchSystemInfo/Parameters/BinaryPath=%s" % batchSystemParams .get ("BinaryPath" , "Unknown" ))
766+ self .cfg .append (
767+ "-o /LocalSite/BatchSystemInfo/Parameters/BinaryPath=%s" % batchSystemParams .get ("BinaryPath" , "Unknown" )
768+ )
769769 self .cfg .append ("-o /LocalSite/BatchSystemInfo/Parameters/Host=%s" % batchSystemParams .get ("Host" , "Unknown" ))
770- self .cfg .append ("-o /LocalSite/BatchSystemInfo/Parameters/InfoPath=%s" % batchSystemParams .get ("InfoPath" , "Unknown" ))
770+ self .cfg .append (
771+ "-o /LocalSite/BatchSystemInfo/Parameters/InfoPath=%s" % batchSystemParams .get ("InfoPath" , "Unknown" )
772+ )
771773
772774 self .cfg .append ('-n "%s"' % self .pp .site )
773775 self .cfg .append ('-S "%s"' % self .pp .setup )
@@ -856,7 +858,7 @@ def execute(self):
856858 localArchitecture = localArchitecture .strip ().split ("\n " )[- 1 ].strip ()
857859 cfg .append ('-S "%s"' % self .pp .setup )
858860 cfg .append ("-o /LocalSite/Architecture=%s" % localArchitecture )
859-
861+
860862 # add the local platform as determined by the platform module
861863 cfg .append ("-o /LocalSite/Platform=%s" % platform .machine ())
862864
@@ -1130,6 +1132,8 @@ def _runNagiosProbes(self):
11301132 self .log .error ("Return code = %d: %s" % (retCode , str (output ).split ("\n " , 1 )[0 ]))
11311133 retStatus = "error"
11321134
1135+ # TODO: Do something with the retStatus (for example: log it?)
1136+
11331137 # report results to pilot logger too. Like this:
11341138 # "NagiosProbes", probeCmd, retStatus, str(retCode) + ' ' + output.split('\n',1)[0]
11351139
0 commit comments