# HG changeset patch # User Erik Grinaker # Date 1165916001 0 # Node ID faf1e560d20a2725428a38bfaa457939ed451318 # Parent a8035f5129f2dd7ee2aa2e82069e875fe608c397 added SplashID CSV import [Devan Goodwin] diff -r a8035f5129f2dd7ee2aa2e82069e875fe608c397 -r faf1e560d20a2725428a38bfaa457939ed451318 NEWS --- a/NEWS Sun Dec 03 22:08:46 2006 +0000 +++ b/NEWS Tue Dec 12 09:33:21 2006 +0000 @@ -5,6 +5,7 @@ - translation support - ported to gtk+ 2.8 and gnome 2.10 - added LUKS file import/export [John Lenz] +- added SplashID CSV file import [Devan Goodwin] - cleaned up preferences dialog - only show Revelation files by default in open and save dialogs @@ -24,7 +25,6 @@ - added swedish translation [Daniel Nylander] Code changes: -- depend on pygtk 2.8 and gnome-python 2.10 - improved build scripts - generate ChangeLog from subversion log during make dist - removed gnomemisc module diff -r a8035f5129f2dd7ee2aa2e82069e875fe608c397 -r faf1e560d20a2725428a38bfaa457939ed451318 src/lib/datahandler/Makefile.am --- a/src/lib/datahandler/Makefile.am Sun Dec 03 22:08:46 2006 +0000 +++ b/src/lib/datahandler/Makefile.am Tue Dec 12 09:33:21 2006 +0000 @@ -14,6 +14,7 @@ netrc.py \ pwsafe.py \ rvl.py \ + splashid.py \ text.py \ xhtml.py diff -r a8035f5129f2dd7ee2aa2e82069e875fe608c397 -r faf1e560d20a2725428a38bfaa457939ed451318 src/lib/datahandler/__init__.py --- a/src/lib/datahandler/__init__.py Sun Dec 03 22:08:46 2006 +0000 +++ b/src/lib/datahandler/__init__.py Tue Dec 12 09:33:21 2006 +0000 @@ -30,6 +30,7 @@ from netrc import NetRC from pwsafe import PasswordSafe1, PasswordSafe2, MyPasswordSafe, MyPasswordSafeOld, PasswordGorilla from rvl import RevelationXML, Revelation, RevelationLUKS +from splashid import SplashIDCSV from text import PlainText from xhtml import XHTML @@ -46,6 +47,7 @@ PlainText, Revelation, RevelationLUKS, + SplashIDCSV, XHTML, RevelationXML ] @@ -80,7 +82,7 @@ def get_import_handlers(): - "Returns a list of handlers which can import" + "Returns a list of handlers which can import" handlers = [] diff -r a8035f5129f2dd7ee2aa2e82069e875fe608c397 -r faf1e560d20a2725428a38bfaa457939ed451318 src/lib/datahandler/splashid.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/datahandler/splashid.py Tue Dec 12 09:33:21 2006 +0000 @@ -0,0 +1,108 @@ +# +# Revelation 0.4.7 - a password manager for GNOME 2 +# http://oss.codepoet.no/revelation/ +# $Id$ +# +# Module for importing data from CSV files. +# +# Copyright (c) 2006 Devan Goodwin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import csv, time + +import base +from revelation import data, entry + + +class SplashIDCSV(base.DataHandler): + """ + Data handler for CSV files generated by SplashID. + + While SplashID CSV files were used as the basis for this parser, + by arranging data in the format similar to what SplashID generates + (i.e. use a spreadsheet and export a CSV with the proper format) + one should be able to import any CSV file. + + SplashID's CSV data looks like the following: + + Type,Field 1,Field 2,Field 3,Field 4,Field 5,Field 6,Notes,Category + + The mapping to a Revelation generic entry takes place as follows: + + Type: Ignored + Field 1: Name + Field 2: Username + Field 3: Password + Field 4: Hostname + Field 5: Added to Description + Field 6: Added to Description + Notes: Added to Description + Category: Folder + """ + + name = "SplashID CSV" + importer = True + exporter = False + encryption = False + + def import_data(self, input, password): + """ Import data from a file into the entry store. """ + + # Replace any vertical tabs with spaces, SplashID seems to use + # these to seperate lines within a Notes field: + if input.count('\x0b'): + input = input.replace('\x0b', ' ') + + entrystore = data.EntryStore() + + # Maintain a hash of folder names to folder entries so we + # can use each category encountered to create a new folder + # by that name, or use an existing one if we've already + # created it: + folders = {} + + for line in input.splitlines(): + for row in csv.reader([line]): + + # Raise FormatError if we don't have all 9 fields + if len(row) != 9: + raise base.FormatError + + # Import the entry + e = entry.GenericEntry() + e.name = row[1] + e.description = " / ".join([ desc.strip() for desc in row[5:7] if desc.strip() != "" ]) + e.updated = time.time() + + e[entry.UsernameField] = row[2] + e[entry.PasswordField] = row[3] + e[entry.HostnameField] = row[4] + + # Create and/or add to folder based on category: + if folders.has_key(row[8]): + parent = folders[category] + + else: + folder = entry.FolderEntry() + folder.name = category + parent = entrystore.add_entry(new_folder) + folders[row[8]] = parent + + # Add the entry + entrystore.add_entry(e, parent) + + return entrystore