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')])
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
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
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
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
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
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
def dll(x): return path.addsuffix(x, ".dll") def lib(x): return path.addsuffix(x, ".lib")
def bin(x): return path.addsuffix(x, ".exe") def dll(x): return path.addsuffix(x, ".dll")
def obj(x): return path.addsuffix(x, ".obj") def bin(x): return path.addsuffix(x, ".exe")
def dll(x): return path.addsuffix(x, ".dll")
def lib(x): return path.addprefix(path.addsuffix(x, ".a"), "lib")
def dll(x): return path.addsuffix(x, ".so") def lib(x): return path.addprefix(path.addsuffix(x, ".a"), "lib")
def dll(x): return path.addsuffix(x, ".so")
def lib(x): return path.addsuffix(x, ".lib")
def bin(x): return path.addsuffix(x, ".exe")
def obj(x): return path.addsuffix(x, ".o") def bin(x): return x
def obj(x): return path.addsuffix(x, ".o")
def dll(x): return path.addsuffix(x, ".dylib")
def obj(x): return path.addsuffix(x, ".obj")