Skip to content

Commit db4c1db

Browse files
authored
Add get_containers (#59)
* create get_containers method and add to container wrapper * Update CHANGE.txt * Bump version to 2.5.0 * Format with black
1 parent a201425 commit db4c1db

File tree

4 files changed

+90
-30
lines changed

4 files changed

+90
-30
lines changed

CHANGE.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
LabKey Python Client API News
33
+++++++++++
44

5-
What's New in the LabKey 2.4.2 package
5+
What's New in the LabKey 2.5.0 package
66
==============================
77

8-
*Release date: TBD*
9-
- Container API - add ability to rename containers
8+
*Release date: 07/06/2023*
9+
- Container API
10+
- add rename
11+
- add get_containers
12+
- Add transform_helper to labkey.utils
13+
- See docs in docs/transform_helper.md for more information
1014

1115
What's New in the LabKey 2.4.1 package
1216
==============================

labkey/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# limitations under the License.
1515
#
1616
__title__ = "labkey"
17-
__version__ = "2.4.1"
17+
__version__ = "2.5.0"
1818
__author__ = "LabKey"
1919
__license__ = "Apache License 2.0"

labkey/container.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,43 @@ def rename(
7070
return server_context.make_request(url, json=payload)
7171

7272

73+
def get_containers(
74+
server_context: ServerContext,
75+
container_path: str = None,
76+
include_effective_permissions: bool = True,
77+
include_subfolders: bool = False,
78+
depth: int = 50,
79+
include_standard_properties: bool = True,
80+
):
81+
"""
82+
Gets the containers for a given container_path
83+
:param server_context: a ServerContext object
84+
:param container_path: The container path to query against, defaults to the container path of the ServerContext
85+
:param include_effective_permissions: If set to false, the effective permissions for this container resource will
86+
not be included (defaults to True)
87+
:param include_subfolders: If set to true, the entire branch of containers will be returned. If false, only the
88+
immediate children of the starting container will be returned (defaults to False).
89+
:param depth: May be used to control the depth of recursion if includeSubfolders is set to true
90+
:param include_standard_properties: Includes the standard properties for containers, if f False returns a limited
91+
subset of properties: ['path', 'children', 'name', 'id'] (defaults to True)
92+
:return:
93+
"""
94+
url = server_context.build_url("project", "getContainers.view", container_path=container_path)
95+
payload = {
96+
"includeSubfolders": include_subfolders,
97+
"includeEffectivePermissions": include_effective_permissions,
98+
"includeStandardProperties": include_standard_properties,
99+
}
100+
101+
if include_subfolders:
102+
payload["depth"] = depth
103+
104+
return server_context.make_request(url, json=payload)
105+
106+
73107
class ContainerWrapper:
74108
"""
75-
Wrapper for all of the API methods exposed in the container module. Used by the APIWrapper class.
109+
Wrapper for all the API methods exposed in the container module. Used by the APIWrapper class.
76110
"""
77111

78112
def __init__(self, server_context: ServerContext):
@@ -95,6 +129,27 @@ def delete(self, container_path: str = None):
95129
return delete(self.server_context, container_path)
96130

97131
def rename(
98-
self, name: str = None, title: str = None, add_alias: bool = True, container_path: str = None
132+
self,
133+
name: str = None,
134+
title: str = None,
135+
add_alias: bool = True,
136+
container_path: str = None,
99137
):
100138
return rename(self.server_context, name, title, add_alias, container_path)
139+
140+
def get_containers(
141+
self,
142+
container_path: str = None,
143+
include_effective_permissions: bool = True,
144+
include_subfolders: bool = True,
145+
depth: int = 50,
146+
include_standard_properties: bool = True,
147+
):
148+
return get_containers(
149+
self.server_context,
150+
container_path,
151+
include_effective_permissions,
152+
include_subfolders,
153+
depth,
154+
include_standard_properties,
155+
)

labkey/utils.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,40 @@ def json_dumps(*args, **kwargs):
3434

3535

3636
def transform_helper(user_transform_func, file_path_run_properties):
37-
#file_path_run_properties must be explicitly defined as ${runInfo} within the user's transform script
38-
#parse run properties to for results data in and out filepaths
39-
file_path_in = ''
40-
file_path_out = ''
37+
# file_path_run_properties must be explicitly defined as ${runInfo} within the user's transform script
38+
# parse run properties to for results data in and out filepaths
39+
file_path_in = ""
40+
file_path_out = ""
4141
with open(file_path_run_properties) as file_run_properties:
4242
for l in file_run_properties:
43-
row = l.strip().split('\t')
44-
if row[0] == 'runDataFile':
43+
row = l.strip().split("\t")
44+
if row[0] == "runDataFile":
4545
file_path_out = row[3]
46-
if row[0] == 'runDataUploadedFile':
46+
if row[0] == "runDataUploadedFile":
4747
file_path_in = row[1]
48-
49-
#parse results data into array, confirming supported file type is used
48+
49+
# parse results data into array, confirming supported file type is used
5050
with open(file_path_in) as file_in:
5151
data_grid = []
5252

5353
for l in file_in:
54-
if '\t' in l:
55-
row = l.replace('\n', '').split('\t')
56-
elif ',' in l:
57-
row = l.replace('\n', '').split(',')
54+
if "\t" in l:
55+
row = l.replace("\n", "").split("\t")
56+
elif "," in l:
57+
row = l.replace("\n", "").split(",")
5858
else:
59-
raise ValueError('Unsupported file type or delimiter used. Header used: \n' + str(l))
60-
data_grid.append(row)
61-
62-
#run user transform on parsed results data array
59+
raise ValueError(
60+
"Unsupported file type or delimiter used. Header used: \n" + str(l)
61+
)
62+
data_grid.append(row)
63+
64+
# run user transform on parsed results data array
6365
transformed_grid = user_transform_func(data_grid)
64-
65-
#write transformed results data array to LabKey assay results data grid
66-
#transformed array must be a python list object, not a numpy array or pandas dataframe
67-
with open(file_path_out, mode='w') as file_out:
66+
67+
# write transformed results data array to LabKey assay results data grid
68+
# transformed array must be a python list object, not a numpy array or pandas dataframe
69+
with open(file_path_out, mode="w") as file_out:
6870
for row in transformed_grid:
6971
row = [str(el).strip() for el in row]
70-
row = '\t'.join(row)
71-
file_out.write(row + '\n')
72-
72+
row = "\t".join(row)
73+
file_out.write(row + "\n")

0 commit comments

Comments
 (0)