-
Notifications
You must be signed in to change notification settings - Fork 7
Add transforms for girder items and folders #37
base: master
Are you sure you want to change the base?
Conversation
somehow these didn't exist yet
@property | ||
def local_path(self): | ||
if self._local_path is None: | ||
self._local_path = os.path.join(tempfile.mkdtemp(), str(self._id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the virtues of downloading an item via the old Girder worker methods was that the names of the files were the original names in the item (with some sanitization). This has the problem that two files with the same name would conflict, but the virtue that a task that uses a group of files in a item has expected names. For a single file, this is usually just the loss of the extension, but when downloading a whole item, the names of files relative to each other are more useful. It would be better to uses the original file name (projects like gaia would otherwise need to reimplement this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of an item with multiple files, the files will still retain their names from the server, and will be siblings on the filesystem: https://github.com/girder/girder/blob/master/clients/python/girder_client/__init__.py#L1294-L1309
However, I do think it's a bug that a single file download loses its name. Placing each resource inside a folder by its ID is a good feature because it prevents collision based on name, but we don't want to lose either the name or the file extension.
I think I'd prefer to fix that problem on a future PR, though, since it was not introduced by this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that we can let the calling context decide by adding an optional file_name
kwarg to __init__(...)
and just using the ID if its not passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my plan.
There's a related PR in girder_worker, which is the feature I actually need currently. |
return self._local_path | ||
|
||
def cleanup(self): | ||
shutil.rmtree(os.path.dirname(self.local_path), ignore_errors=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to remove the downloaded folder or file, but not the tempdir that was created.
For cleanup i think you're going to have to track the temporary directory separately from the folder/file that is downloaded. you might as well bake that into |
somehow these didn't exist yet