Created
October 9, 2012 12:11
-
-
Save juba/3858437 to your computer and use it in GitHub Desktop.
Python script to convert pwsafe exportdb output to a KeePassX Xml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import csv | |
import datetime | |
import sys | |
import StringIO | |
from genshi.template import MarkupTemplate | |
class Bunch(object): | |
def __init__(self, **d): | |
self.__dict__ = d | |
TEMPLATE = """\ | |
<!DOCTYPE KEEPASSX_DATABASE> | |
<database xmlns:py="http://genshi.edgewall.org/"> | |
<group> | |
<title>Passwords</title> | |
<icon>1</icon> | |
<entry py:for="entry in entries"> | |
<title>${entry.group}.${entry.title}</title> | |
<username>${entry.username}</username> | |
<password>${entry.password}</password> | |
<url></url> | |
<comment>${entry.notes}</comment> | |
<icon>1</icon> | |
<creation>${now}</creation> | |
<lastaccess>${now}</lastaccess> | |
<lastmod>${now}</lastmod> | |
<expire>Never</expire> | |
</entry> | |
</group> | |
</database> | |
""" | |
lines = [l for l in sys.stdin.readlines() if not l.startswith("#")][1:] | |
dialect = csv.Sniffer().sniff(''.join(lines)) | |
entries = [] | |
for (_id, group, title, username, password, notes) in csv.reader(lines, dialect=dialect): | |
entry = Bunch(group=group, username=username, title=title, password=password, notes=notes) | |
entries.append(entry) | |
now = datetime.datetime.now() | |
output = MarkupTemplate(TEMPLATE).generate(entries=entries, now=now).render() | |
print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from : http://argandgahandapandpa.wordpress.com/2011/06/23/moving-from-pwsafe-to-keepassx/