Skip to content

add export folder #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion labkey/container.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .server_context import ServerContext

import os
from datetime import datetime

def create(
server_context: ServerContext,
Expand Down Expand Up @@ -103,6 +104,42 @@ def get_containers(

return server_context.make_request(url, json=payload)

def export_archive(
server_context: ServerContext,
container_path: str = None,
download_directory: str = None,
includeSubfolders: str = "on",
includePhi: str = "on",
exportPhiLevel: str = "Restricted",
location: str = "2"
):

"""
Export the select container's folder archive. A lot of API args are ignored. That could be addressed in future development.

:param server_context: A LabKey server context. See utils.create_server_context.
:param container_path: the path of where you want to create the container.
:return:
"""

data = {"includeSubfolders": "on",
"includePhi": "on",
"exportPhiLevel": "Restricted",
"location": "2"}
timestamp = datetime.now().strftime("%Y-%m-%d %H_%M_%S")
filename = f"exported_archive_{timestamp}.zip"

if download_directory != None:
os.chdir(download_directory)

url = server_context.build_url("admin", "exportFolder.view", container_path)
content = server_context.make_request(url, payload=data)['content']

with open(filename, "wb") as exported_file:
exported_file.write(content)

return content


class ContainerWrapper:
"""
Expand Down Expand Up @@ -153,3 +190,22 @@ def get_containers(
depth,
include_standard_properties,
)

def export_archive(
self,
container_path: str = None,
download_directory: str = None,
includeSubfolders: str = "on",
includePhi: str = "on",
exportPhiLevel: str = "Restricted",
location: str = "2"
):
return export_archive(
self.server_context,
container_path,
download_directory,
includeSubfolders,
includePhi,
exportPhiLevel,
location
)