Permalink
Browse files

adds a generic csv importer

  • Loading branch information...
grahl committed Apr 6, 2012
1 parent ff67342 commit 7063d0f5d0c40fa711202c74f3da065d03f63bd2
Showing with 28 additions and 1 deletion.
  1. +28 −1 src/frontends/cmdline/loxodo.py
@@ -24,6 +24,7 @@
import readline
import cmd
import re
import csv
try:
import pygtk
import gtk
@@ -84,7 +85,7 @@ def do_help(self, line):
return

print "\nCommands:"
print " ".join(("ls", "show", "quit", "add", "save"))
print " ".join(("ls", "show", "quit", "add", "save", "import"))
print

def do_quit(self, line):
@@ -136,6 +137,32 @@ def do_add(self, line):
self.vault_modified = True
print "User Added, but not saved"

def do_import(self,line):
"""
Adds a CSV importer, based on CSV file
Example: /home/user/data.csv
Columns: Title,User,Password,URL,Group
"""
if not line:
cmd.Cmd.do_help(self, "import")
return

data = csv.reader(open(line,'rb'))
try:
for row in data:
entry = self.vault.Record.create()
entry.title = row[0]
entry.user = row[1]
entry.passwd = row[2]
entry.url = row[3]
entry.group = row[4]
self.vault.records.append(entry)
self.vault_modified = True
print "Import completed, but not saved."
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (line, data.line_num, e))

def do_ls(self, line):
"""
Show contents of this Vault. If an argument is added a case insensitive

0 comments on commit 7063d0f

Please sign in to comment.