Loading py/utopya_jobtree.py +53 −25 Original line number Diff line number Diff line #! /usr/bin/env python # # Changes # # 2022-09, Arjo Segers # Improved code that is added to job script to load Environment Module functions. # # 2022-09, Arjo Segers # Print info on missing `tasks` list. # """ ************************* ``utopya_jobtree`` module Loading Loading @@ -843,14 +853,25 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : #endif self.Append( '# check ...' ) self.Append( 'if "MODULESHOME" not in os.environ.keys() :' ) self.Append( ' logging.error( "ERROR - could not load environment modules without MODULESHOME" )' ) self.Append( ' print( "ERROR - could not load environment modules without MODULESHOME" )' ) self.Append( ' raise Exception' ) self.Append( '#endif' ) self.Append( '# initialization script for environment modules:' ) self.Append( 'initfile = os.path.join( os.environ["MODULESHOME"], "init", "python.py" )' ) self.Append( '# check ...' ) self.Append( 'if not os.path.isfile(initfile) :' ) self.Append( ' logging.err( "ERROR - could not find environment modules initialization file: %s" % initfile )' ) self.Append( '# initialization scripts for environment modules:' ) self.Append( 'initfiles = []' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "python.py" ) )' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "python" ) )' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "env_modules_python.py" ) )' ) self.Append( '# search first one that is present:' ) self.Append( 'found = False' ) self.Append( 'for initfile in initfiles :' ) self.Append( ' found = os.path.isfile(initfile)' ) self.Append( ' if found : break' ) self.Append( '#endfor' ) self.Append( 'if not found :' ) self.Append( ' print( "ERROR - could not find any environment modules initialization file:" )' ) self.Append( ' for initfile in initfiles :' ) self.Append( ' print( "ERROR - %s" % initfile )' ) self.Append( ' #endfor' ) self.Append( ' raise Exception' ) self.Append( '#endif' ) self.Append( '# load module functions:' ) Loading Loading @@ -1233,27 +1254,28 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : #logging.info( 'xxx get setting: %s' % name_generic+'.tasks' ) # list with task names: tasknames = self.GetSetting( name_generic+'.tasks', default='None' ).split() # loop: for taskname in tasknames : # taskname part in rcfile keys: if taskname == 'None' : taskkey = 'task' tasknames = self.GetSetting( name_generic+'.tasks', default='None' ) # might be undefined: if tasknames == 'None' : logging.warning( 'no "tasks" list defined, either single task or no tasks at all ...' ) tasknames = ['task'] else : taskkey = taskname tasknames = tasknames.split() #endif # loop: for taskname in tasknames : # work directory: wdir = self._GetWorkdir() # module and class name as defined in rcfile: cls = self.GetSetting( name_generic+('.%s.class' % taskkey), default='None' ) # module and class name as defined in rcfile; # might be undefined for jobtree: cls = self.GetSetting( name_generic+('.%s.class' % taskname), default='None' ) # undefined? then skip: if cls == 'None' : continue # arguments for initialization: args = self.GetSetting( name_generic+('.%s.args' % taskkey) ) args = self.GetSetting( name_generic+('.%s.args' % taskname) ) # replace templates: args = args.replace( '%{workdir}', wdir ) args = args.replace( '%{name}', self.name ) Loading Loading @@ -1300,7 +1322,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : self.Append( '#endif' ) #endif #endfor # tasks #endfor # tasknames # add space: self.Append( '' ) Loading Loading @@ -1596,7 +1618,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # * def Run( self, without_next=False, _indent='' ) : def Run( self, without_next=False, single=False, _indent='' ) : """ Create and submit the job for the named item in the job step. Loading @@ -1611,7 +1633,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : * :py:meth:`AddCwd` * :py:meth:`AddVariables` * :py:meth:`AddTasks` * :py:meth:`AddNextJob` * :py:meth:`AddNextJob` *(not called if ``single=True``)* * :py:meth:`AddFooter` The file is written and submitted by a call to the method:: Loading Loading @@ -1648,8 +1670,11 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # add task lines: self.AddTasks() # no next job (nor comments) if "single" is enabled ... if not single : # add lines to create and submit next job: self.AddNextJob( without_next=without_next ) #endif # finish lines: self.AddFooter() Loading @@ -1661,11 +1686,14 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # * def Start( self ) : def Start( self, single=False ) : """ Create object for the first job along tree that is not marked as virtual, and call its :py:meth:`Run` method. The ``single`` flag is passed to the :py:meth:`Run` method; if enabled, only a single job step is performed. """ # get first non-virtual name, might be current: Loading @@ -1677,7 +1705,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # create object for this root: jbs = jbsclass( xname, self.rcfile, rcbase=self.rcbase ) # run: jbs.Run() jbs.Run( single=single ) #enddef Start Loading Loading
py/utopya_jobtree.py +53 −25 Original line number Diff line number Diff line #! /usr/bin/env python # # Changes # # 2022-09, Arjo Segers # Improved code that is added to job script to load Environment Module functions. # # 2022-09, Arjo Segers # Print info on missing `tasks` list. # """ ************************* ``utopya_jobtree`` module Loading Loading @@ -843,14 +853,25 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : #endif self.Append( '# check ...' ) self.Append( 'if "MODULESHOME" not in os.environ.keys() :' ) self.Append( ' logging.error( "ERROR - could not load environment modules without MODULESHOME" )' ) self.Append( ' print( "ERROR - could not load environment modules without MODULESHOME" )' ) self.Append( ' raise Exception' ) self.Append( '#endif' ) self.Append( '# initialization script for environment modules:' ) self.Append( 'initfile = os.path.join( os.environ["MODULESHOME"], "init", "python.py" )' ) self.Append( '# check ...' ) self.Append( 'if not os.path.isfile(initfile) :' ) self.Append( ' logging.err( "ERROR - could not find environment modules initialization file: %s" % initfile )' ) self.Append( '# initialization scripts for environment modules:' ) self.Append( 'initfiles = []' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "python.py" ) )' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "python" ) )' ) self.Append( 'initfiles.append( os.path.join( os.environ["MODULESHOME"], "init", "env_modules_python.py" ) )' ) self.Append( '# search first one that is present:' ) self.Append( 'found = False' ) self.Append( 'for initfile in initfiles :' ) self.Append( ' found = os.path.isfile(initfile)' ) self.Append( ' if found : break' ) self.Append( '#endfor' ) self.Append( 'if not found :' ) self.Append( ' print( "ERROR - could not find any environment modules initialization file:" )' ) self.Append( ' for initfile in initfiles :' ) self.Append( ' print( "ERROR - %s" % initfile )' ) self.Append( ' #endfor' ) self.Append( ' raise Exception' ) self.Append( '#endif' ) self.Append( '# load module functions:' ) Loading Loading @@ -1233,27 +1254,28 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : #logging.info( 'xxx get setting: %s' % name_generic+'.tasks' ) # list with task names: tasknames = self.GetSetting( name_generic+'.tasks', default='None' ).split() # loop: for taskname in tasknames : # taskname part in rcfile keys: if taskname == 'None' : taskkey = 'task' tasknames = self.GetSetting( name_generic+'.tasks', default='None' ) # might be undefined: if tasknames == 'None' : logging.warning( 'no "tasks" list defined, either single task or no tasks at all ...' ) tasknames = ['task'] else : taskkey = taskname tasknames = tasknames.split() #endif # loop: for taskname in tasknames : # work directory: wdir = self._GetWorkdir() # module and class name as defined in rcfile: cls = self.GetSetting( name_generic+('.%s.class' % taskkey), default='None' ) # module and class name as defined in rcfile; # might be undefined for jobtree: cls = self.GetSetting( name_generic+('.%s.class' % taskname), default='None' ) # undefined? then skip: if cls == 'None' : continue # arguments for initialization: args = self.GetSetting( name_generic+('.%s.args' % taskkey) ) args = self.GetSetting( name_generic+('.%s.args' % taskname) ) # replace templates: args = args.replace( '%{workdir}', wdir ) args = args.replace( '%{name}', self.name ) Loading Loading @@ -1300,7 +1322,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : self.Append( '#endif' ) #endif #endfor # tasks #endfor # tasknames # add space: self.Append( '' ) Loading Loading @@ -1596,7 +1618,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # * def Run( self, without_next=False, _indent='' ) : def Run( self, without_next=False, single=False, _indent='' ) : """ Create and submit the job for the named item in the job step. Loading @@ -1611,7 +1633,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : * :py:meth:`AddCwd` * :py:meth:`AddVariables` * :py:meth:`AddTasks` * :py:meth:`AddNextJob` * :py:meth:`AddNextJob` *(not called if ``single=True``)* * :py:meth:`AddFooter` The file is written and submitted by a call to the method:: Loading Loading @@ -1648,8 +1670,11 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # add task lines: self.AddTasks() # no next job (nor comments) if "single" is enabled ... if not single : # add lines to create and submit next job: self.AddNextJob( without_next=without_next ) #endif # finish lines: self.AddFooter() Loading @@ -1661,11 +1686,14 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # * def Start( self ) : def Start( self, single=False ) : """ Create object for the first job along tree that is not marked as virtual, and call its :py:meth:`Run` method. The ``single`` flag is passed to the :py:meth:`Run` method; if enabled, only a single job step is performed. """ # get first non-virtual name, might be current: Loading @@ -1677,7 +1705,7 @@ class UtopyaJobStep( utopya_rc.UtopyaRc ) : # create object for this root: jbs = jbsclass( xname, self.rcfile, rcbase=self.rcbase ) # run: jbs.Run() jbs.Run( single=single ) #enddef Start Loading