Example #1
0
  def test_addsuffix(self):
    from craftr.utils.path import addsuffix
    self.assertEqual(addsuffix(_('foo/bar/baz'), _('.eggs'), True), _('foo/bar/baz.eggs'))
    self.assertEqual(addsuffix(_('foo/bar/baz.spam'), _('.eggs'), True), _('foo/bar/baz.eggs'))
    self.assertEqual(addsuffix(_('foo/bar/baz.spam'), None, True), _('foo/bar/baz'))
    self.assertEqual(addsuffix(_('foo/bar/baz.spam'), _(''), True), _('foo/bar/baz'))
    self.assertEqual(
      addsuffix([
        _('foo/bar/baz'),
        _('foo/bar/baz.spam'),
        _('foo/bar/baz.baz')], _('.eggs'), True),
      [
        _('foo/bar/baz.eggs'),
        _('foo/bar/baz.eggs'),
        _('foo/bar/baz.eggs')])

    self.assertEqual(addsuffix(_('foo/bar/baz.spam'), _('eggs'), False), _('foo/bar/baz.spameggs'))
    self.assertEqual(addsuffix(_('foo/bar/baz.spam'), _('.eggs'), False), _('foo/bar/baz.spam.eggs'))
    self.assertEqual(
      addsuffix([
        _('foo/bar/baz'),
        _('foo/bar/baz.spam'),
        _('foo/bar/baz.baz')], _('eggs'), False),
      [
        _('foo/bar/bazeggs'),
        _('foo/bar/baz.spameggs'),
        _('foo/bar/baz.bazeggs')])
Example #2
0
  def write_command_file(self, filename, commands, inputs=None, outputs=None,
      cwd=None, environ=None, foreach=False, suffix='.cmd', dry=False,
      accept_additional_args=False):

    if suffix is not None:
      filename = path.addsuffix(filename, suffix)
    result = ['cmd', '/Q', '/c', filename]
    if foreach:
      result += ['$in', '$out']
      inputs, outputs = ['%1'], ['%2']

    commands = self.replace_commands_inout_vars(commands, inputs, outputs)
    if dry:
      return result, filename

    path.makedirs(path.dirname(path.abs(filename)))
    with open(filename, 'w') as fp:
      fp.write('REM This file is automatically generated with Craftr. It is \n')
      fp.write('REM not recommended to modify it manually.\n\n')
      if cwd is not None:
        fp.write('cd ' + shell.quote(cwd) + '\n\n')
      for key, value in environ.items():
        fp.write('set ' + shell.quote('{}={}'.format(key, value), for_ninja=True) + '\n')
      fp.write('\n')
      for index, command in enumerate(commands):
        if accept_additional_args and index == len(commands)-1:
          command.append(shell.safe('%*'))
        fp.write(shell.join(command) + '\n')
        fp.write('if %errorlevel% neq 0 exit %errorlevel%\n\n')

    return result, filename
Example #3
0
def relocate_files(files, outdir, suffix, replace_suffix=True, parent=None):
  """
  Converts a list of filenames, relocating them to *outdir* and replacing
  their existing suffix. If *suffix* is a callable, it will be passed the
  new filename and expected to return the same filename, eventually with
  a different suffix.
  """

  if parent is None:
    parent = session.module.namespace.project_dir
  result = []
  for filename in files:
    filename = path.join(outdir, path.rel(filename, parent))
    filename = path.addsuffix(filename, suffix, replace=replace_suffix)
    result.append(filename)
  return result
Example #4
0
def relocate_files(files, outdir, suffix, replace_suffix=True, parent=None):
  """
  Converts a list of filenames, relocating them to *outdir* and replacing
  their existing suffix. If *suffix* is a callable, it will be passed the
  new filename and expected to return the same filename, eventually with
  a different suffix.
  """

  if parent is None:
    parent = session.module.project_dir
  result = []
  for filename in files:
    filename = path.join(outdir, path.rel(filename, parent))
    filename = path.addsuffix(filename, suffix, replace=replace_suffix)
    result.append(filename)
  return result
Example #5
0
    def write_command_file(self,
                           filename,
                           commands,
                           inputs=None,
                           outputs=None,
                           cwd=None,
                           environ=None,
                           foreach=False,
                           suffix='.sh',
                           dry=False,
                           accept_additional_args=False):

        if suffix is not None:
            filename = path.addsuffix(filename, suffix)
        result = [filename]
        if foreach:
            result += ['$in', '$out']
            inputs, outputs = ['%1'], ['%2']

        commands = self.replace_commands_inout_vars(commands, inputs, outputs)
        if dry:
            return result, filename

        path.makedirs(path.dirname(filename))
        with open(filename, 'w') as fp:
            # TODO: Make sure this also works for shells other than bash.
            fp.write('#!' + shell.find_program(environ.get('SHELL', 'bash')) +
                     '\n')
            fp.write('set -e\n')
            if cwd:
                fp.write('cd ' + shell.quote(cwd) + '\n')
            fp.write('\n')
            for key, value in environ.items():
                fp.write('export {}={}\n'.format(key, shell.quote(value)))
            fp.write('\n')
            for index, command in enumerate(commands):
                if accept_additional_args and index == len(commands) - 1:
                    command.append(shell.safe('$*'))
                fp.write(shell.join(command))
                fp.write('\n')

        os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
                 | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH)  # rwxrw-r--

        return result, filename
Example #6
0
    def write_command_file(self,
                           filename,
                           commands,
                           inputs=None,
                           outputs=None,
                           cwd=None,
                           environ=None,
                           foreach=False,
                           suffix='.cmd',
                           dry=False,
                           accept_additional_args=False):

        if suffix is not None:
            filename = path.addsuffix(filename, suffix)
        result = ['cmd', '/Q', '/c', filename]
        if foreach:
            result += ['$in', '$out']
            inputs, outputs = ['%1'], ['%2']

        commands = self.replace_commands_inout_vars(commands, inputs, outputs)
        if dry:
            return result, filename

        path.makedirs(path.dirname(path.abs(filename)))
        with open(filename, 'w') as fp:
            fp.write(
                'REM This file is automatically generated with Craftr. It is \n'
            )
            fp.write('REM not recommended to modify it manually.\n\n')
            if cwd is not None:
                fp.write('cd ' + shell.quote(cwd) + '\n\n')
            for key, value in environ.items():
                fp.write(
                    'set ' +
                    shell.quote('{}={}'.format(key, value), for_ninja=True) +
                    '\n')
            fp.write('\n')
            for index, command in enumerate(commands):
                if accept_additional_args and index == len(commands) - 1:
                    command.append(shell.safe('%*'))
                fp.write(shell.join(command) + '\n')
                fp.write('if %errorlevel% neq 0 exit %errorlevel%\n\n')

        return result, filename
Example #7
0
  def write_command_file(self, filename, commands, inputs=None, outputs=None,
      cwd=None, environ=None, foreach=False, suffix='.sh', dry=False,
      accept_additional_args=False):

    if suffix is not None:
      filename = path.addsuffix(filename, suffix)
    result = [filename]
    if foreach:
      result += ['$in', '$out']
      inputs, outputs = ['%1'], ['%2']

    commands = self.replace_commands_inout_vars(commands, inputs, outputs)
    if dry:
      return result, filename

    path.makedirs(path.dirname(filename))
    with open(filename, 'w') as fp:
      # TODO: Make sure this also works for shells other than bash.
      fp.write('#!' + shell.find_program(environ.get('SHELL', 'bash')) + '\n')
      fp.write('set -e\n')
      if cwd:
        fp.write('cd ' + shell.quote(cwd) + '\n')
      fp.write('\n')
      for key, value in environ.items():
        fp.write('export {}={}\n'.format(key, shell.quote(value)))
      fp.write('\n')
      for index, command in enumerate(commands):
        if accept_additional_args and index == len(commands)-1:
          command.append(shell.safe('$*'))
        fp.write(shell.join(command))
        fp.write('\n')

    os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
      stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH)  # rwxrw-r--

    return result, filename
Example #8
0
def dll(x): return path.addsuffix(x, ".dll")
def lib(x): return path.addsuffix(x, ".lib")
Example #9
0
def bin(x): return path.addsuffix(x, ".exe")
def dll(x): return path.addsuffix(x, ".dll")
Example #10
0
def obj(x): return path.addsuffix(x, ".obj")
def bin(x): return path.addsuffix(x, ".exe")
Example #11
0
def dll(x):
    return path.addsuffix(x, ".dll")
Example #12
0
def lib(x):
    return path.addprefix(path.addsuffix(x, ".a"), "lib")
Example #13
0
def dll(x): return path.addsuffix(x, ".so")
def lib(x): return path.addprefix(path.addsuffix(x, ".a"), "lib")
Example #14
0
def dll(x): return path.addsuffix(x, ".dll")
def lib(x): return path.addsuffix(x, ".lib")
Example #15
0
def dll(x):
    return path.addsuffix(x, ".so")
Example #16
0
def lib(x):
    return path.addsuffix(x, ".lib")
Example #17
0
def bin(x):
    return path.addsuffix(x, ".exe")
Example #18
0
def obj(x): return path.addsuffix(x, ".obj")
def bin(x): return path.addsuffix(x, ".exe")
Example #19
0
def bin(x):
    return path.addsuffix(x, ".exe")
Example #20
0
def bin(x): return path.addsuffix(x, ".exe")
def dll(x): return path.addsuffix(x, ".dll")
Example #21
0
def lib(x):
    return path.addsuffix(x, ".lib")
Example #22
0
def obj(x): return path.addsuffix(x, ".o")
def bin(x): return x
Example #23
0
def obj(x):
    return path.addsuffix(x, ".o")
Example #24
0
def dll(x):
    return path.addsuffix(x, ".dylib")
Example #25
0
def obj(x):
    return path.addsuffix(x, ".obj")