Procházet zdrojové kódy

Fix configuration options and add docs

oz123 před 10 roky
rodič
revize
075763d5a3

+ 35 - 0
docs/source/configuration.rst

@@ -0,0 +1,35 @@
+Configuring Pwman3:
+=================== 
+
+By default Pwman3 will read the configuration file from the following path::
+
+    ~/.pwman/config 
+
+This is the ``PWMAN_CONFIG`` following. 
+
+You can override this by giving the ``-c <Config File>`` at the commnad line 
+when starting Pwman3. 
+
+The configuration file has the following structure::
+
+    [Section]
+    Option = Value
+
+The following is an example default config file::
+    
+    [Readline]
+    history = <PWMAN_CONFIG>/history
+
+    [Global]
+    save = True
+    colors = yes
+    cp_timeout = 5
+    umask = 0100
+    cls_timeout = 10
+    xsel = /usr/bin/xsel
+
+    [Database]
+    type = SQLite
+    filename = <PWMAN_CONFIG>/pwman.db
+    
+

+ 6 - 5
docs/source/index.rst

@@ -13,12 +13,13 @@ Contents:
     
    install
    tutorial
+   configuration  
+
+About pwman3:
+^^^^^^^^^^^^^ 
+
+Pwman3 is a simple command line password manager for Python 2.7-3.X. 
 
 
-Indices and tables
-==================
 
-* :ref:`genindex`
-* :ref:`modindex`
-* :ref:`search`
 

+ 2 - 13
pwman/__init__.py

@@ -24,7 +24,7 @@ import argparse
 import sys
 import re
 import colorama
-from pwman.util import config
+from .util import config
 from pwman.data import factory
 from pwman.data.database import __DB_FORMAT__
 
@@ -68,17 +68,6 @@ def which(cmd):  # pragma: no cover
 
 config_dir = os.path.expanduser("~/.pwman")
 
-default_config = {'Global': {'umask': '0100', 'colors': 'yes',
-                             'cls_timeout': '5',
-                             'save': 'True'
-                             },
-                  'Database': {'type': 'SQLite',
-                               'filename': os.path.join(config_dir,
-                                                        "pwman.db")},
-                  'Readline': {'history': os.path.join(config_dir,
-                                                       "history")}
-                  }
-
 
 def parser_options(formatter_class=argparse.HelpFormatter):  # pragma: no cover
     parser = argparse.ArgumentParser(prog=appname,
@@ -99,7 +88,7 @@ def get_conf(args):
     if not os.path.isdir(config_dir):  # pragma: no cover
         os.mkdir(config_dir)
 
-    configp = config.Config(args.cfile, default_config)
+    configp = config.Config(args.cfile, config.default_config)
     return configp
 
 

+ 9 - 7
pwman/tests/test_config.py

@@ -20,8 +20,8 @@
 import os
 import sys
 import unittest
-from pwman.util.config import (Config, ConfigException, default_config,
-                               get_pass_conf)
+from pwman.util import config
+
 
 if sys.version_info.major > 2:
     from configparser import NoSectionError
@@ -62,7 +62,8 @@ class TestConfig(unittest.TestCase):
                 continue
 
     def setUp(self):
-        self.conf = Config(filename='testfile.conf', defaults=default_config)
+        self.conf = config.Config(filename='testfile.conf',
+                                  defaults=config.default_config)
 
     def test_has_defaults(self):
         self.assertTrue(self.conf.parser.has_section('Readline'))
@@ -76,8 +77,8 @@ class TestConfig(unittest.TestCase):
                          self.conf.get_value('Readline', 'history'))
 
     def test_has_user_db(self):
-        self.assertEqual(os.path.expanduser('~/.pwman/pwman.db'),
-                         self.conf.get_value('Database', 'filename'))
+        self.assertNotEqual(os.path.expanduser('~/.pwman/pwman.db'),
+                            self.conf.get_value('Database', 'filename'))
 
     def test_wrong_config(self):
         with open('wrong_conf.conf', 'w') as f:
@@ -85,7 +86,8 @@ class TestConfig(unittest.TestCase):
 [Encryption
 algorithm = Blowfish
 """)
-        self.assertRaises(ConfigException, Config, 'wrong_conf.conf')
+        self.assertRaises(config.ConfigException, config.Config,
+                          'wrong_conf.conf')
 
     def test_set_value(self):
         self.conf.set_value('Global', 'colors', 'no')
@@ -96,7 +98,7 @@ algorithm = Blowfish
                           self.conf.set_value, *('Error', 'colors', 'no'))
 
     def test_get_pass_conf(self):
-        ans = get_pass_conf(self.conf)
+        ans = config.get_pass_conf(self.conf)
         self.assertFalse(any(ans))
 
 if __name__ == '__main__':

+ 7 - 7
pwman/tests/test_tools.py

@@ -1,6 +1,6 @@
 from pwman.data import factory
 from pwman.util import config
-from pwman import which, default_config
+from pwman import which
 from pwman.ui import get_ui_platform
 import os
 import os.path
@@ -47,11 +47,11 @@ class DummyCallback4(Callback):
         return u'newsecret'
 
 
-default_config['Database'] = {'type': 'SQLite',
-                              'filename':
-                              os.path.join(os.path.dirname(__file__),
-                                           "test.pwman.db")
-                              }
+config.default_config['Database'] = {'type': 'SQLite',
+                                     'filename':
+                                     os.path.join(os.path.dirname(__file__),
+                                                  "test.pwman.db")
+                                     }
 
 dc = """
 [Global]
@@ -74,7 +74,7 @@ class SetupTester(object):
         f.close()
         self.configp = config.Config(os.path.join(os.path.dirname(__file__),
                                                   "test.conf"),
-                                     default_config)
+                                     config.default_config)
         self.configp.set_value('Database', 'filename',
                                os.path.join(os.path.dirname(__file__),
                                             "test.pwman.db"))

+ 1 - 1
pwman/util/config.py

@@ -31,7 +31,7 @@ else:                           # pragma: no cover
 config_dir = os.path.expanduser("~/.pwman")
 
 default_config = {'Global': {'umask': '0100', 'colors': 'yes',
-                             'cls_timeout': '5', 'cp_timeout': '5',
+                             'cls_timeout': '10', 'cp_timeout': '5',
                              'save': 'True'
                              },
                   'Database': {'type': 'SQLite',