From 62e703f5a71fcc2470aaac85c0ec39f4976cf914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20G=C3=BCnther?= Date: Fri, 5 Feb 2016 20:58:18 +0100 Subject: keepass2pass.py: Don't import all entries twice Without this patch, all entries are processed twice: once in the first call to import_group (which recursively processes all entries), then in the following import_group on all subgroups. This leads to spurious warnings ("Duplicate needs merging") and extra text added to each entry. --- contrib/importers/keepass2pass.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'contrib') diff --git a/contrib/importers/keepass2pass.py b/contrib/importers/keepass2pass.py index 80a2ad9..f4147fc 100755 --- a/contrib/importers/keepass2pass.py +++ b/contrib/importers/keepass2pass.py @@ -72,9 +72,10 @@ def import_entry(entries, element, path=''): entries[element_path] = data -def import_group(entries, element, path=''): +def import_group(entries, element, path='', npath=None): """ Import all entries and sub-groups from given group """ - npath = path_for(element, path) + if npath is None: + npath = path_for(element, path) for group in element.findall('Group'): import_group(entries, group, npath) for entry in element.findall('Entry'): @@ -90,11 +91,7 @@ def import_passwords(xml_file, root_path=None): xml_tree = ElementTree.XML(text) root = xml_tree.find('Root') root_group = root.find('Group') - import_group(entries,root_group,'') - if root_path is None: root_path = root_group.find('Name').text - groups = root_group.findall('Group') - for group in groups: - import_group(entries, group, root_path) + import_group(entries, root_group, '', root_path) password_count = 0 for path, data in sorted(entries.iteritems()): sys.stdout.write("[>>>>] Importing %s ... " % path.encode("utf-8")) -- cgit v1.2.3