You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the parsers on the specified files and collect the results.
17
+
login with save_token=True don't forget!!
18
+
19
+
Args:
20
+
openbis (Openbis): An instance of the Openbis class from pyBIS, already logged in.
21
+
space_name (str): The space in openBIS where the entities will be stored.
22
+
project_name (str): The project in openBIS where the entities will be stored.
23
+
collection_name (str): The collection in openBIS where the entities will be stored.
24
+
files_parser (dict): A dictionary where keys are parser instances and values are lists of file paths to be parsed. E.g., {MasterdataParserExample(): ["path/to/file.json", "path/to/another_file.json"]}
25
+
"""
26
+
# Ensure openbis is provided
27
+
ifopenbisisNone:
28
+
logger.error("An instance of Openbis must be provided for the parser to run.")
29
+
return
30
+
# Ensure the space, project, and collection are set
31
+
ifnotproject_name:
32
+
logger.error("The Project name must be specified for the parser to run.")
33
+
return
34
+
# Ensure the files_parser is not empty
35
+
ifnotfiles_parser:
36
+
logger.error(
37
+
"No files or parsers to parse. Please provide valid file paths or contact an Admin to add missing parser."
38
+
)
39
+
return
40
+
41
+
# Specify the space
42
+
try:
43
+
space=openbis.get_space(space_name)
44
+
exceptException:
45
+
space=None
46
+
# If space is not found, use the user space
47
+
ifspaceisNone:
48
+
# user name as default space
49
+
forsinopenbis.get_spaces():
50
+
ifs.code.endswith(openbis.username.upper()):
51
+
space=s
52
+
logger.warning(
53
+
f"Space {space_name} does not exist in openBIS. "
54
+
f"Loading space for {openbis.username}."
55
+
)
56
+
break
57
+
# no space found
58
+
ifspaceisNone:
59
+
logger.error(
60
+
f"No usable Space for {openbis.username} in openBIS. Please create it first or notify an Admin."
61
+
)
62
+
return
63
+
64
+
# Get project if `project_name` already exists under the space or create a new one if it does not
65
+
ifproject_name.upper() in [p.codeforpinspace.get_projects()]:
66
+
project=space.get_project(project_name)
67
+
else:
68
+
logger.info("Replacing project code with uppercase and underscores.")
69
+
project=space.new_project(
70
+
code=project_name.replace(" ", "_").upper(),
71
+
description="New project created via automated parsing with `bam_masterdata`.",
72
+
)
73
+
project.save()
74
+
75
+
# Create a new pybis `COLLECTION` to store the generated objects
76
+
ifnotcollection_name:
77
+
logger.info(
78
+
"No Collection name specified. Attaching objects directly to Project."
79
+
)
80
+
collection_openbis=project
81
+
else:
82
+
ifcollection_name.upper() in [c.codeforcinproject.get_collections()]:
0 commit comments