Exemplo n.º 1
0
def main(argv):
    # Name the experiment.
    experiment.name('test-shellcmds')

    fname = 'afile.txt'
    logger.log('# Testing globbing...')
    shargs = {'echo': True}
    # Wildcards need to be escaped with a `\' or quoted to protect them from
    # expansion by the host.
    container.run('ls \\*')
    # shell and container interfaces should behave as identically as possible.
    host.run('ls \\*', **shargs)

    logger.emlog('# Testing redirection...')
    logger.log(F'# Adding text to {fname}:')
    container.run(F'echo "Some Text" | tee {fname}')
    container.run(F'echo "More \'Text\'" >> {fname}')

    logger.emlog(F'# The contents of {fname} are:')
    host.run(F'cat {fname}', **shargs)

    logger.emlog('# Testing quoting...')
    container.run('echo "Some \'Text\'"')

    logger.emlog('# Testing command chaining...')
    container.run('true && echo true!')
    container.run('false || echo false... && echo and done!')

    metadata.add_asset(metadata.FileAsset(fname))
Exemplo n.º 2
0
    def _flatten(self) -> None:
        tcmd = '{} {} {}'.format(
            self.tarcmd,
            self.config['tag'],
            self.config['output_path']
        )

        logger.log('# Begin Flatten Output')
        os.environ['CH_BUILDER'] = self.builder
        host.run(tcmd, echo=True)
        logger.log('# End Flatten Output')
Exemplo n.º 3
0
 def stage(self, imgp: str) -> str:
     '''
     Stages the provided container image to an instance-determined base
     directory. The staged image path is returned if the staging completed
     successfully.
     '''
     stage_cmd = F'{_ImageStager.prun_generate()} ' \
                 F'{cntrimg.activator().tar2dirs(imgp, self.basep)}'
     runargs = {'echo': True, 'verbose': False}
     host.run(stage_cmd, **runargs)
     return os.path.join(self.basep, _ImageStager.get_img_dir_name(imgp))
Exemplo n.º 4
0
def main(argv):
    # Name the experiment.
    experiment.name('test-shellcmds')

    fname = 'afile.txt'
    logger.log('# Testing globbing...')
    shargs = {'echo': True}
    # Wildcards don't need to be escaped with a `\' or quoted to protect them
    # from expansion by the host. We take care of that for you.
    container.run('ls *')
    # host and container interfaces should behave as identically as possible.
    host.run('ls *', **shargs)

    logger.emlog('# Testing redirection...')
    logger.log(F'# Adding text to {fname}:')
    host.run(F'echo "Some Text" | tee {fname}', **shargs)
    host.run(F'echo "More \'Text\'" >> {fname}', **shargs)

    logger.emlog(F'# The contents of {fname} are:')
    host.run(F'cat {fname}', **shargs)

    logger.emlog('# Testing quoting...')
    container.run('echo "Some \'Text\'"')

    logger.emlog('# Testing command chaining...')
    container.run('true && echo true!')
    container.run('false || echo false is good  && echo true is good')

    logger.emlog('# Testing variable lifetimes within chained commands...')
    container.run('export FOO="bar" && '
                  'test ! -z $FOO && '
                  'echo "Looks good!" || '
                  'exit 1')

    metadata.add_asset(metadata.FileAsset(fname))
Exemplo n.º 5
0
    def _build(self) -> None:
        dockerf = self.config['spec']
        context = os.path.dirname(self.config['spec'])

        bcmd = '{} -b {} -t {} -f {} {}'.format(
            self.buildc,
            self.builder,
            self.config['tag'],
            dockerf,
            context
        )

        logger.emlog('# Begin Build Output')
        # Run the command specified by bcmd.
        host.run(bcmd, echo=True)
        logger.emlog('# End Build Output')
Exemplo n.º 6
0
 def run(  # pylint: disable=too-many-arguments
         self,
         cmds: List[str],
         echo: bool = True,
         capture: bool = False,
         verbose: bool = True,
         check_exit_code: bool = True
 ) -> List[str]:
     imgp = self.get_img_path()
     ccargs = [
         F'--set-env={imgp}/ch/environment',
         F'{imgp}'
     ]
     # Charliecloud activation command string.
     ccrc = F'{self.runcmd} {" ".join(ccargs)}'
     bmgc = F'{constants.BASH_MAGIC}'
     # First command.
     cmdf = cmds[0]
     # The rest of the commands.
     cmdr = ' '.join(cmds[1:])
     # Are multiple command strings provided?
     multicmd = len(cmds) > 1
     # Default command string if a single command is provided.
     cmdstr = F'{ccrc} -- {bmgc} {shlex.quote(cmdf)}'
     if multicmd:
         cmdstr = F'{cmdf} {ccrc} --join -- {bmgc} {shlex.quote(cmdr)}'
     runargs = {
         'verbatim': True,
         'echo': echo,
         'capture_output': capture,
         'verbose': verbose,
         'check_exit_code': check_exit_code
     }
     return host.run(cmdstr, **runargs)
Exemplo n.º 7
0
 def run(self,
         cmds: List[str],
         echo: bool = True,
         capture: bool = False,
         verbose: bool = True) -> List[str]:
     # Charliecloud activation command string.
     ccrc = F'{self.runcmd} {self.get_img_path()}'
     bmgc = F'{constants.BASH_MAGIC}'
     # First command.
     cmdf = cmds[0]
     # The rest of the commands.
     cmdr = ' '.join(cmds[1:])
     # Are multiple command strings provided?
     multicmd = len(cmds) > 1
     # Default command string if a single command is provided.
     cmdstr = F'{ccrc} -- {bmgc} {cmdf}'
     if multicmd:
         cmdstr = F'{cmdf} {ccrc} --join -- {bmgc} {cmdr}'
     runargs = {
         'verbatim': True,
         'echo': echo,
         'capture': capture,
         'verbose': verbose
     }
     return host.run(cmdstr, **runargs)
Exemplo n.º 8
0
 def run(self,
         cmds: List[str],
         echo: bool = True,
         capture: bool = False,
         verbose: bool = True) -> List[str]:
     # Note that we use this strategy instead of just running the
     # provided command so that quoting and escape requirements are
     # consistent across activators.
     cmdstr = F"{constants.BASH_MAGIC} {' '.join(cmds)}"
     runargs = {
         'verbatim': True,
         'echo': echo,
         'capture': capture,
         'verbose': verbose
     }
     return host.run(cmdstr, **runargs)
Exemplo n.º 9
0
 def run(  # pylint: disable=too-many-arguments
         self,
         cmds: List[str],
         echo: bool = True,
         capture: bool = False,
         verbose: bool = True,
         check_exit_code: bool = True
 ) -> List[str]:
     # Note that we use this strategy instead of just running the
     # provided command so that quoting and escape requirements are
     # consistent across activators.
     cmdstr = F"{constants.BASH_MAGIC} {shlex.quote(' '.join(cmds))}"
     runargs = {
         'verbatim': True,
         'echo': echo,
         'capture_output': capture,
         'verbose': verbose,
         'check_exit_code': check_exit_code
     }
     return host.run(cmdstr, **runargs)
Exemplo n.º 10
0
def main(argv):
    experiment.name('hello-container')
    container.run('echo "hello from a container!"')
    host.run('echo "hello from the host!"')