|
| 1 | +import shutil |
| 2 | + |
1 | 3 | from qtpy import QtWidgets |
2 | 4 |
|
| 5 | +import bw2data as bd |
| 6 | +from bw2data.project import ProjectDataset |
| 7 | +from bw2data.utils import safe_filename |
| 8 | + |
3 | 9 | from activity_browser import settings, application |
4 | 10 | from activity_browser.actions.base import ABAction, exception_dialogs |
5 | | -from activity_browser.mod import bw2data as bd |
6 | 11 | from activity_browser.ui.icons import qicons |
7 | 12 |
|
| 13 | +from .project_switch import ProjectSwitch |
| 14 | + |
8 | 15 |
|
9 | 16 | class ProjectDelete(ABAction): |
10 | 17 | """ |
@@ -62,18 +69,28 @@ def run(project_names: [str] = None): |
62 | 69 |
|
63 | 70 | # try to delete the project, delete directory if user specified so |
64 | 71 | 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) |
66 | 73 |
|
67 | 74 | 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()) |
71 | 76 |
|
72 | 77 | # inform the user of successful deletion |
73 | 78 | QtWidgets.QMessageBox.information( |
74 | 79 | application.main_window, "Project(s) deleted", "Project(s) successfully deleted" |
75 | 80 | ) |
76 | 81 |
|
| 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 | + |
77 | 94 |
|
78 | 95 | class ProjectDeletionDialog(QtWidgets.QDialog): |
79 | 96 |
|
|
0 commit comments