|
@@ -0,0 +1,135 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import os
|
|
|
+import os.path
|
|
|
+
|
|
|
+import sys
|
|
|
+sys.path.insert(0, os.getcwd())
|
|
|
+_saveconfig = True
|
|
|
+
|
|
|
+import sys
|
|
|
+from pwman.util.crypto import CryptoEngine
|
|
|
+
|
|
|
+if 'darwin' in sys.platform:
|
|
|
+ from pwman.ui.mac import PwmanCliMac as PwmanCli
|
|
|
+ from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
|
|
|
+ OSX = True
|
|
|
+elif 'win' in sys.platform:
|
|
|
+ from pwman.ui.cli import PwmanCli
|
|
|
+ from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
|
|
|
+ OSX = False
|
|
|
+else:
|
|
|
+ from pwman.ui.cli import PwmanCli
|
|
|
+ from pwman.ui.cli import PwmanCliNew
|
|
|
+ OSX = False
|
|
|
+
|
|
|
+
|
|
|
+import pwman.util.config as config
|
|
|
+import pwman.data.factory
|
|
|
+from pwman.data.convertdb import PwmanConvertDB
|
|
|
+
|
|
|
+
|
|
|
+def which(cmd):
|
|
|
+ _, cmdname = os.path.split(cmd)
|
|
|
+
|
|
|
+ for path in os.environ["PATH"].split(os.pathsep):
|
|
|
+ cmd = os.path.join(path, cmdname)
|
|
|
+ if os.path.isfile(cmd) and os.access(cmd, os.X_OK):
|
|
|
+ return cmd
|
|
|
+
|
|
|
+ return None
|
|
|
+
|
|
|
+try:
|
|
|
+ config_dir = os.path.expanduser("~/.pwman")
|
|
|
+ if not os.path.isdir(config_dir):
|
|
|
+ os.mkdir(config_dir)
|
|
|
+
|
|
|
+ config_file = os.path.join(config_dir, "config")
|
|
|
+
|
|
|
+ default_config = {'Global': {'umask': '0100', 'colors': 'yes',
|
|
|
+ 'cls_timeout': '5'
|
|
|
+ },
|
|
|
+ 'Database': {'type': 'SQLite',
|
|
|
+ 'filename': os.path.join(config_dir,
|
|
|
+ "pwman.db")},
|
|
|
+ 'Encryption': {'algorithm': 'AES'},
|
|
|
+ 'Readline': {'history': os.path.join(config_dir,
|
|
|
+ "history")}
|
|
|
+ }
|
|
|
+
|
|
|
+ config.set_defaults(default_config)
|
|
|
+ if 'win' in sys.platform:
|
|
|
+ try:
|
|
|
+ import colorama
|
|
|
+ colorama.init()
|
|
|
+ except ImportError:
|
|
|
+ config.set_value("Global", "colors", 'no')
|
|
|
+ if os.path.exists(config_file):
|
|
|
+ config.load(config_file)
|
|
|
+ xselpath = config.get_value("Global", "xselpath")
|
|
|
+ elif not OSX:
|
|
|
+ xselpath = which("xsel")
|
|
|
+ config.set_value("Global", "xsel", xselpath)
|
|
|
+ elif OSX:
|
|
|
+ pbcopypath = which("pbcopy")
|
|
|
+ config.set_value("Global", "xsel", pbcopypath)
|
|
|
+
|
|
|
+ umask = int(config.get_value("Global", "umask"))
|
|
|
+ os.umask(umask)
|
|
|
+
|
|
|
+ enc = CryptoEngine.get()
|
|
|
+
|
|
|
+ dbtype = config.get_value("Database", "type")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if os.path.exists(config.get_value("Database", "filename")):
|
|
|
+ dbver = pwman.data.factory.check_db_version(dbtype)
|
|
|
+ dbver = float(dbver.strip("\'"))
|
|
|
+ else:
|
|
|
+ dbver = 0.4
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ db = pwman.data.factory.create(dbtype, dbver)
|
|
|
+ if dbver >= 0.4:
|
|
|
+ cli = PwmanCliNew(db, xselpath)
|
|
|
+ elif dbver < 0.4:
|
|
|
+ cli = PwmanCli(db, xselpath)
|
|
|
+except SystemExit, e:
|
|
|
+ sys.exit(e)
|
|
|
+import logging
|
|
|
+import unittest
|
|
|
+from db_tests import CLITests
|
|
|
+from db_tests import DBTests
|
|
|
+if __name__ == '__main__':
|
|
|
+ unittest.main()
|