Don't bother returning whether or not we copied it or not, we can

figure that out by looking to see whether our storage is local or not.
This commit is contained in:
Christopher Allan Webber 2011-06-11 21:20:26 -05:00
parent a32acafa0b
commit fdc5003903
2 changed files with 11 additions and 17 deletions

View File

@ -65,9 +65,8 @@ class TestWorkbench(object):
our_file.write('Our file') our_file.write('Our file')
# with a local file storage # 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) this_workbench, this_storage, filepath)
assert copied is False
assert filename == os.path.join( assert filename == os.path.join(
tmpdir, 'dir1/dir2/ourfile.txt') tmpdir, 'dir1/dir2/ourfile.txt')
@ -78,20 +77,20 @@ class TestWorkbench(object):
with this_storage.get_file(filepath, 'w') as our_file: with this_storage.get_file(filepath, 'w') as our_file:
our_file.write('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) this_workbench, this_storage, filepath)
assert filename == os.path.join( assert filename == os.path.join(
this_workbench, 'ourfile.txt') this_workbench, 'ourfile.txt')
# fake remote file storage, filename_if_copying set # 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') this_workbench, this_storage, filepath, 'thisfile')
assert filename == os.path.join( assert filename == os.path.join(
this_workbench, 'thisfile.txt') this_workbench, 'thisfile.txt')
# fake remote file storage, filename_if_copying set, # fake remote file storage, filename_if_copying set,
# keep_extension_if_copying set to false # 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) this_workbench, this_storage, filepath, 'thisfile.text', False)
assert filename == os.path.join( assert filename == os.path.join(
this_workbench, 'thisfile.text') this_workbench, 'thisfile.text')

View File

@ -89,37 +89,32 @@ class WorkbenchManager(object):
filename_if_copying yourself, it'll be set for you (assuming such an filename_if_copying yourself, it'll be set for you (assuming such an
extension can be extacted from the filename in the filepath). extension can be extacted from the filename in the filepath).
Also returns whether or not it copied the file locally.
Returns: Returns:
(localized_filename, copied_locally) localized_filename
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.
Examples: Examples:
>>> wb_manager.possibly_localize_file( >>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', local_storage, ... '/our/workbench/subdir', local_storage,
... ['path', 'to', 'foobar.jpg']) ... ['path', 'to', 'foobar.jpg'])
(u'/local/storage/path/to/foobar.jpg', False) u'/local/storage/path/to/foobar.jpg'
>>> wb_manager.possibly_localize_file( >>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage, ... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg']) ... ['path', 'to', 'foobar.jpg'])
(u'/our/workbench/subdir/foobar.jpg', True) '/our/workbench/subdir/foobar.jpg'
>>> wb_manager.possibly_localize_file( >>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage, ... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg'], 'source.jpeg', False) ... ['path', 'to', 'foobar.jpg'], 'source.jpeg', False)
(u'/our/workbench/subdir/foobar.jpeg', True) '/our/workbench/subdir/foobar.jpeg'
>>> wb_manager.possibly_localize_file( >>> wb_manager.possibly_localize_file(
... '/our/workbench/subdir', remote_storage, ... '/our/workbench/subdir', remote_storage,
... ['path', 'to', 'foobar.jpg'], 'source', True) ... ['path', 'to', 'foobar.jpg'], 'source', True)
(u'/our/workbench/subdir/foobar.jpg', True) '/our/workbench/subdir/foobar.jpg'
""" """
if storage.local_storage: if storage.local_storage:
return (storage.get_local_path(filepath), False) return storage.get_local_path(filepath)
else: else:
if filename_if_copying is None: if filename_if_copying is None:
dest_filename = filepath[-1] dest_filename = filepath[-1]
@ -137,4 +132,4 @@ class WorkbenchManager(object):
storage.copy_locally( storage.copy_locally(
filepath, full_dest_filename) filepath, full_dest_filename)
return (full_dest_filename, True) return full_dest_filename