1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- """
- 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
- from pwman.ui.baseui import 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, **kwargs):
- """
- initialize CLI interface, set up the DB
- connecion, see if we have xsel ...
- """
- super(PwmanCliNew, self).__init__(**kwargs)
- 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> "
|