Skip to content

Commit e1c6635

Browse files
authored
Merge pull request Pennyw0rth#433 from Pennyw0rth/neff-fix-database-creation
Fix a bug with the databases when a new protocol is added
2 parents 27313a0 + c2dfa67 commit e1c6635

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

nxc/database.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,8 @@ def write_configfile(config, config_path):
4545
config.write(configfile)
4646

4747

48-
def create_workspace(workspace_name, p_loader=None):
49-
"""
50-
Create a new workspace with the given name.
51-
52-
Args:
53-
----
54-
workspace_name (str): The name of the workspace.
55-
56-
Returns:
57-
-------
58-
None
59-
"""
60-
if exists(path_join(WORKSPACE_DIR, workspace_name)):
61-
print(f"[-] Workspace {workspace_name} already exists")
62-
else:
63-
print(f"[*] Creating {workspace_name} workspace")
64-
mkdir(path_join(WORKSPACE_DIR, workspace_name))
65-
48+
def init_protocol_dbs(workspace_name, p_loader=None):
49+
"""Check for each protocol if the database exists, if not create it."""
6650
if p_loader is None:
6751
p_loader = ProtocolLoader()
6852
protocols = p_loader.get_protocols()
@@ -87,11 +71,35 @@ def create_workspace(workspace_name, p_loader=None):
8771
conn.close()
8872

8973

74+
def create_workspace(workspace_name, p_loader=None):
75+
"""
76+
Create a new workspace with the given name.
77+
78+
Args:
79+
----
80+
workspace_name (str): The name of the workspace.
81+
82+
Returns:
83+
-------
84+
None
85+
"""
86+
if exists(path_join(WORKSPACE_DIR, workspace_name)):
87+
print(f"[-] Workspace {workspace_name} already exists")
88+
else:
89+
print(f"[*] Creating {workspace_name} workspace")
90+
mkdir(path_join(WORKSPACE_DIR, workspace_name))
91+
92+
init_protocol_dbs(workspace_name, p_loader)
93+
94+
9095
def delete_workspace(workspace_name):
9196
shutil.rmtree(path_join(WORKSPACE_DIR, workspace_name))
9297
print(f"[*] Workspace {workspace_name} deleted")
9398

9499

95100
def initialize_db():
96101
if not exists(path_join(WORKSPACE_DIR, "default")):
97-
create_workspace("default")
102+
create_workspace("default")
103+
104+
# Even if the default workspace exists, we still need to check if every protocol has a database (in case of a new protocol)
105+
init_protocol_dbs("default")

0 commit comments

Comments
 (0)