<s> from __future__ import print_function <EOL> import sys <EOL> import cmd <EOL> if sys . version_info . major > <NUM_LIT:2> : <EOL> raw_input = input <EOL> try : <EOL> import readline <EOL> _readline_available = True <EOL> except ImportError as e : <EOL> import pyreadline as readline <EOL> _readline_available = True <EOL> from pwman . ui . baseui import BaseCommands <EOL> from pwman import ( get_conf_options , get_db_version , version , website , parser_options ) <EOL> from pwman . ui . tools import CLICallback <EOL> from pwman . data import factory <EOL> from pwman . exchange . importer import Importer <EOL> from pwman . util . crypto_engine import CryptoEngine <EOL> class PwmanCli ( cmd . Cmd , BaseCommands ) : <EOL> """<STR_LIT>""" <EOL> undoc_header = "<STR_LIT>" <EOL> def __init__ ( self , db , hasxsel , callback , config_parser , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( PwmanCli , self ) . __init__ ( ** kwargs ) <EOL> self . intro = "<STR_LIT>" % ( '<STR_LIT>' , version , website ) <EOL> self . _historyfile = config_parser . get_value ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . hasxsel = hasxsel <EOL> self . config = config_parser <EOL> try : <EOL> enc = CryptoEngine . get ( ) <EOL> enc . callback = callback ( ) <EOL> self . _db = db <EOL> self . _db . open ( ) <EOL> except Exception as e : <EOL> self . error ( e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> readline . read_history_file ( self . _historyfile ) <EOL> except IOError as e : <EOL> pass <EOL> self . prompt = "<STR_LIT>" <EOL> def get_ui_platform ( platform ) : <EOL> if '<STR_LIT>' in platform : <EOL> from pwman . ui . mac import PwmanCliMac as PwmanCli <EOL> OSX = True <EOL> elif '<STR_LIT>' in platform : <EOL> from pwman . ui . win import PwmanCliWin as PwmanCli <EOL> OSX = False <EOL> else : <EOL> from pwman . ui . cli import PwmanCli <EOL> OSX = False <EOL> return PwmanCli , OSX <EOL> def main ( ) : <EOL> args = parser_options ( ) . parse_args ( ) <EOL> PwmanCli , OSX = get_ui_platform ( sys . platform ) <EOL> xselpath , dbtype , config = get_conf_options ( args , OSX ) <EOL> dburi = config . get_value ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> print ( dburi ) <EOL> dbver = get_db_version ( config , args ) <EOL> CryptoEngine . get ( ) <EOL> db = factory . createdb ( dburi , dbver ) <EOL> if args . file_delim : <EOL> importer = Importer ( ( args , config , db ) ) <EOL> importer . run ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> cli = PwmanCli ( db , xselpath , CLICallback , config ) <EOL> try : <EOL> cli . cmdloop ( ) <EOL> except KeyboardInterrupt as e : <EOL> print ( e ) <EOL> finally : <EOL> config . save ( ) </s>
