Example #1
0
    def to_shell(self, runner, logger=None):
        """!Adds the environment variables to @c runner and generates
        shell code that would create the command file.

        @param[out] runner A produtil.prog.Runner to modify
        @param logger a logging.Logger for log messages
        @returns a tuple containing shell code and the modified runner"""
        if logger is None: logger = module_logger
        sio = StringIO()
        filename = self.filename
        if filename is None:
            filename = 'tempfile'
        bsfilename = shbackslash(filename)

        sio.write('cat /dev/null >%s\n' % (bsfilename, ))
        prior = None
        count = 0
        for line in self.cmdf_contents.splitlines():
            if not count:
                prior = line
                count = 1
            elif prior != line:
                if count > 1:
                    sio.write(
                        'for n in $( seq 1 %d ) ; do echo %s ; done >> %s\n' %
                        (count, shbackslash(line), bsfilename))
                else:
                    sio.write('echo %s >> %s\n' %
                              (shbackslash(line), bsfilename))
                prior = line
                count = 1
            else:
                count += 1
        if count > 0:
            if count > 1:
                sio.write(
                    'for n in $( seq 1 %d ) ; do echo %s ; done >> %s\n' %
                    (count, shbackslash(line), bsfilename))
            else:
                sio.write('echo %s >> %s\n' % (shbackslash(line), bsfilename))

        kw = {self.cmd_envar: filename}
        self._add_more_vars(kw, logger)
        if logger is not None:
            for k, v in kw.items():
                self.info('Set %s=%s' % (k, repr(v)), logger)
        if self.filename_arg:
            runner = runner[filename]
        runner = runner.env(**kw)
        text = sio.getvalue()
        sio.close()
        return text, runner
Example #2
0
 def args(self):
     """!Iterates over the executable arguments."""
     if self._env:
         yield '/bin/env'
         for k,v in self._env.items():
             yield '%s=%s'%(k,shbackslash(v))
     for arg in self._args: yield arg
Example #3
0
    m = re.match(
        '''(?x)(?P<section>[a-zA-Z][a-zA-Z0-9_]*)\.(?P<option>[^=]+)=(?P<value>.*)$''',
        s)
    if not m:
        return os.path.abspath(s)
    else:
        return s


# Turn any conf files specified in arguments into fully-qualified
# paths.  This is needed because run_hafs will generally be started
# from a different directory than the exhafs_launch.py.
if firstarg + 2 < len(args):
    confargs = args[(firstarg + 2):]
    more_launch_vars = ' '.join(
        entity_quote(shbackslash(fullify(str(x)))) for x in confargs)
else:
    confargs = list()
    more_launch_vars = ''
logger.info('MORE_LAUNCH_VARS=' + repr(more_launch_vars))

# Tell the hafs.launcher to parse the remaining arguments so we can
# make the conf information:

# Generate the conf file and run the hafs.launcher's sanity checks
# that do not require a cycle:
# mslist does not contain the fakestorm id
logger.info('MSLIST: ' + repr(mslist))
if multistorm:
    (case_root, parm, infiles, stids, stid, pstid,
     moreopts) = hafs.launcher.multistorm_parse_args(mslist,