Browse Source

More code clean-up ...

Remove more code related to converted, none-support encryption
algorithm and more ...
oz123 10 năm trước cách đây
mục cha
commit
1f5f1bfa86
4 tập tin đã thay đổi với 7 bổ sung76 xóa
  1. 0 15
      pwman/__init__.py
  2. 6 3
      pwman/util/config.py
  3. 1 6
      pwman/util/crypto_engine.py
  4. 0 52
      scripts/pwman3

+ 0 - 15
pwman/__init__.py

@@ -74,7 +74,6 @@ default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                   'Database': {'type': 'SQLite',
                                'filename': os.path.join(config_dir,
                                                         "pwman.db")},
-                  'Encryption': {'algorithm': 'AES'},
                   'Readline': {'history': os.path.join(config_dir,
                                                        "history")}
                   }
@@ -88,18 +87,6 @@ def parser_options(formatter_class=argparse.HelpFormatter):
                         default=os.path.expanduser("~/.pwman/config"),
                         help='cofiguration file to read')
     parser.add_argument('-d', '--database', dest='dbase')
-    parser.add_argument('-k', '--convert', dest='dbconvert',
-                        action='store_true', default=False,
-                        # os.path.expanduser('~/.pwman/pwman.db'),
-                        help=("Convert old DB format to version >= 0.4."
-                              " The database that will be converted is the"
-                              " one found in the config file, or the one given"
-                              " as command line argument."))
-    parser.add_argument('-O', '--output', dest='output',
-                        # default=os.path.expanduser(
-                        #'~/.pwman/pwman-newdb.db'),
-                        help=("The name of the newly created database after "
-                              "converting."))
     return parser
 
 
@@ -164,8 +151,6 @@ def get_conf_options(args, OSX):
 def get_db_version(config, dbtype, args):
     if os.path.exists(config.get_value("Database", "filename")):
         dbver = factory.check_db_version(dbtype)
-        if dbver < 0.4 and not args.dbconvert:
-            print(_db_warn)
     else:
         dbver = __DB_FORMAT__
     return dbver

+ 6 - 3
pwman/util/config.py

@@ -22,9 +22,9 @@ import sys
 import os
 
 if sys.version_info.major > 2:
-    from configparser import ConfigParser, ParsingError
+    from configparser import ConfigParser, ParsingError, NoOptionError
 else:
-    from ConfigParser import ConfigParser, ParsingError
+    from ConfigParser import ConfigParser, ParsingError, NoOptionError
 import copy
 
 config_dir = os.path.expanduser("~/.pwman")
@@ -92,7 +92,10 @@ class Config(object):
                     parser.set(section, key, value)
 
     def get_value(self, section, name):
-        return self.parser.get(section, name)
+        try:
+            return self.parser.get(section, name)
+        except NoOptionError:
+            return ''
 
     def set_value(self, section, name, value):
         self.parser.set(section, name, value)

+ 1 - 6
pwman/util/crypto_engine.py

@@ -93,17 +93,12 @@ class CryptoEngine(object):  # pagma: no cover
         if CryptoEngine._instance_new:
             return CryptoEngine._instance_new
 
-        algo = config.get_value("Encryption", "algorithm")
-
-        if not algo:
-            raise Exception("Parameters missing, no algorithm given")
-
         try:
             timeout = int(config.get_value("Encryption", "timeout"))
         except ValueError:
             timeout = -1
 
-        kwargs = {'algorithm': algo,
+        kwargs = {'algorithm': 'AES',
                   'timeout': timeout}
 
         if dbver >= 0.5:

+ 0 - 52
scripts/pwman3

@@ -21,76 +21,24 @@
 #============================================================================
 from __future__ import print_function
 import sys
-import shutil
 from pwman import get_conf_options, get_db_version
 from pwman import parser_options
 from pwman.ui import get_ui_platform
 from pwman.ui.tools import CLICallback
 import pwman.util.config as config
 import pwman.data.factory
-from pwman.data.convertdb import PwmanConvertDB
 from pwman.util.crypto_engine import CryptoEngine
 
 if sys.version_info.major > 2:
     raw_input = input
 
 
-def auto_convert():
-    try:
-        #1) Display a message saying that the database will be converted
-        # This step is done already in get_db_version
-        dbconvertor = PwmanConvertDB(args, config)
-
-        #2) copy the old database :
-        # cp ~/.pwman3/pwman.db  ~/.pwman3/pwman.backup-2013-11-23-23:15.db
-        #3) Display a message about the backup file path
-        # These steps are done by PwmanConvertDB.backup_old_db()
-        dbconvertor.backup_old_db()
-
-        #4) convert the old database to the new format in ~/.pwman3/pwman.db
-        # This step is done by PwmanConvertDB.create_new_db()
-        #                      PwmanConvertDB.convert_nodes()
-        #                      PwmanConvertDB.save_new_nodes_to_db()
-        #                      PwmanConvertDB.save_old_key()
-        dbconvertor.read_old_db()
-        dbconvertor.create_new_db()
-        dbconvertor.convert_nodes()
-        dbconvertor.save_new_nodes_to_db()
-        dbconvertor.save_old_key()
-        #5) Display a message about the result of the conversion
-        # add message here ...
-        #5b) close connection
-        dbconvertor.db.close()
-        print("Your datbase %s was successfully converted " %
-              dbconvertor.dbname)
-        #5c) rename the newly created db to the old name!
-        shutil.move(dbconvertor.newdb_name, dbconvertor.dbname)
-        #6) Start the pwman3 normally if all went ok
-        return True
-    except Exception as e:
-        raise e
-
-
 def main(args):
     PwmanCliNew, OSX = get_ui_platform(sys.platform)
     xselpath, dbtype = get_conf_options(args, OSX)
     dbver = get_db_version(config, dbtype, args)
     CryptoEngine.get(dbver)
 
-    if args.dbconvert:
-        dbconvertor = PwmanConvertDB(args, config)
-        dbconvertor.run()
-        sys.exit(0)
-
-    if dbver < 0.4:
-        ans = raw_input("Would you like to proceed with the conversion of the "
-                        "database before starting pwman3 [y/N]?")
-        if ans.lower() != "y":
-            sys.exit(1)
-
-        auto_convert()
-        dbver = 0.4
-
     db = pwman.data.factory.create(dbtype, dbver)
     cli = PwmanCliNew(db, xselpath, CLICallback)