Skip to content

Commit

Permalink
Apply some heuristics to make certain datasets look more like a binder
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Dec 12, 2019
1 parent f0cc56c commit 16f38e3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions server/tasks/import_binder.py
Expand Up @@ -17,6 +17,8 @@
from fs.mode import Mode
from fs.path import basename
from fs.permissions import Permissions
from fs.tarfs import ReadTarFS
from fs.zipfs import ReadZipFS
from girderfs.core import WtDmsGirderFS
from girder_client import GirderClient
from girder.constants import AccessType
Expand All @@ -34,6 +36,35 @@
from ..utils import getOrCreateRootFolder


def sanitize_binder(root):
root_listdir = root.listdir("/")

if len(root_listdir) != 1:
return

single_file_or_dir = root_listdir[0]

if root.isdir(single_file_or_dir):
with root.opendir(single_file_or_dir) as subdir:
copy_fs(subdir, root)
root.removetree("/" + single_file_or_dir)
sanitize_binder(root)

if root.isfile(single_file_or_dir):
if single_file_or_dir.endswith(".zip"):
archive_fs = ReadZipFS
elif ".tar" in root.listdir[0]:
archive_fs = ReadTarFS
else:
archive_fs = None

if archive_fs is not None:
with archive_fs(root.openbin(single_file_or_dir)) as archive:
copy_fs(archive, root)
root.remove("/" + single_file_or_dir)
sanitize_binder(root)


def run(job):
jobModel = Job()
jobModel.updateJob(job, status=JobStatus.RUNNING)
Expand Down Expand Up @@ -120,6 +151,7 @@ def run(job):
str(session["_id"]), girder_root + "/api/v1", str(token["_id"])
) as source_fs:
copy_fs(source_fs, destination_fs)
sanitize_binder(destination_fs)

Session().deleteSession(user, session)

Expand Down

0 comments on commit 16f38e3

Please sign in to comment.