Skip to content

Commit f8d153a

Browse files
committed
Enable duplication from functional-sqlite
1 parent cff003c commit f8d153a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

activity_browser/actions/activity/activity_duplicate_to_db.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from activity_browser.bwutils import refresh_node
1010
from activity_browser.actions.base import ABAction, exception_dialogs
1111
from activity_browser.ui.icons import qicons
12+
from bw_functional import Product
1213

1314
from .activity_open import ActivityOpen
1415

@@ -131,4 +132,27 @@ def duplicate_sqlite_to_functional_sqlite(nodes: list[bd.Node], to_db_name: str)
131132

132133
@staticmethod
133134
def duplicate_functional_sqlite_to_sqlite(nodes: list[bd.Node], to_db_name: str) -> list[bd.Node]:
134-
raise NotImplementedError("Duplicating from functional_sqlite to sqlite is not yet implemented.")
135+
new_nodes = []
136+
products = [prod for node in nodes if isinstance(node, bf.Process) for prod in node.products()]
137+
138+
for product in products:
139+
dataset = product.as_dict()
140+
dataset.pop("id", None)
141+
dataset.pop("key", None)
142+
143+
exchanges = product.virtual_edges
144+
dataset["database"] = to_db_name
145+
dataset["type"] = "processwithreferenceproduct"
146+
147+
new_node = bd.Node(**dataset)
148+
new_node.save()
149+
new_nodes.append(new_node)
150+
151+
for exc in exchanges:
152+
exc["output"] = (to_db_name, exc["output"][1])
153+
if exc["type"] == "production":
154+
exc["input"] = (to_db_name, new_node.key[1])
155+
new_exc = bd.Edge(**exc)
156+
new_exc.save()
157+
158+
return new_nodes

0 commit comments

Comments
 (0)