our_file.write('Our file')
# with a local file storage
- filename, copied = self.workbench_manager.possibly_localize_file(
+ filename = self.workbench_manager.possibly_localize_file(
this_workbench, this_storage, filepath)
- assert copied is False
assert filename == os.path.join(
tmpdir, 'dir1/dir2/ourfile.txt')
with this_storage.get_file(filepath, 'w') as our_file:
our_file.write('Our file')
- filename, copied = self.workbench_manager.possibly_localize_file(
+ filename = self.workbench_manager.possibly_localize_file(
this_workbench, this_storage, filepath)
assert filename == os.path.join(
this_workbench, 'ourfile.txt')
# fake remote file storage, filename_if_copying set
- filename, copied = self.workbench_manager.possibly_localize_file(
+ filename = self.workbench_manager.possibly_localize_file(
this_workbench, this_storage, filepath, 'thisfile')
assert filename == os.path.join(
this_workbench, 'thisfile.txt')
# fake remote file storage, filename_if_copying set,
# keep_extension_if_copying set to false
- filename, copied = self.workbench_manager.possibly_localize_file(
+ filename = self.workbench_manager.possibly_localize_file(
this_workbench, this_storage, filepath, 'thisfile.text', False)
assert filename == os.path.join(
this_workbench, 'thisfile.text')
filename_if_copying yourself, it'll be set for you (assuming such an
extension can be extacted from the filename in the filepath).
- Also returns whether or not it copied the file locally.
-
Returns:
- (localized_filename, copied_locally)
- The first of these bieng the absolute filename as described above as a
- unicode string, the second being a boolean stating whether or not we
- had to copy the file locally.
+ localized_filename
Examples:
>>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', local_storage,
... ['path', 'to', 'foobar.jpg'])
- (u'/local/storage/path/to/foobar.jpg', False)
+ u'/local/storage/path/to/foobar.jpg'
>>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg'])
- (u'/our/workbench/subdir/foobar.jpg', True)
+ '/our/workbench/subdir/foobar.jpg'
>>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg'], 'source.jpeg', False)
- (u'/our/workbench/subdir/foobar.jpeg', True)
+ '/our/workbench/subdir/foobar.jpeg'
>>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg'], 'source', True)
- (u'/our/workbench/subdir/foobar.jpg', True)
+ '/our/workbench/subdir/foobar.jpg'
"""
if storage.local_storage:
- return (storage.get_local_path(filepath), False)
+ return storage.get_local_path(filepath)
else:
if filename_if_copying is None:
dest_filename = filepath[-1]
storage.copy_locally(
filepath, full_dest_filename)
- return (full_dest_filename, True)
+ return full_dest_filename