Skip to content

Commit

Permalink
improve the fetching function of the note in papyrus and update the R…
Browse files Browse the repository at this point in the history
…EADME file.
  • Loading branch information
liwei-lai committed Oct 20, 2012
1 parent df9774c commit 95cde98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Support Commands:
- group: group name of the record.
- item: item name of the record.
- value: value of the record. well, there is the place store the password.
- note(optional): note of the record, the lengths of the note is unlimit.
- note(optional): note of the record, the lengths of the note is unlimit but should be within the quotation marks (' or ").

Add a record to the program.

Expand All @@ -43,6 +43,7 @@ Support Commands:

args:
- record_id: the id of the record, `ls` is a useful command for lookup the record id.
- note(optional): note of the record, the lengths of the note is unlimit but should be within the quotation marks (' or ").

Update a record to the program.

Expand Down Expand Up @@ -74,7 +75,7 @@ some instance::
======================
help

(papyrus) >>> add web yahoo apassword
(papyrus) >>> add web yahoo apassword 'there is a note.'
(papyrus) >>> ls groups
* List all (group_id, group) pairs:
(0, web)
Expand All @@ -96,7 +97,7 @@ some instance::
group: web
record: yahoo
value: apassword
note: None
note: there is a note.
created: 2012-10-19_22:24:31.656777
update: 2012-10-19_22:24:31.656777
(papyrus) >>>
Expand Down
35 changes: 21 additions & 14 deletions papyrus.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,15 @@ def _validate_line(self, line, lengths, cmd):
u"`help {2}` get help message!").format(cmd, line, cmd)
if not line:
raise PapyrusException(err_msg)
argv = line.strip().split()
if len(argv) not in lengths:
if ("'" in line or '"' in line) and len(line.split()) >= 4:
args = line.split(' ', 3)
args[3] = args[3].strip("'\"")
else:
args = line.strip().split()
if len(args) not in lengths:
raise PapyrusException(err_msg)

return argv
return args

def _ls_case_groups(self, target):
print u"* List all (group_id, group) pairs:"
Expand Down Expand Up @@ -326,8 +330,8 @@ def do_ls(self, line):
List all the groups or records existing in the current program.
"""
argv = self._validate_line(line, lengths=(1, 2), cmd='ls')
target = argv[0]
args = self._validate_line(line, lengths=(1, 2), cmd='ls')
target = args[0]
if target.isdigit():
target = int(target)

Expand Down Expand Up @@ -358,9 +362,9 @@ def do_info(self, line):
Show the full infomation about specific record.
"""
argv = self._validate_line(line, lengths=(1,), cmd='info')
args = self._validate_line(line, lengths=(1,), cmd='info')
try:
rid = int(argv[0])
rid = int(args[0])
record = self.handler.records['_rid'][rid]
except ValueError:
print "The `record_id` should be a integer."
Expand All @@ -386,12 +390,13 @@ def do_add(self, line):
- group: group name of the record.
- item: item name of the record.
- value: value of the record. well, there is the place store the password.
- note(optional): note of the record, the lengths of the note is unlimit.
- note(optional): note of the record, the lengths of the note is unlimit
but should be within the quotation marks (' or ").
Add a record to the program.
"""
argv = self._validate_line(line, lengths=(3, 4), cmd='add')
if not self.handler.add_record(*argv):
args = self._validate_line(line, lengths=(3, 4), cmd='add')
if not self.handler.add_record(*args):
raise PapyrusException(u"Fail to add record to the program.")

def do_update(self, line):
Expand All @@ -401,11 +406,13 @@ def do_update(self, line):
args::
- record_id: the id of the record, `ls` is a useful command for
lookup the record id.
- note(optional): note of the record, the lengths of the note is unlimit
but should be within the quotation marks (' or ").
Update a record to the program.
"""
argv = self._validate_line(line, lengths=(2, 3), cmd='update')
if not self.handler.update_record(*argv):
args = self._validate_line(line, lengths=(2, 3), cmd='update')
if not self.handler.update_record(*args):
raise PapyrusException(u"Fail to update record to the program.")

def do_delete(self, line):
Expand All @@ -418,8 +425,8 @@ def do_delete(self, line):
Delete a record to the program.
"""
argv = self._validate_line(line, lengths=(1,), cmd='delete')
if not self.handler.delete_record(*argv):
args = self._validate_line(line, lengths=(1,), cmd='delete')
if not self.handler.delete_record(*args):
raise PapyrusException(u"Fail to delete record to the program.")

# def complete_update(self, text, line, begidx, endidx):
Expand Down

0 comments on commit 95cde98

Please sign in to comment.