12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """
- Define the CLI interface for pwman3 and the helper functions
- """
- from __future__ import print_function
- import pwman
- from pwman.util.crypto_engine import CryptoEngine
- import sys
- import cmd
- from pwman.ui.base import Aliases, BaseCommands
- try:
- import readline
- _readline_available = True
- except ImportError as e:
- _readline_available = False
- class PwmanCliNew(cmd.Cmd, Aliases, BaseCommands):
- """
- Inherit from the BaseCommands and Aliases
- """
- def __init__(self, db, hasxsel, callback, config_parser):
- """
- initialize CLI interface, set up the DB
- connecion, see if we have xsel ...
- """
- cmd.Cmd.__init__(self)
- self.intro = "%s %s (c) visit: %s" % (pwman.appname, pwman.version,
- pwman.website)
- self._historyfile = config_parser.get_value("Readline", "history")
- self.hasxsel = hasxsel
- self.config = config_parser
- try:
- enc = CryptoEngine.get()
- enc.callback = callback()
- self._db = db
-
- self._db.open()
- except Exception as e:
- self.error(e)
- sys.exit(1)
- try:
- readline.read_history_file(self._historyfile)
- except IOError as e:
- pass
- self.prompt = "pwman> "
|