[python3] fixes (s/iteritems/items) and chmod
authorArthur Lutz <arthur.lutz@logilab.fr>
Tue, 12 Nov 2019 17:57:17 +0100
changeset 133 80b24cc45c50
parent 132 d1d9f951bebc
child 134 327f13314b72
[python3] fixes (s/iteritems/items) and chmod
_modules/cubicweb.py
--- a/_modules/cubicweb.py	Fri Oct 11 10:45:34 2019 +0200
+++ b/_modules/cubicweb.py	Tue Nov 12 17:57:17 2019 +0100
@@ -6,6 +6,7 @@
 
 # Import python libs
 import sys
+import stat
 import pipes
 import logging
 import re
@@ -18,7 +19,7 @@
 
 # Import salt libs
 from salt.utils import check_or_die
-try: 
+try:
     from salt.utils.url import strip_proto
 except ImportError:
     # legacy  < 2015.8
@@ -51,7 +52,7 @@
 
 def start(name, pyramid=False):
     '''
-    Start a Cubicweb instance 
+    Start a Cubicweb instance
 
     name:
        name of the instance to start
@@ -68,7 +69,7 @@
     else:
         start_cmd = __salt__['cmd.run']('cubicweb-ctl start {0}'.format(name))
     log.debug('start {0}: {1!r}'.format(name, start_cmd))
-    # TODO use force-restart when implemented 
+    # TODO use force-restart when implemented
     if '--force' in start_cmd:
         with file('/var/run/cubicweb/{0}-all-in-one.pid'.format(name), 'r') as f:
             if __salt__['status.pid'](f.read()):
@@ -172,7 +173,7 @@
     stdout = __salt__['cmd.run_stdout']('/bin/grep --with-filename ^db\-host /etc/cubicweb.d/*/sources', use_vt=True)
     sources_dict = {}
     for line in stdout.splitlines():
-        print line
+        print(line)
         filename, conf = line.split(':')
         _, _, _, instance, _ = filename.split('/')
         _, db_host = conf.split('=')
@@ -224,14 +225,14 @@
         name of the cubicweb instance
     cubes
         cubes to be installed in this instance
-    install_type    
+    install_type
         installation type (optional, default: all-in-one)
     kwargs
         used to configure instance (see cubicweb.configure)
 
     CLI Example::
 
-        salt '*' cubicweb.create blog blog 
+        salt '*' cubicweb.create blog blog
         salt '*' cubicweb.create blog blog all-in-one
     '''
     log.debug('create {0} ({1}): {2!r}'.format(name,install_type, cubes))
@@ -254,11 +255,11 @@
     name
         name of the cubicweb instance
     kwargs
-        used to configure instance 
+        used to configure instance
 
     CLI Example::
 
-        salt '*' cubicweb.configure blog key1=value1 
+        salt '*' cubicweb.configure blog key1=value1
         salt '*' cubicweb.configure blog smtp-host=localhost
     '''
     cmd = 'cubicweb-ctl configure '
@@ -299,7 +300,7 @@
 def initialize(name, drop=False):
     '''Initialize the database for an instance
 
-    name: 
+    name:
         name of the instance
     drop:
         if True, drop the database first (default: False)
@@ -341,8 +342,8 @@
         if dumpfileurl.startswith('http') or dumpfileurl.startswith('salt'):
             out = __salt__['cp.get_url'](dumpfileurl, dst)
         else:
-            # TODO sanitize/check variables 
-            # TODO there must be a better way, cp.get_file with file:// ? 
+            # TODO sanitize/check variables
+            # TODO there must be a better way, cp.get_file with file:// ?
             out = __salt__['cmd.run']('mkdir {0}'.format(tmpdir))
             out = __salt__['cmd.run']('cp {0} {1}'.format(dumpfileurl, dst))
 
@@ -362,7 +363,9 @@
             pgpassfile.write('*:*:{0}:{1}:{2}\n'.format(src['db-name'],
                                                         src['db-user'],
                                                         src['db-password']))
-        os.chmod(pgpass, 0600)
+        os.chmod(pgpass,
+                 stat.S_IRUSR |
+                 stat.S_IWUSR)
         env = {'PGPASSFILE': pgpass}
         cmd = _pgdbcmd('pg_restore',
                        src.get('db-host'),