Skip to content

Commit 14e6920

Browse files
authored
Merge pull request #1520 from mrvisscher/major-project-hash-fixes
Fix issues with project hash difference between BW Legacy and BW25
2 parents 14ee7da + f31a8bd commit 14e6920

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

activity_browser/actions/project/project_delete.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import shutil
2+
13
from qtpy import QtWidgets
24

5+
import bw2data as bd
6+
from bw2data.project import ProjectDataset
7+
from bw2data.utils import safe_filename
8+
39
from activity_browser import settings, application
410
from activity_browser.actions.base import ABAction, exception_dialogs
5-
from activity_browser.mod import bw2data as bd
611
from activity_browser.ui.icons import qicons
712

13+
from .project_switch import ProjectSwitch
14+
815

916
class ProjectDelete(ABAction):
1017
"""
@@ -62,18 +69,28 @@ def run(project_names: [str] = None):
6269

6370
# try to delete the project, delete directory if user specified so
6471
if bd.projects.current in project_names:
65-
bd.projects.set_current(settings.ab_settings.startup_project)
72+
ProjectSwitch.run(settings.ab_settings.startup_project)
6673

6774
for project in project_names:
68-
bd.projects.delete_project(
69-
project, delete_dialog.deletion_warning_checked()
70-
)
75+
ProjectDelete.delete_project(project, delete_dialog.deletion_warning_checked())
7176

7277
# inform the user of successful deletion
7378
QtWidgets.QMessageBox.information(
7479
application.main_window, "Project(s) deleted", "Project(s) successfully deleted"
7580
)
7681

82+
@staticmethod
83+
def delete_project(name: str, delete_dir: bool):
84+
85+
ds = ProjectDataset.get(ProjectDataset.name == name)
86+
87+
if delete_dir:
88+
dir_path = bd.projects._base_data_dir / safe_filename(name, full=ds.full_hash)
89+
assert dir_path.is_dir(), "Can't find project directory"
90+
shutil.rmtree(dir_path)
91+
92+
ds.delete_instance()
93+
7794

7895
class ProjectDeletionDialog(QtWidgets.QDialog):
7996

activity_browser/actions/project/project_export.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
from qtpy import QtWidgets, QtCore
77

8+
import bw2data as bd
9+
from bw2data.project import ProjectDataset
10+
811
from activity_browser import application
9-
from activity_browser.mod import bw2data as bd
1012
from activity_browser.actions.base import ABAction, exception_dialogs
1113
from activity_browser.ui.threading import ABThread
1214

@@ -65,7 +67,9 @@ class ExportThread(ABThread):
6567
project_name: str
6668

6769
def run_safely(self):
68-
project_dir = os.path.join(bd.projects._base_data_dir, bd.utils.safe_filename(self.project_name))
70+
ds = ProjectDataset.get(ProjectDataset.name == self.project_name)
71+
project_folder_name = bd.utils.safe_filename(self.project_name, full=ds.full_hash)
72+
project_dir = os.path.join(bd.projects._base_data_dir, project_folder_name)
6973

7074
with open(os.path.join(project_dir, ".project-name.json"), "w") as f:
7175
json.dump({"name": self.project_name}, f)

0 commit comments

Comments
 (0)