|
| 1 | +########################################################################### |
| 2 | +# Copyright (c), The AiiDA team. All rights reserved. # |
| 3 | +# This file is part of the AiiDA code. # |
| 4 | +# # |
| 5 | +# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # |
| 6 | +# For further information on the license, see the LICENSE.txt file # |
| 7 | +# For further information please visit http://www.aiida.net # |
| 8 | +########################################################################### |
| 9 | +"""Data plugin that models a stashed folder on a remote computer.""" |
| 10 | + |
| 11 | +from typing import List, Tuple, Union |
| 12 | + |
| 13 | +from aiida.common.datastructures import StashMode |
| 14 | +from aiida.common.lang import type_check |
| 15 | +from aiida.common.pydantic import MetadataField |
| 16 | + |
| 17 | +from .base import RemoteStashData |
| 18 | + |
| 19 | +__all__ = ('RemoteStashCopyData',) |
| 20 | + |
| 21 | + |
| 22 | +class RemoteStashCopyData(RemoteStashData): |
| 23 | + """Data plugin that models a folder with files of a completed calculation job that has been stashed through a copy. |
| 24 | +
|
| 25 | + This data plugin can and should be used to stash files if and only if the stash mode is `StashMode.COPY`. |
| 26 | + """ |
| 27 | + |
| 28 | + _storable = True |
| 29 | + |
| 30 | + class Model(RemoteStashData.Model): |
| 31 | + target_basepath: str = MetadataField(description='The the target basepath') |
| 32 | + source_list: List[str] = MetadataField(description='The list of source files that were stashed') |
| 33 | + |
| 34 | + def __init__(self, stash_mode: StashMode, target_basepath: str, source_list: List[str], **kwargs): |
| 35 | + """Construct a new instance |
| 36 | +
|
| 37 | + :param stash_mode: the stashing mode with which the data was stashed on the remote. |
| 38 | + :param target_basepath: the target basepath. |
| 39 | + :param source_list: the list of source files. |
| 40 | + """ |
| 41 | + super().__init__(stash_mode, **kwargs) |
| 42 | + self.target_basepath = target_basepath |
| 43 | + self.source_list = source_list |
| 44 | + |
| 45 | + # Although this subclass supports only the `StashMode.COPY` mode, |
| 46 | + # the design aligns with the `RemoteStashData` LSP for consistency. |
| 47 | + # For stashing with compressed options, consider using `RemoteStashCompressedData`. |
| 48 | + if stash_mode != StashMode.COPY: |
| 49 | + raise ValueError('`RemoteStashCopyData` can only be used with `stash_mode == StashMode.COPY`.') |
| 50 | + |
| 51 | + @property |
| 52 | + def target_basepath(self) -> str: |
| 53 | + """Return the target basepath. |
| 54 | +
|
| 55 | + :return: the target basepath. |
| 56 | + """ |
| 57 | + return self.base.attributes.get('target_basepath') |
| 58 | + |
| 59 | + @target_basepath.setter |
| 60 | + def target_basepath(self, value: str): |
| 61 | + """Set the target basepath. |
| 62 | +
|
| 63 | + :param value: the target basepath. |
| 64 | + """ |
| 65 | + type_check(value, str) |
| 66 | + self.base.attributes.set('target_basepath', value) |
| 67 | + |
| 68 | + @property |
| 69 | + def source_list(self) -> Union[List, Tuple]: |
| 70 | + """Return the list of source files that were stashed. |
| 71 | +
|
| 72 | + :return: the list of source files. |
| 73 | + """ |
| 74 | + return self.base.attributes.get('source_list') |
| 75 | + |
| 76 | + @source_list.setter |
| 77 | + def source_list(self, value: Union[List, Tuple]): |
| 78 | + """Set the list of source files that were stashed. |
| 79 | +
|
| 80 | + :param value: the list of source files. |
| 81 | + """ |
| 82 | + type_check(value, (list, tuple)) |
| 83 | + self.base.attributes.set('source_list', value) |
0 commit comments