Example #1
0
    def _build_resources(self):
        for name, dest, content in self.new_files:
            filename = self._get_abs_path(dest)
            tools.makedirs(os.path.dirname(filename))
            with open(filename, 'w') as file:
                logging.debug('Writing file "%s"' % filename)
                file.write(content)
                if dest == 'run':
                    # Make run script executable.
                    # TODO: Replace by adding an "executable" kwarg in add_new_file().
                    os.chmod(filename, 0755)

        for name, source, dest, required, symlink in self.resources:

            if required and not os.path.exists(source):
                logging.critical('Required resource not found: %s' % source)
            dest = self._get_abs_path(dest)
            if not dest.startswith(self.path):
                # Only copy resources that reside in the experiment/run dir.
                continue
            if symlink:
                # Do not create a symlink if the file doesn't exist.
                if not os.path.exists(source):
                    continue
                source = self._get_rel_path(source)
                os.symlink(source, dest)
                logging.debug('Linking from %s to %s' % (source, dest))
                continue

            # Even if the directory containing a resource has already been added,
            # we copy the resource since we might want to overwrite it.
            logging.debug('Copying %s to %s' % (source, dest))
            tools.copy(source, dest, required, self.ignores)
Example #2
0
    def _build_resources(self):
        for name, dest, content in self.new_files:
            filename = self._get_abs_path(dest)
            tools.makedirs(os.path.dirname(filename))
            with open(filename, 'w') as file:
                logging.debug('Writing file "%s"' % filename)
                file.write(content)
                if dest == 'run':
                    # Make run script executable.
                    # TODO: Replace by adding an "executable" kwarg in add_new_file().
                    os.chmod(filename, 0755)

        for name, source, dest, required, symlink in self.resources:

            if required and not os.path.exists(source):
                logging.critical('Required resource not found: %s' % source)
            dest = self._get_abs_path(dest)
            if not dest.startswith(self.path):
                # Only copy resources that reside in the experiment/run dir.
                continue
            if symlink:
                # Do not create a symlink if the file doesn't exist.
                if not os.path.exists(source):
                    continue
                source = self._get_rel_path(source)
                os.symlink(source, dest)
                logging.debug('Linking from %s to %s' % (source, dest))
                continue

            # Even if the directory containing a resource has already been added,
            # we copy the resource since we might want to overwrite it.
            logging.debug('Copying %s to %s' % (source, dest))
            tools.copy(source, dest, required, self.ignores)
Example #3
0
    def _build_resources(self, only_parsers=False):
        for resource in self.resources:
            if only_parsers and not resource.is_parser:
                continue
            if not os.path.exists(resource.source):
                logging.critical(f"Resource not found: {resource.source}")
            dest = self._get_abs_path(resource.dest)
            if not dest.startswith(self.path):
                # Only copy resources that reside in the experiment/run dir.
                continue
            if resource.symlink:
                # Do not create a symlink if the file doesn't exist.
                if not os.path.exists(resource.source):
                    continue
                source = self._get_rel_path(resource.source)
                os.symlink(source, dest)
                logging.debug(f"Linking from {source} to {dest}")
                continue

            # Even if the directory containing a resource has already been added,
            # we copy the resource since we might want to overwrite it.
            logging.debug(f"Copying {resource.source} to {dest}")
            tools.copy(resource.source, dest)
Example #4
0
def test_copy_dir_to_dir():
    tools.copy(src_dir, dest_dir3)
    assert os.path.isdir(os.path.join(base, "dest_dir_also_not_existing"))
    assert os.path.isfile(
        os.path.join(base, "dest_dir_also_not_existing", "nested_src_file"))
Example #5
0
def test_copy_file_to_not_ex_dir():
    tools.copy(src_file, dest_dir2)
    assert os.path.isfile(os.path.join(base, "dest_dir_not_existing"))
Example #6
0
def test_copy_file_to_file():
    tools.copy(src_file, dest_file)
    assert os.path.isfile(os.path.join(base, "dest1", "dest_file"))
Example #7
0
def test_copy_file_to_ex_dir():
    tools.copy(src_file, dest_dir1)
    assert os.path.isfile(os.path.join(base, 'dest_dir_existing', 'src_file'))
Example #8
0
def test_copy_dir_to_dir():
    copy(src_dir, dest_dir3)
    assert os.path.isdir(os.path.join(base, 'dest_dir_also_not_existing'))
    assert os.path.isfile(os.path.join(base, 'dest_dir_also_not_existing',
                                       'nested_src_file'))
Example #9
0
def test_copy_file_to_not_ex_dir():
    copy(src_file, dest_dir2)
    assert os.path.isfile(os.path.join(base, 'dest_dir_not_existing'))
Example #10
0
def test_copy_file_to_ex_dir():
    copy(src_file, dest_dir1)
    assert os.path.isfile(os.path.join(base, 'dest_dir_existing', 'src_file'))
Example #11
0
def test_copy_file_to_file():
    copy(src_file, dest_file)
    assert os.path.isfile(os.path.join(base, 'dest1', 'dest_file'))
def test_copy_dir_to_dir():
    copy(src_dir, dest_dir3)
    assert os.path.isdir(os.path.join(base, 'dest_dir_also_not_existing'))
    assert os.path.isfile(
        os.path.join(base, 'dest_dir_also_not_existing', 'nested_src_file'))
def test_copy_file_to_not_ex_dir():
    copy(src_file, dest_dir2)
    assert os.path.isfile(os.path.join(base, 'dest_dir_not_existing'))
def test_copy_file_to_file():
    copy(src_file, dest_file)
    assert os.path.isfile(os.path.join(base, 'dest1', 'dest_file'))