diff options
author | Juhamatti Niemelä <iiska@iki.fi> | 2012-09-15 01:07:42 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-09-15 01:07:42 +0200 |
commit | 4f6e81c28ffa034677583417a7a982e4aadd5fb0 (patch) | |
tree | 482a4726218fca4a315aa9109381cbeeb94ec3f6 | |
parent | 02d0b9a8007fb8532e3b2af3557fdefbeb8bb9b2 (diff) | |
download | pass-4f6e81c28ffa034677583417a7a982e4aadd5fb0.tar.gz pass-4f6e81c28ffa034677583417a7a982e4aadd5fb0.tar.bz2 pass-4f6e81c28ffa034677583417a7a982e4aadd5fb0.zip |
Script for importing password data XML from KeepassX to password-store.
Diffstat (limited to '')
-rwxr-xr-x | contrib/keepassx2pass.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/contrib/keepassx2pass.py b/contrib/keepassx2pass.py new file mode 100755 index 0000000..86e2f11 --- /dev/null +++ b/contrib/keepassx2pass.py @@ -0,0 +1,37 @@ +#! /usr/bin/env python + +import sys + +from subprocess import Popen, PIPE +from xml.etree import ElementTree + +def path_for(element, path=''): + """ Generate path name from elements title and current path """ + title = element.find('title').text + return '/'.join([path, title]) + +def import_entry(element, path=''): + """ Import new password entry to password-store using pass insert + command """ + proc = Popen(['pass', 'insert', path_for(element, path)], + stdin=PIPE, stdout=PIPE) + proc.communicate(element.find('password').text + "\n") + proc.wait() + +def import_group(element, path=''): + """ Import all entries and sub-groups from given group """ + npath = path_for(element, path) + for group in element.findall('group'): + import_group(group, npath) + for entry in element.findall('entry'): + import_entry(entry, npath) + + +def main(xml_file): + """ Parse given KeepassX XML file and import password groups from it """ + with open(xml_file) as xml: + for group in ElementTree.XML(xml.read()).findall('group'): + import_group(group) + +if __name__ == '__main__': + main(sys.argv[1]) |