Skip to content

Commit 7438c37

Browse files
authored
Read project list in settings wizard from database (#1194)
* Settings Wizard read Projects from Database #1074 * Fixed unsafe path * Added comments
1 parent f41d8d2 commit 7438c37

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

activity_browser/ui/wizards/settings_wizard.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import brightway2 as bw
33
from PySide2 import QtWidgets, QtCore
4+
from peewee import SqliteDatabase
45
import os
56
import re
67

@@ -109,12 +110,12 @@ def __init__(self, parent=None):
109110

110111
def bw_projects(self, path: str):
111112
""" Finds the bw_projects from the brightway2 environment provided by path"""
112-
projects = []
113-
for dir in [dir for dir in os.listdir(path) if os.path.isdir(path + "/" + dir)]:
114-
project = re.match(r'(\w+)\.', dir)
115-
if project:
116-
projects.append(project.group(1))
117-
return projects
113+
# open the project database
114+
db = SqliteDatabase(os.path.join(path, "projects.db"))
115+
116+
# find all project names using sql query and return
117+
cursor = db.execute_sql('SELECT "name" FROM "projectdataset"')
118+
return [ i[0] for i in cursor.fetchall()]
118119

119120
def restore_defaults(self):
120121
self.change_bw_dir(ab_settings.get_default_directory())

0 commit comments

Comments
 (0)