Pārlūkot izejas kodu

Merge branch 'develop'

Oz N Tiram 6 gadi atpakaļ
vecāks
revīzija
b6cd4364f1

+ 2 - 1
Vagrantfile

@@ -10,7 +10,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   # please see the online documentation at vagrantup.com.
 
   # Every Vagrant virtual environment requires a box to build off of.
-  config.vm.box = "ubuntu/xenial64"
+  config.vm.box = "generic/ubuntu1604"
+  config.vm.box_version = "1.5.0"
   config.vm.hostname = "pwman-dev"
   config.vm.provision :shell, path: "provision_vagrant.sh"
 

+ 7 - 5
docs/source/configuration.rst

@@ -1,11 +1,11 @@
 Configuring Pwman3
 ==================
 
-By default Pwman3 will read the configuration file from the following path::
+By default Pwman3 will read the configuration file from the following path on Unix like systems::
 
-    ~/.pwman/config
+    ~/.config/pwman/config
 
-This is the ``PWMAN_CONFIG`` following.
+On windows the configuration is found in ``%APPDATA/pwman/%``
 
 You can override this by giving the ``-c <Config File>`` at the commnad line
 when starting Pwman3.
@@ -18,7 +18,7 @@ The configuration file has the following structure::
 The following is an example default config file::
 
     [Readline]
-    history = <PWMAN_CONFIG>/history
+    history = <PWMAN_DATA_DIR>/history
 
     [Global]
     save = True
@@ -30,12 +30,14 @@ The following is an example default config file::
     lock_timeout = 60
 
     [Database]
-    filename = sqlite:///<PWMAN_CONFIG>/pwman.db`
+    filename = sqlite:///<PWMAN_DATA_DIR>/pwman.db`
 
     [Updater]
     supress_version_check = no
     client_info = ee5cd64310568736b971e3fb7c7064a4459b99a2b78672515fd0f06c82f65d5
 
+On Windows ``PWMAN_DATA_DIR`` is ``%APPDATA/pwman/%`` on Unix like systems it is
+``~/.local/share/pwman/``.
 
 Following is a table describing the parameters and their meanings:
 

+ 17 - 18
provision_vagrant.sh

@@ -1,6 +1,16 @@
 #!/usr/bin/env bash
-sudo locale-gen "en_US.UTF-8"
-sudo dpkg-reconfigure --frontend=noninteractiv locales
+
+apt-get install -y debconf-utils
+export TERM=linux
+export DEBIAN_FRONTEND=noninteractive
+echo 'debconf debconf/frontend select noninteractive' | debconf-set-selections
+
+locale-gen "en_US.UTF-8"
+
+dpkg-reconfigure --frontend=noninteractiv locales
+
+debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password toor'
+debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password toor'
 
 echo "LC_ALL=en_US.UTF-8" >> /etc/environment
 echo "LANG=en_US.UTF-8" >> /etc/environment
@@ -13,22 +23,14 @@ postgresql python3-psycopg2 build-essential \
 mysql-server-5.7
 "
 
-set -x
-
 apt-get update
 apt-get install -y ${PACKAGES}
 
-if [ ! -f  /usr/local/bin/pip ]; then
-    wget https://bootstrap.pypa.io/get-pip.py
-	sudo python get-pip.py
-fi
-
 if [ ! -f  /usr/local/bin/pip3 ]; then
-	sudo python3 get-pip.py
+    wget https://bootstrap.pypa.io/get-pip.py
+    sudo python3 get-pip.py
 fi
 
-sudo mysqladmin -u root password toor
-
 PYTHON_PACKAGES="psycopg2 pymysql pymongo pexpect coverage pew"
 
 sudo pip3 install ${PYTHON_PACKAGES}
@@ -38,9 +40,9 @@ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
 
 echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
 
-sudo apt-get update
-sudo apt-get install -y mongodb-org
-sudo systemctl start mongod
+apt-get update
+apt-get install -y mongodb-org
+systemctl start mongod
 
 cd /home/vagrant
 if [ ! -d pwman3 ]; then
@@ -60,6 +62,3 @@ sudo -u postgres psql -c 'grant ALL ON DATABASE pwman to tester' -U postgres
 
 # setup mongodb
 mongo < /home/vagrant/pwman3/tests/init_mongo.js
-#mongo pwmantest --eval 'db.addUser("tester", "12345678");'
-
-

+ 4 - 5
pwman/__init__.py

@@ -76,7 +76,7 @@ def parser_options(formatter_class=argparse.HelpFormatter):  # pragma: no cover
                                      formatter_class=formatter_class)
     parser.add_argument('-c', '--config', dest='cfile',
                         default=os.path.join(
-                                             config.find_config_dir('pwman'),
+                                             config.find_config_dir('pwman')[0],
                                              'config'),
                         help='cofiguration file to read')
     parser.add_argument('-d', '--database', dest='dbase')
@@ -93,10 +93,9 @@ def parser_options(formatter_class=argparse.HelpFormatter):  # pragma: no cover
 
 
 def get_conf(args):
-    config_dir = config.find_config_dir('pwman')
-
-    if not os.path.isdir(config_dir):  # pragma: no cover
-        os.makedirs(config_dir, exist_ok=True)
+    for dir in config.find_config_dir('pwman'):
+        if not os.path.isdir(dir):  # pragma: no cover
+            os.makedirs(dir, exist_ok=True)
 
     configp = config.Config(args.cfile, config.default_config)
     return configp

+ 1 - 4
pwman/data/factory.py

@@ -18,10 +18,7 @@
 # ============================================================================
 
 import sys
-if sys.version_info.major > 2:  # pragma: no cover
-    from urllib.parse import urlparse
-else:
-    from urlparse import urlparse
+from urllib.parse import urlparse
 
 import os
 

+ 6 - 13
pwman/ui/baseui.py

@@ -34,10 +34,6 @@ from pwman.ui.tools import CliMenuItem
 from pwman.ui.tools import CMDLoop, get_or_create_pass
 
 
-if sys.version_info.major > 2:  # pragma: no cover
-    raw_input = input
-
-
 def _heard_enter():  # pragma: no cover
     i, o, e = uselect.select([sys.stdin], [], [], 0.0001)
     for s in i:
@@ -208,7 +204,7 @@ class BaseUtilsMixin:
 
         return ids
 
-    def _get_tags(self, default=None, reader=raw_input):
+    def _get_tags(self, default=None, reader=input):
         """
         Read tags from user input.
         Tags are simply returned as a list
@@ -354,17 +350,14 @@ class BaseCommands(HelpUIMixin, AliasesMixin, BaseUtilsMixin):
 
         nodes = self._db.getnodes(ids)
         ce = CryptoEngine.get()
-
         for node in nodes:
-            url = ce.decrypt(node[3])
+            url = ce.decrypt(node[3]).decode()
             if not url.startswith(("http://", "https://")):
                 url = "https://" + url
-            os.umask(22)
-            tools.open_url(url)
-
-            umask = self.config.get_value("Global", "umask")
-            if re.search(r'^\d{4}$', umask):
-                os.umask(int(umask))
+            if url:
+                mask = os.umask(22)
+                tools.open_url(url)
+                os.umask(mask)
 
     def do_cls(self, args):  # pragma: no cover
         """clear the screen"""

+ 8 - 6
pwman/util/config.py

@@ -76,14 +76,16 @@ def find_config_dir(appname):
     config_dir = os.path.expanduser("~/.%s" % appname)
 
     if os.path.exists(config_dir):
-        return config_dir
+        return config_dir, config_dir
     elif platform.system() == 'Windows':
-        return os.path.expandvars(os.path.join('$APPDATA', appname))
+        app_data = os.path.expandvars(os.path.join('$APPDATA', appname))
+        return app_data, app_data
     else:
-        return os.path.join(XDG_CONFIG_HOME, appname)
+        return (os.path.join(XDG_CONFIG_HOME, appname),
+                os.path.join(XDG_DATA_HOME, appname))
 
 
-config_dir = find_config_dir('pwman')
+config_dir, data_dir = find_config_dir('pwman')
 
 
 default_config = {'Global': {'umask': '0100', 'colors': 'yes',
@@ -92,9 +94,9 @@ default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                              'lock_timeout': '600'
                              },
                   'Database': {
-                      'dburi': 'sqlite://' + os.path.join(config_dir,
+                      'dburi': 'sqlite://' + os.path.join(data_dir,
                                                           'pwman.db')},
-                  'Readline': {'history': os.path.join(config_dir,
+                  'Readline': {'history': os.path.join(data_dir,
                                                        'history')},
                   'Crypto': {'supress_warning': 'no'},
 

+ 6 - 6
tests/test_config.py

@@ -46,7 +46,7 @@ class TestFindConfigWindows(unittest.TestCase):
         with unittest.mock.patch('platform.system') as pl:
             pl.return_value = 'Windows'
             os.environ['APPDATA'] = 'balls'
-            cdir = config.find_config_dir('zzzz')
+            cdir, data_dir = config.find_config_dir('zzzz')
 
             self.assertEqual(
                 os.path.expandvars(os.path.join('$APPDATA', 'zzzz')),
@@ -65,7 +65,7 @@ class TestFindConfigCompat(unittest.TestCase):
         os.rmdir(self.c_path)
 
     def test_compat(self):
-        cdir = config.find_config_dir('zzzz_compat_posix')
+        cdir, data_dir = config.find_config_dir('zzzz_compat_posix')
         self.assertEqual(self.c_path, cdir)
 
 
@@ -79,7 +79,7 @@ class TestFindConfigXDG(unittest.TestCase):
 
     def test_new_scheme(self):
         # assert we get xdg_fine with Linux
-        cdir = config.find_config_dir('zzzz_posix')
+        cdir, data_dir = config.find_config_dir('zzzz_posix')
         self.assertEqual(cdir, os.path.expanduser("~/.config/zzzz_posix"))
 
 
@@ -102,13 +102,13 @@ class TestConfig(unittest.TestCase):
         self.assertTrue(self.conf.parser.has_section('Readline'))
 
     def test_has_user_history(self):
-        cdir = find_config_dir('pwman')
-        path = os.path.join(cdir, "history")
+        ddir = find_config_dir('pwman')[1]
+        path = os.path.join(ddir, "history")
         config = self.conf.get_value('Readline', 'history')
         self.assertEqual(path, config)
 
     def test_has_user_db(self):
-        self.assertNotEqual(os.path.join(config.find_config_dir("pwman"),'pwman.db'),
+        self.assertNotEqual(os.path.join(config.find_config_dir("pwman")[1],'pwman.db'),
                             self.conf.get_value('Database', 'filename'))
 
     def test_wrong_config(self):