Эх сурвалжийг харах

Configuration improvements

oz123 10 жил өмнө
parent
commit
f7847cd5e0

+ 10 - 9
pwman/tests/test_config.py

@@ -20,19 +20,16 @@
 import os
 import sys
 import unittest
-from pwman.util.config import Config, ConfigException, default_config
+from pwman.util.config import (Config, ConfigException, default_config,
+                               get_pass_conf)
+
 if sys.version_info.major > 2:
     from configparser import NoSectionError
 else:
     from ConfigParser import NoSectionError
 
-# TODO: Drop support for none AES Encryption,
-# So the whole section [Encryption] can be dropped.
 with open('testfile.conf', 'w') as f:
     f.write("""
-[Encryption]
-algorithm = Blowfish
-
 [Global]
 xsel = /usr/bin/xsel
 colors = yes
@@ -70,9 +67,9 @@ class TestConfig(unittest.TestCase):
     def test_has_defaults(self):
         self.assertTrue(self.conf.parser.has_section('Readline'))
 
-    def test_has_blowfish(self):
-        self.assertEqual('Blowfish', self.conf.get_value('Encryption',
-                                                         'algorithm'))
+    #def test_has_blowfish(self):
+    #    self.assertEqual('Blowfish', self.conf.get_value('Encryption',
+    #                                                     'algorithm'))
 
     def test_has_user_history(self):
         self.assertEqual(os.path.expanduser('~/.pwman/history'),
@@ -98,5 +95,9 @@ algorithm = Blowfish
         self.assertRaises(NoSectionError,
                           self.conf.set_value, *('Error', 'colors', 'no'))
 
+    def test_get_pass_conf(self):
+        ans = get_pass_conf(self.conf)
+        self.assertFalse(any(ans))
+
 if __name__ == '__main__':
     unittest.main(verbosity=2)

+ 12 - 8
pwman/util/config.py

@@ -37,7 +37,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")}
                   }
@@ -60,12 +59,11 @@ class ConfigNoConfigException(ConfigException):
 class Config(object):
 
     def __init__(self, filename=None, defaults=None, **kwargs):
-
         self.filename = filename
         self.parser = self._load(defaults)
 
     def _load(self, defaults):
-        parser = ConfigParser(defaults)
+        parser = ConfigParser()
         try:
             with open(self.filename) as f:
                 try:
@@ -79,7 +77,6 @@ class Config(object):
             self.save(os.path.join(config_dir, 'config'), parser)
 
         self._add_defaults(defaults, parser)
-
         return parser
 
     def _add_defaults(self, defaults, parser):
@@ -101,6 +98,7 @@ class Config(object):
         self.parser.set(section, name, value)
 
     def save(self, filename, parser=None):  # pragma: no cover
+
         with open(filename, "w") as fp:
             if parser:
                 parser.write(fp)
@@ -109,9 +107,15 @@ class Config(object):
 
 
 def get_pass_conf(config):  # pragma: no cover
-    numerics = config.get_value("Generator", "numerics").lower() == 'true'
-    # TODO: allow custom leetifying through the config
-    leetify = config.get_value("Generator", "leetify").lower() == 'true'
     special_chars = config.get_value("Generator",
                                      "special_chars").lower() == 'true'
-    return numerics, leetify, special_chars
+    ascii_lowercase = config.get_value("Generator",
+                                       "ascii_lowercase").lower() == 'true'
+    ascii_uppercase = config.get_value("Generator",
+                                       "ascii_uppercase").lower() == 'true'
+    ascii_digits = config.get_value("Generator",
+                                    "ascii_digits").lower() == 'true'
+    ascii_punctuation = config.get_value("Generator",
+                                         "ascii_punctuation").lower() == 'true'
+    return special_chars, ascii_lowercase, ascii_uppercase, ascii_digits, \
+        ascii_punctuation

+ 2 - 1
scripts/pwman3

@@ -53,7 +53,8 @@ def main(args):
         cli.cmdloop()
     except KeyboardInterrupt as e:
         print(e)
-
+    finally:
+        config.save(args.cfile)
 
 if __name__ == '__main__':
     args = parser_options().parse_args()