Пример #1
0
    def calculate_hash_paths(self, paths, directory):
        try:
            files, dirs, _, _ = parse_paths(self.root, paths, directory)
        except PathDoesNotExist as e:
            raise PathDoesNotExist(
                __("error",
                   "controller.file.driver.local.create_collection.filepath",
                   str(e)))

        # Populate collection from left to right in lists
        for file_tuple in files:
            src_abs_filepath, dest_abs_filepath = file_tuple
            if os.path.exists(dest_abs_filepath):
                raise FileAlreadyExistsError(
                    __("error",
                       "controller.file.driver.create_collection.file_exists",
                       dest_abs_filepath))
            # File is copied over to the new destination path
            shutil.copy2(src_abs_filepath, dest_abs_filepath)

        for dir_tuple in dirs:
            src_abs_dirpath, dest_abs_dirpath = dir_tuple
            if os.path.exists(dest_abs_dirpath):
                raise DirAlreadyExistsError(
                    __("error",
                       "controller.file.driver.create_collection.dir_exists",
                       dest_abs_dirpath))
            os.makedirs(dest_abs_dirpath)
            # All contents of directory is copied over to the new directory path
            self.copytree(src_abs_dirpath, dest_abs_dirpath)

        # Hash the files to find filehash
        return self.get_dirhash(directory)
Пример #2
0
    def create(self, path=None, output_path=None):
        if not path:
            path = os.path.join(self.filepath, "Dockerfile")
        if not output_path:
            directory, filename = os.path.split(path)
            output_path = os.path.join(directory, "datmo" + filename)
        if not os.path.isfile(path):
            raise EnvironmentDoesNotExist(
                __("error", "controller.environment.driver.docker.create.dne",
                   path))
        if os.path.isfile(output_path):
            raise FileAlreadyExistsError(
                __("error",
                   "controller.environment.driver.docker.create.exists",
                   output_path))
        success = self.create_datmo_definition(
            input_definition_path=path, output_definition_path=output_path)

        return success, path, output_path