Skip to content

Commit

Permalink
Added ability to add user and save vault from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdynick authored and sommer committed Jul 9, 2010
1 parent 8e00821 commit 7e86a7c
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/frontends/cmdline/loxodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self.vault = None
self.vault_file_name = None
self.vault_password = None
self.vault_modified = False

cmd.Cmd.__init__(self)
if sys.platform == "darwin":
Expand Down Expand Up @@ -87,14 +88,21 @@ def do_help(self, line):
return

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

def do_quit(self, line):
"""
Exits interactive mode.
"""
self.do_save();
return True

def do_save(self, line=None):
if self.vault_modified and self.vault_file_name and self.vault_password:
self.vault.write_to_file(self.vault_file_name, self.vault_password)
self.vault_modified = False
print "Changes Saved"


def do_EOF(self, line):
Expand All @@ -103,6 +111,35 @@ def do_EOF(self, line):
"""
return True

def do_add(self, line):
"""
Adds a user to the vault
Example: add USERNAME [TITLE, [GROUP]]
"""
if not line:
cmd.Cmd.do_help(self, "add")
return

line = line.split(" ")
entry = self.vault.Record.create()
entry.user = line[0]
if len(line) >= 2:
entry.title = line[1]
if len(line) >= 3:
entry.group = line[2]

passwd = getpass("Password: ")
passwd2 = getpass("Re-Type Password: ")
if passwd != passwd2:
print "Passwords don't match"
return

entry.passwd = passwd

self.vault.records.append(entry)
self.vault_modified = True
print "User Added, but not saved"

def do_ls(self, line):
"""
Expand Down

0 comments on commit 7e86a7c

Please sign in to comment.