|
@@ -1,15 +1,15 @@
|
|
#============================================================================
|
|
#============================================================================
|
|
# This file is part of Pwman3.
|
|
# This file is part of Pwman3.
|
|
-#
|
|
|
|
|
|
+#
|
|
# Pwman3 is free software; you can redistribute it and/or modify
|
|
# Pwman3 is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License, version 2
|
|
# it under the terms of the GNU General Public License, version 2
|
|
-# as published by the Free Software Foundation;
|
|
|
|
-#
|
|
|
|
|
|
+# as published by the Free Software Foundation;
|
|
|
|
+#
|
|
# Pwman3 is distributed in the hope that it will be useful,
|
|
# Pwman3 is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
# GNU General Public License for more details.
|
|
-#
|
|
|
|
|
|
+#
|
|
# You should have received a copy of the GNU General Public License
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Pwman3; if not, write to the Free Software
|
|
# along with Pwman3; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
@@ -54,7 +54,7 @@ except ImportError, e:
|
|
class CLICallback(Callback):
|
|
class CLICallback(Callback):
|
|
def getinput(self, question):
|
|
def getinput(self, question):
|
|
return raw_input(question)
|
|
return raw_input(question)
|
|
-
|
|
|
|
|
|
+
|
|
def getsecret(self, question):
|
|
def getsecret(self, question):
|
|
return getpass.getpass(question + ":")
|
|
return getpass.getpass(question + ":")
|
|
|
|
|
|
@@ -79,7 +79,7 @@ class PwmanCli(cmd.Cmd):
|
|
else:
|
|
else:
|
|
# traceback.print_exc()
|
|
# traceback.print_exc()
|
|
print "Error: %s " % (exception)
|
|
print "Error: %s " % (exception)
|
|
-
|
|
|
|
|
|
+
|
|
def do_EOF(self, args):
|
|
def do_EOF(self, args):
|
|
return self.do_exit(args)
|
|
return self.do_exit(args)
|
|
|
|
|
|
@@ -109,10 +109,10 @@ class PwmanCli(cmd.Cmd):
|
|
ids += range(int(m.group(1)),
|
|
ids += range(int(m.group(1)),
|
|
int(m.group(2))+1)
|
|
int(m.group(2))+1)
|
|
return ids
|
|
return ids
|
|
-
|
|
|
|
|
|
+
|
|
def get_filesystem_path(self, default=""):
|
|
def get_filesystem_path(self, default=""):
|
|
return getinput("Enter filename: ", default)
|
|
return getinput("Enter filename: ", default)
|
|
-
|
|
|
|
|
|
+
|
|
def get_username(self, default=""):
|
|
def get_username(self, default=""):
|
|
return getinput("Username: ", default)
|
|
return getinput("Username: ", default)
|
|
|
|
|
|
@@ -170,7 +170,7 @@ class PwmanCli(cmd.Cmd):
|
|
for tn in tagstrings:
|
|
for tn in tagstrings:
|
|
tags.append(Tag(tn))
|
|
tags.append(Tag(tn))
|
|
return tags
|
|
return tags
|
|
-
|
|
|
|
|
|
+
|
|
def print_node(self, node):
|
|
def print_node(self, node):
|
|
width = str(_defaultwidth)
|
|
width = str(_defaultwidth)
|
|
print "Node %d." % (node.get_id())
|
|
print "Node %d." % (node.get_id())
|
|
@@ -184,7 +184,7 @@ class PwmanCli(cmd.Cmd):
|
|
node.get_notes())
|
|
node.get_notes())
|
|
print typeset("Tags: ", ANSI.Red),
|
|
print typeset("Tags: ", ANSI.Red),
|
|
for t in node.get_tags():
|
|
for t in node.get_tags():
|
|
- print "%s " % t.get_name(),
|
|
|
|
|
|
+ print "rr %s " % t.get_name(),
|
|
print
|
|
print
|
|
|
|
|
|
def heardEnter():
|
|
def heardEnter():
|
|
@@ -203,7 +203,7 @@ class PwmanCli(cmd.Cmd):
|
|
if ret is not None:
|
|
if ret is not None:
|
|
return True
|
|
return True
|
|
return False
|
|
return False
|
|
-
|
|
|
|
|
|
+
|
|
def waituntil_enter(somepredicate,timeout, period=0.25):
|
|
def waituntil_enter(somepredicate,timeout, period=0.25):
|
|
mustend = time.time() + timeout
|
|
mustend = time.time() + timeout
|
|
while time.time() < mustend:
|
|
while time.time() < mustend:
|
|
@@ -212,13 +212,13 @@ class PwmanCli(cmd.Cmd):
|
|
break
|
|
break
|
|
time.sleep(period)
|
|
time.sleep(period)
|
|
self.do_cls('')
|
|
self.do_cls('')
|
|
-
|
|
|
|
|
|
+
|
|
if sys.platform != 'win32':
|
|
if sys.platform != 'win32':
|
|
print "Type Enter to flush screen (autoflash in 5 sec.)"
|
|
print "Type Enter to flush screen (autoflash in 5 sec.)"
|
|
waituntil_enter(heardEnter, 5)
|
|
waituntil_enter(heardEnter, 5)
|
|
else:
|
|
else:
|
|
print "Press any key to flush screen (autoflash in 5 sec.)"
|
|
print "Press any key to flush screen (autoflash in 5 sec.)"
|
|
- waituntil_enter(heardEnterWin, 5)
|
|
|
|
|
|
+ waituntil_enter(heardEnterWin, 5)
|
|
|
|
|
|
def do_tags(self, arg):
|
|
def do_tags(self, arg):
|
|
tags = self._db.listtags()
|
|
tags = self._db.listtags()
|
|
@@ -237,7 +237,7 @@ class PwmanCli(cmd.Cmd):
|
|
enc = CryptoEngine.get()
|
|
enc = CryptoEngine.get()
|
|
if not enc.alive():
|
|
if not enc.alive():
|
|
return strings
|
|
return strings
|
|
-
|
|
|
|
|
|
+
|
|
tags = self._db.listtags()
|
|
tags = self._db.listtags()
|
|
for t in tags:
|
|
for t in tags:
|
|
name = t.get_name()
|
|
name = t.get_name()
|
|
@@ -325,7 +325,7 @@ class PwmanCli(cmd.Cmd):
|
|
def do_export(self, arg):
|
|
def do_export(self, arg):
|
|
try:
|
|
try:
|
|
nodes = self.get_ids(arg)
|
|
nodes = self.get_ids(arg)
|
|
-
|
|
|
|
|
|
+
|
|
types = exporter.Exporter.types()
|
|
types = exporter.Exporter.types()
|
|
type = select("Select filetype:", types)
|
|
type = select("Select filetype:", types)
|
|
exp = exporter.Exporter.get(type)
|
|
exp = exporter.Exporter.get(type)
|
|
@@ -385,7 +385,7 @@ class PwmanCli(cmd.Cmd):
|
|
|
|
|
|
def do_rm(self, arg):
|
|
def do_rm(self, arg):
|
|
self.do_delete(arg)
|
|
self.do_delete(arg)
|
|
-
|
|
|
|
|
|
+
|
|
def do_delete(self, arg):
|
|
def do_delete(self, arg):
|
|
ids = self.get_ids(arg)
|
|
ids = self.get_ids(arg)
|
|
try:
|
|
try:
|
|
@@ -404,9 +404,9 @@ class PwmanCli(cmd.Cmd):
|
|
|
|
|
|
def do_ls(self, args):
|
|
def do_ls(self, args):
|
|
self.do_list(args)
|
|
self.do_list(args)
|
|
-
|
|
|
|
|
|
+
|
|
def do_list(self, args):
|
|
def do_list(self, args):
|
|
-
|
|
|
|
|
|
+
|
|
if len(args.split()) > 0:
|
|
if len(args.split()) > 0:
|
|
self.do_clear('')
|
|
self.do_clear('')
|
|
self.do_filter(args)
|
|
self.do_filter(args)
|
|
@@ -447,7 +447,7 @@ class PwmanCli(cmd.Cmd):
|
|
c = getonechar("Press <Space> for more, or 'Q' to cancel")
|
|
c = getonechar("Press <Space> for more, or 'Q' to cancel")
|
|
if c == 'q':
|
|
if c == 'q':
|
|
break
|
|
break
|
|
-
|
|
|
|
|
|
+
|
|
except Exception, e:
|
|
except Exception, e:
|
|
self.error(e)
|
|
self.error(e)
|
|
|
|
|
|
@@ -457,7 +457,7 @@ class PwmanCli(cmd.Cmd):
|
|
enc.forget()
|
|
enc.forget()
|
|
except Exception,e:
|
|
except Exception,e:
|
|
self.error(e)
|
|
self.error(e)
|
|
-
|
|
|
|
|
|
+
|
|
def do_passwd(self, args):
|
|
def do_passwd(self, args):
|
|
try:
|
|
try:
|
|
self._db.changepassword()
|
|
self._db.changepassword()
|
|
@@ -504,7 +504,7 @@ class PwmanCli(cmd.Cmd):
|
|
print "Config saved."
|
|
print "Config saved."
|
|
except Exception, e:
|
|
except Exception, e:
|
|
self.error(e)
|
|
self.error(e)
|
|
-
|
|
|
|
|
|
+
|
|
def do_cls(self,args):
|
|
def do_cls(self,args):
|
|
os.system('clear')
|
|
os.system('clear')
|
|
|
|
|
|
@@ -518,7 +518,7 @@ class PwmanCli(cmd.Cmd):
|
|
node = self._db.getnodes(ids)
|
|
node = self._db.getnodes(ids)
|
|
text_to_clipboards(node[0].get_password())
|
|
text_to_clipboards(node[0].get_password())
|
|
print """copied password for %s@%s clipboard... erasing in 10 sec...""" %\
|
|
print """copied password for %s@%s clipboard... erasing in 10 sec...""" %\
|
|
- (node[0].get_username(), node[0].get_url())
|
|
|
|
|
|
+ (node[0].get_username(), node[0].get_url())
|
|
time.sleep(10)
|
|
time.sleep(10)
|
|
text_to_clipboards("")
|
|
text_to_clipboards("")
|
|
except Exception, e:
|
|
except Exception, e:
|
|
@@ -528,7 +528,7 @@ class PwmanCli(cmd.Cmd):
|
|
|
|
|
|
def do_cp(self,args):
|
|
def do_cp(self,args):
|
|
self.do_copy(args)
|
|
self.do_copy(args)
|
|
-
|
|
|
|
|
|
+
|
|
def do_open(self, args):
|
|
def do_open(self, args):
|
|
ids = self.get_ids(args)
|
|
ids = self.get_ids(args)
|
|
if len(ids) > 1:
|
|
if len(ids) > 1:
|
|
@@ -548,12 +548,12 @@ class PwmanCli(cmd.Cmd):
|
|
##
|
|
##
|
|
def usage(self, string):
|
|
def usage(self, string):
|
|
print "Usage: %s" % (string)
|
|
print "Usage: %s" % (string)
|
|
-
|
|
|
|
|
|
+
|
|
def help_open(self):
|
|
def help_open(self):
|
|
self.usage("open <ID>")
|
|
self.usage("open <ID>")
|
|
print "Launch default browser with 'xdg-open url',\n\
|
|
print "Launch default browser with 'xdg-open url',\n\
|
|
the url must contain http:// or https://."
|
|
the url must contain http:// or https://."
|
|
-
|
|
|
|
|
|
+
|
|
def help_o(self):
|
|
def help_o(self):
|
|
self.help_open()
|
|
self.help_open()
|
|
|
|
|
|
@@ -570,7 +570,7 @@ the url must contain http:// or https://."
|
|
|
|
|
|
def help_ls(self):
|
|
def help_ls(self):
|
|
self.help_list()
|
|
self.help_list()
|
|
-
|
|
|
|
|
|
+
|
|
def help_list(self):
|
|
def help_list(self):
|
|
self.usage("list <tag> ...")
|
|
self.usage("list <tag> ...")
|
|
print "List nodes that match current or specified filter. ls is an alias."
|
|
print "List nodes that match current or specified filter. ls is an alias."
|
|
@@ -606,7 +606,7 @@ the url must contain http:// or https://."
|
|
self.usage("edit <ID|tag> ... ")
|
|
self.usage("edit <ID|tag> ... ")
|
|
print "Edits a nodes."
|
|
print "Edits a nodes."
|
|
self._mult_id_help()
|
|
self._mult_id_help()
|
|
-
|
|
|
|
|
|
+
|
|
def help_import(self):
|
|
def help_import(self):
|
|
self.usage("import [filename] ...")
|
|
self.usage("import [filename] ...")
|
|
print "Imports a nodes from a file."
|
|
print "Imports a nodes from a file."
|
|
@@ -615,14 +615,14 @@ the url must contain http:// or https://."
|
|
self.usage("export <ID|tag> ... ")
|
|
self.usage("export <ID|tag> ... ")
|
|
print "Exports a list of ids to an external format. If no IDs or tags are specified, then all nodes under the current filter are exported."
|
|
print "Exports a list of ids to an external format. If no IDs or tags are specified, then all nodes under the current filter are exported."
|
|
self._mult_id_help()
|
|
self._mult_id_help()
|
|
-
|
|
|
|
|
|
+
|
|
def help_new(self):
|
|
def help_new(self):
|
|
self.usage("new")
|
|
self.usage("new")
|
|
print "Creates a new node."
|
|
print "Creates a new node."
|
|
-
|
|
|
|
|
|
+
|
|
def help_rm(self):
|
|
def help_rm(self):
|
|
self.help_delete()
|
|
self.help_delete()
|
|
-
|
|
|
|
|
|
+
|
|
def help_print(self):
|
|
def help_print(self):
|
|
self.usage("print <ID|tag> ...")
|
|
self.usage("print <ID|tag> ...")
|
|
print "Displays a node. ",
|
|
print "Displays a node. ",
|
|
@@ -630,7 +630,7 @@ the url must contain http:// or https://."
|
|
|
|
|
|
def _mult_id_help(self):
|
|
def _mult_id_help(self):
|
|
print "Multiple ids and nodes can be specified, separated by a space. A range of ids can be specified in the format n-N. e.g. '10-20' would specify all nodes having ids from 10 to 20 inclusive. Tags are considered one-by-one. e.g. 'foo 2 bar' would yield to all nodes with tag 'foo', node 2 and all nodes with tag 'bar'."
|
|
print "Multiple ids and nodes can be specified, separated by a space. A range of ids can be specified in the format n-N. e.g. '10-20' would specify all nodes having ids from 10 to 20 inclusive. Tags are considered one-by-one. e.g. 'foo 2 bar' would yield to all nodes with tag 'foo', node 2 and all nodes with tag 'bar'."
|
|
-
|
|
|
|
|
|
+
|
|
def help_exit(self):
|
|
def help_exit(self):
|
|
self.usage("exit")
|
|
self.usage("exit")
|
|
print "Exits the application."
|
|
print "Exits the application."
|
|
@@ -642,10 +642,10 @@ the url must contain http:// or https://."
|
|
def help_set(self):
|
|
def help_set(self):
|
|
self.usage("set [configoption] [value]")
|
|
self.usage("set [configoption] [value]")
|
|
print "Sets a configuration option. If no value is specified, the current value for [configoption] is output. If neither [configoption] nor [value] are specified, the whole current configuration is output. [configoption] must be of the format <section>.<option>"
|
|
print "Sets a configuration option. If no value is specified, the current value for [configoption] is output. If neither [configoption] nor [value] are specified, the whole current configuration is output. [configoption] must be of the format <section>.<option>"
|
|
-
|
|
|
|
|
|
+
|
|
def help_ls(self):
|
|
def help_ls(self):
|
|
self.help_list()
|
|
self.help_list()
|
|
-
|
|
|
|
|
|
+
|
|
def help_passwd(self):
|
|
def help_passwd(self):
|
|
self.usage("passwd")
|
|
self.usage("passwd")
|
|
print "Changes the password on the database. "
|
|
print "Changes the password on the database. "
|
|
@@ -665,14 +665,18 @@ the url must contain http:// or https://."
|
|
def help_tags(self):
|
|
def help_tags(self):
|
|
self.usage("tags")
|
|
self.usage("tags")
|
|
print "Displays all tags in used in the database."
|
|
print "Displays all tags in used in the database."
|
|
-
|
|
|
|
|
|
+
|
|
def postloop(self):
|
|
def postloop(self):
|
|
try:
|
|
try:
|
|
readline.write_history_file(self._historyfile)
|
|
readline.write_history_file(self._historyfile)
|
|
except Exception, e:
|
|
except Exception, e:
|
|
pass
|
|
pass
|
|
-
|
|
|
|
|
|
+
|
|
def __init__(self, db, hasxsel):
|
|
def __init__(self, db, hasxsel):
|
|
|
|
+ """
|
|
|
|
+ initialize CLI interface, set up the DB
|
|
|
|
+ connecion, see if we have xsel ...
|
|
|
|
+ """
|
|
cmd.Cmd.__init__(self)
|
|
cmd.Cmd.__init__(self)
|
|
self.intro = "%s %s (c) %s <%s>" % (pwman.appname, pwman.version,
|
|
self.intro = "%s %s (c) %s <%s>" % (pwman.appname, pwman.version,
|
|
pwman.author, pwman.authoremail)
|
|
pwman.author, pwman.authoremail)
|
|
@@ -709,7 +713,7 @@ class PwmanCliMac(PwmanCli):
|
|
node[0].get_password()
|
|
node[0].get_password()
|
|
text_to_mcclipboard(node[0].get_password())
|
|
text_to_mcclipboard(node[0].get_password())
|
|
print """copied password for %s@%s clipboard... erasing in 10 sec...""" %\
|
|
print """copied password for %s@%s clipboard... erasing in 10 sec...""" %\
|
|
- (node[0].get_username(), node[0].get_url())
|
|
|
|
|
|
+ (node[0].get_username(), node[0].get_url())
|
|
time.sleep(10)
|
|
time.sleep(10)
|
|
text_to_clipboards("")
|
|
text_to_clipboards("")
|
|
except Exception, e:
|
|
except Exception, e:
|
|
@@ -717,7 +721,7 @@ class PwmanCliMac(PwmanCli):
|
|
|
|
|
|
def do_cp(self,args):
|
|
def do_cp(self,args):
|
|
self.do_copy(args)
|
|
self.do_copy(args)
|
|
-
|
|
|
|
|
|
+
|
|
def do_open(self, args):
|
|
def do_open(self, args):
|
|
ids = self.get_ids(args)
|
|
ids = self.get_ids(args)
|
|
if len(ids) > 1:
|
|
if len(ids) > 1:
|
|
@@ -732,7 +736,7 @@ class PwmanCliMac(PwmanCli):
|
|
|
|
|
|
def do_o(self, args):
|
|
def do_o(self, args):
|
|
self.do_open(args)
|
|
self.do_open(args)
|
|
-
|
|
|
|
|
|
+
|
|
##
|
|
##
|
|
## Help functions
|
|
## Help functions
|
|
##
|
|
##
|
|
@@ -740,7 +744,7 @@ class PwmanCliMac(PwmanCli):
|
|
self.usage("open <ID>")
|
|
self.usage("open <ID>")
|
|
print "Launch default browser with 'open url',\n\
|
|
print "Launch default browser with 'open url',\n\
|
|
the url must contain http:// or https://."
|
|
the url must contain http:// or https://."
|
|
-
|
|
|
|
|
|
+
|
|
def help_o(self):
|
|
def help_o(self):
|
|
self.help_open()
|
|
self.help_open()
|
|
|
|
|
|
@@ -757,7 +761,7 @@ def getonechar(question, width=_defaultwidth):
|
|
question = "%s " % (question)
|
|
question = "%s " % (question)
|
|
print question.ljust(width),
|
|
print question.ljust(width),
|
|
sys.stdout.flush()
|
|
sys.stdout.flush()
|
|
-
|
|
|
|
|
|
+
|
|
fd = sys.stdin.fileno()
|
|
fd = sys.stdin.fileno()
|
|
tty_mode = tty.tcgetattr(fd)
|
|
tty_mode = tty.tcgetattr(fd)
|
|
tty.setcbreak(fd)
|
|
tty.setcbreak(fd)
|
|
@@ -767,7 +771,7 @@ def getonechar(question, width=_defaultwidth):
|
|
tty.tcsetattr(fd, tty.TCSAFLUSH, tty_mode)
|
|
tty.tcsetattr(fd, tty.TCSAFLUSH, tty_mode)
|
|
print ch
|
|
print ch
|
|
return ch
|
|
return ch
|
|
-
|
|
|
|
|
|
+
|
|
def getyesno(question, defaultyes=False, width=_defaultwidth):
|
|
def getyesno(question, defaultyes=False, width=_defaultwidth):
|
|
if (defaultyes):
|
|
if (defaultyes):
|
|
default = "[Y/n]"
|
|
default = "[Y/n]"
|
|
@@ -801,7 +805,7 @@ def getinput(question, default="", completer=None, width=_defaultwidth):
|
|
readline.set_startup_hook(defaulter)
|
|
readline.set_startup_hook(defaulter)
|
|
oldcompleter = readline.get_completer()
|
|
oldcompleter = readline.get_completer()
|
|
readline.set_completer(completer)
|
|
readline.set_completer(completer)
|
|
-
|
|
|
|
|
|
+
|
|
x = raw_input(question.ljust(width))
|
|
x = raw_input(question.ljust(width))
|
|
|
|
|
|
readline.set_completer(oldcompleter)
|
|
readline.set_completer(oldcompleter)
|
|
@@ -822,8 +826,8 @@ def getpassword(question, width=_defaultwidth, echo=False):
|
|
return a1
|
|
return a1
|
|
else:
|
|
else:
|
|
print "Passwords don't match. Try again."
|
|
print "Passwords don't match. Try again."
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
def typeset(text, color, bold=False, underline=False):
|
|
def typeset(text, color, bold=False, underline=False):
|
|
if not config.get_value("Global", "colors") == 'yes':
|
|
if not config.get_value("Global", "colors") == 'yes':
|
|
return text
|
|
return text
|
|
@@ -858,12 +862,12 @@ def text_to_clipboards(text):
|
|
xsel_proc.communicate(text)
|
|
xsel_proc.communicate(text)
|
|
# "clipboard":
|
|
# "clipboard":
|
|
xsel_proc = sp.Popen(['xsel', '-bi'], stdin=sp.PIPE)
|
|
xsel_proc = sp.Popen(['xsel', '-bi'], stdin=sp.PIPE)
|
|
- xsel_proc.communicate(text)
|
|
|
|
|
|
+ xsel_proc.communicate(text)
|
|
except OSError, e:
|
|
except OSError, e:
|
|
print e, "\nExecuting xsel failed, is it installed ?\n \
|
|
print e, "\nExecuting xsel failed, is it installed ?\n \
|
|
please check your configuration file ... "
|
|
please check your configuration file ... "
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
def text_to_mcclipboards(text):
|
|
def text_to_mcclipboards(text):
|
|
"""
|
|
"""
|
|
copy text to mac os x clip board
|
|
copy text to mac os x clip board
|
|
@@ -889,12 +893,12 @@ def open_url(link, MacOS=False):
|
|
sp.Popen([uopen, link], stdin=sp.PIPE)
|
|
sp.Popen([uopen, link], stdin=sp.PIPE)
|
|
except OSError, e:
|
|
except OSError, e:
|
|
print "Executing open_url failed with:\n", e
|
|
print "Executing open_url failed with:\n", e
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
class CliMenu(object):
|
|
class CliMenu(object):
|
|
def __init__(self):
|
|
def __init__(self):
|
|
self.items = []
|
|
self.items = []
|
|
-
|
|
|
|
|
|
+
|
|
def add(self, item):
|
|
def add(self, item):
|
|
if (isinstance(item, CliMenuItem)):
|
|
if (isinstance(item, CliMenuItem)):
|
|
self.items.append(item)
|
|
self.items.append(item)
|
|
@@ -913,21 +917,21 @@ class CliMenu(object):
|
|
currentstr += ("%s " % (c))
|
|
currentstr += ("%s " % (c))
|
|
else:
|
|
else:
|
|
currentstr = current
|
|
currentstr = current
|
|
-
|
|
|
|
|
|
+
|
|
print ("%d - %-"+str(_defaultwidth)+"s %s") % (i, x.name+":",
|
|
print ("%d - %-"+str(_defaultwidth)+"s %s") % (i, x.name+":",
|
|
currentstr)
|
|
currentstr)
|
|
print "%c - Finish editing" % ('X')
|
|
print "%c - Finish editing" % ('X')
|
|
option = getonechar("Enter your choice:")
|
|
option = getonechar("Enter your choice:")
|
|
try:
|
|
try:
|
|
# substract 1 because array subscripts start at 1
|
|
# substract 1 because array subscripts start at 1
|
|
- selection = int(option) - 1
|
|
|
|
|
|
+ selection = int(option) - 1
|
|
value = self.items[selection].editor(self.items[selection].getter())
|
|
value = self.items[selection].editor(self.items[selection].getter())
|
|
self.items[selection].setter(value)
|
|
self.items[selection].setter(value)
|
|
except (ValueError,IndexError):
|
|
except (ValueError,IndexError):
|
|
if (option.upper() == 'X'):
|
|
if (option.upper() == 'X'):
|
|
break
|
|
break
|
|
print "Invalid selection"
|
|
print "Invalid selection"
|
|
-
|
|
|
|
|
|
+
|
|
class CliMenuItem(object):
|
|
class CliMenuItem(object):
|
|
def __init__(self, name, editor, getter, setter):
|
|
def __init__(self, name, editor, getter, setter):
|
|
self.name = name
|
|
self.name = name
|