You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Request for a method to merge entries and databases in the pykeepass library. This feature would be highly beneficial for the ability to consolidate multiple KeePass databases or resolve conflicts between entries.
Proposed Feature
Introduce a method to merge the contents of one KeePass database into another, including groups and entries, with conflict resolution.
Suggested Method
pykeepass.merge_databases(src_db, trgt_db)
Description:
This method would allow users to merge the contents of a source KeePass database (src_db) into a target database (trgt_db), handling groups, entries, and conflicts in a structured manner.
Example Implementation
Below is a possible implementation of the merge_databases function:
defmerge_databases(source_db, target_db):
""" Merge the contents of the source KeePass database into the target KeePass database. Args: source_db (PyKeePass): The source database to merge from. target_db (PyKeePass): The target database to merge into. """defmerge_groups(source_group, target_group):
# Merge subgroupsforsource_subgroupinsource_group.subgroups:
target_subgroup=target_db.find_groups(
name=source_subgroup.name,
group=target_group,
first=True,
recursive=False
)
ifnottarget_subgroup:
target_subgroup=target_db.add_group(
target_group,
source_subgroup.name,
icon=source_subgroup.icon,
notes=source_subgroup.notes
)
merge_groups(source_subgroup, target_subgroup)
# Merge entriesforsource_entryinsource_group.entries:
target_entry=target_db.find_entries(
uuid=source_entry.uuid,
group=target_group,
first=True,
recursive=False
)
iftarget_entry:
# Handle conflictsprint(f"Conflict detected for entry: {source_entry.title}")
target_entry.title=source_entry.titleor""target_entry.username=source_entry.usernameor""target_entry.password=source_entry.passwordor""target_entry.url=source_entry.urlor""target_entry.notes=source_entry.notesor""target_entry.icon=source_entry.iconor""target_entry.tags=source_entry.tagsor""target_entry.otp=source_entry.otpor""try:
target_entry.autotype_enabled=source_entry.autotype_enabledexceptException:
passtry:
target_entry.autotype_sequence=source_entry.autotype_sequenceexceptException:
passtry:
target_entry.autotype_window=source_entry.autotype_windowexceptException:
passtarget_entry.history.extend(source_entry.history)
else:
# Add new entrytarget_db.add_entry(
target_group,
title=source_entry.title,
username=source_entry.username,
password=source_entry.password,
url=source_entry.url,
notes=source_entry.notes,
icon=source_entry.icon,
tags=source_entry.tags,
otp=source_entry.otp,
force_creation=True
)
merge_groups(source_db.root_group, target_db.root_group)
Benefits
Simplifies Database Management:
Users can easily consolidate multiple KeePass databases into one.
Conflict Resolution:
Provides a clear and structured way to handle conflicts between entries.
Enhanced Functionality:
Expands the capabilities of the pykeepass library, making it more versatile for advanced use cases.
The text was updated successfully, but these errors were encountered:
Summary
Request for a method to merge entries and databases in the
pykeepass
library. This feature would be highly beneficial for the ability to consolidate multiple KeePass databases or resolve conflicts between entries.Proposed Feature
Introduce a method to merge the contents of one KeePass database into another, including groups and entries, with conflict resolution.
Suggested Method
Description:
This method would allow users to merge the contents of a source KeePass database (
src_db
) into a target database (trgt_db
), handling groups, entries, and conflicts in a structured manner.Example Implementation
Below is a possible implementation of the
merge_databases
function:Benefits
Simplifies Database Management:
Users can easily consolidate multiple KeePass databases into one.
Conflict Resolution:
Provides a clear and structured way to handle conflicts between entries.
Enhanced Functionality:
Expands the capabilities of the
pykeepass
library, making it more versatile for advanced use cases.The text was updated successfully, but these errors were encountered: