Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Add transforms for girder items and folders #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zachmullen
Copy link
Member

somehow these didn't exist yet

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))
Copy link
Member

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).

Copy link
Member Author

@zachmullen zachmullen Oct 24, 2018

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.

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my plan.

@zachmullen
Copy link
Member Author

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)
Copy link
Contributor

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.

@kotfic
Copy link
Contributor

kotfic commented Oct 25, 2018

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 __init__() and check in local_path if self._tmp_dir (or whatever) is None, if it is then tempfile.mkdtemp()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants