|
28 | 28 | import tempfile
|
29 | 29 | from os.path import join, dirname
|
30 | 30 | from warnings import warn
|
| 31 | +import errno |
31 | 32 |
|
32 | 33 | from .. import config, logging
|
33 | 34 | from ..utils.filemanip import (
|
@@ -2863,3 +2864,33 @@ def _list_outputs(self):
|
2863 | 2864 |
|
2864 | 2865 | def _add_output_traits(self, base):
|
2865 | 2866 | return add_traits(base, list(self.inputs.output_query.keys()))
|
| 2867 | + |
| 2868 | + |
| 2869 | +class ExportFileInputSpec(BaseInterfaceInputSpec): |
| 2870 | + in_file = File(exists=True, desc='Input file name') |
| 2871 | + out_file = File(exists=False, desc='Output file name') |
| 2872 | + check_extension = traits.Bool(False, desc='Ensure that the input and output file extensions match') |
| 2873 | + clobber = traits.Bool(False, desc='Permit overwriting existing files') |
| 2874 | + |
| 2875 | + |
| 2876 | +class ExportFileOutputSpec(TraitedSpec): |
| 2877 | + out_file = File(exists=True, desc='Output file name') |
| 2878 | + |
| 2879 | + |
| 2880 | +class ExportFile(BaseInterface): |
| 2881 | + input_spec = ExportFileInputSpec |
| 2882 | + output_spec = ExportFileOutputSpec |
| 2883 | + |
| 2884 | + def _run_interface(self, runtime): |
| 2885 | + if not self.inputs.clobber and op.exists(self.inputs.out_file): |
| 2886 | + raise FileExistsError(errno.EEXIST, f'File {self.inputs.out_file} exists') |
| 2887 | + if (self.inputs.check_extension and |
| 2888 | + op.splitext(self.inputs.in_file)[1] != op.splitext(self.inputs.out_file)[1]): |
| 2889 | + raise RuntimeError(f'{self.inputs.in_file} and {self.inputs.out_file} have different extensions') |
| 2890 | + shutil.copy(str(self.inputs.in_file), str(self.inputs.out_file)) |
| 2891 | + return runtime |
| 2892 | + |
| 2893 | + def _list_outputs(self): |
| 2894 | + outputs = self.output_spec().get() |
| 2895 | + outputs['out_file'] = self.inputs.out_file |
| 2896 | + return outputs |
0 commit comments