Skip to content

Commit

Permalink
Read project list in settings wizard from database (#1194)
Browse files Browse the repository at this point in the history
* Settings Wizard read Projects from Database #1074

* Fixed unsafe path

* Added comments
  • Loading branch information
mrvisscher authored Jan 9, 2024
1 parent f41d8d2 commit 7438c37
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions activity_browser/ui/wizards/settings_wizard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import brightway2 as bw
from PySide2 import QtWidgets, QtCore
from peewee import SqliteDatabase
import os
import re

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

def bw_projects(self, path: str):
""" Finds the bw_projects from the brightway2 environment provided by path"""
projects = []
for dir in [dir for dir in os.listdir(path) if os.path.isdir(path + "/" + dir)]:
project = re.match(r'(\w+)\.', dir)
if project:
projects.append(project.group(1))
return projects
# open the project database
db = SqliteDatabase(os.path.join(path, "projects.db"))

# find all project names using sql query and return
cursor = db.execute_sql('SELECT "name" FROM "projectdataset"')
return [ i[0] for i in cursor.fetchall()]

def restore_defaults(self):
self.change_bw_dir(ab_settings.get_default_directory())
Expand Down

0 comments on commit 7438c37

Please sign in to comment.