Skip to content
Snippets Groups Projects
Commit d4a964711550 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:pencil: use _logger instead of logging (no point in defining it otherwise)

parent 89126f315e06
No related branches found
No related tags found
No related merge requests found
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
c = configparser.ConfigParser() c = configparser.ConfigParser()
if not os.path.exists(setup_path): if not os.path.exists(setup_path):
logging.fatal('Missing %s', setup_path) _logger.fatal('Missing %s', setup_path)
return 12 return 12
c.read(setup_path) c.read(setup_path)
...@@ -192,9 +192,9 @@ ...@@ -192,9 +192,9 @@
c.has_option('odoo_scripts', 'postgresql_version') and c.has_option('odoo_scripts', 'postgresql_version') and
c.get('odoo_scripts', 'postgresql_version')) or '9.6' c.get('odoo_scripts', 'postgresql_version')) or '9.6'
image = "%s/%s:latest" % (registry, project) image = "%s/%s:latest" % (registry, project)
logging.debug("Docker image: %s", image) _logger.debug("Docker image: %s", image)
# read from odoo.conf if it exists # read from odoo.conf if it exists
sample_conf = 'conf/dev/odoo.conf' sample_conf = 'conf/dev/odoo.conf'
if os.path.exists(sample_conf): if os.path.exists(sample_conf):
...@@ -196,9 +196,9 @@ ...@@ -196,9 +196,9 @@
# read from odoo.conf if it exists # read from odoo.conf if it exists
sample_conf = 'conf/dev/odoo.conf' sample_conf = 'conf/dev/odoo.conf'
if os.path.exists(sample_conf): if os.path.exists(sample_conf):
logging.info('Reading from sample configuration %s', sample_conf) _logger.info('Reading from sample configuration %s', sample_conf)
c.read(sample_conf) c.read(sample_conf)
if not odoo_db_user: if not odoo_db_user:
if c.has_option('options', 'db_user'): if c.has_option('options', 'db_user'):
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
): ):
extensions.append('unaccent') extensions.append('unaccent')
else: else:
logging.debug('No sample configuration %s', sample_conf) _logger.debug('No sample configuration %s', sample_conf)
extensions.append('unaccent') extensions.append('unaccent')
# Do stuff # Do stuff
......
...@@ -60,6 +60,6 @@ ...@@ -60,6 +60,6 @@
"""Run flake8 if found """Run flake8 if found
""" """
if which('flake8'): if which('flake8'):
logging.info('Running flake8') _logger.info('Running flake8')
call(['flake8']) call(['flake8'])
else: else:
...@@ -64,6 +64,6 @@ ...@@ -64,6 +64,6 @@
call(['flake8']) call(['flake8'])
else: else:
logging.warning('No flake8 in PATH') _logger.warning('No flake8 in PATH')
def main(argv=None): # IGNORE:C0111 def main(argv=None): # IGNORE:C0111
...@@ -280,8 +280,8 @@ ...@@ -280,8 +280,8 @@
if restore_filename: if restore_filename:
if not database: if not database:
logging.fatal('No database name given for restore') _logger.fatal('No database name given for restore')
return 13 return 13
c = ConfigParser() c = ConfigParser()
if not os.path.exists(setup_path): if not os.path.exists(setup_path):
...@@ -284,8 +284,8 @@ ...@@ -284,8 +284,8 @@
return 13 return 13
c = ConfigParser() c = ConfigParser()
if not os.path.exists(setup_path): if not os.path.exists(setup_path):
logging.fatal('Missing %s', setup_path) _logger.fatal('Missing %s', setup_path)
return 12 return 12
c.read(setup_path) c.read(setup_path)
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
if c.has_option('odoo_scripts', 'modules'): if c.has_option('odoo_scripts', 'modules'):
for entry in c.get('odoo_scripts', 'modules').split(): for entry in c.get('odoo_scripts', 'modules').split():
modules.extend(glob.glob(entry)) modules.extend(glob.glob(entry))
logging.debug("addon modules: %s", modules) _logger.debug("addon modules: %s", modules)
registry = ( registry = (
c.has_section('odoo_scripts') and c.has_section('odoo_scripts') and
...@@ -312,8 +312,8 @@ ...@@ -312,8 +312,8 @@
c.has_section('odoo_scripts') and c.has_section('odoo_scripts') and
c.has_option('odoo_scripts', 'postgresql_version') and c.has_option('odoo_scripts', 'postgresql_version') and
c.get('odoo_scripts', 'postgresql_version')) or '9.6' c.get('odoo_scripts', 'postgresql_version')) or '9.6'
logging.debug("Docker image: %s", image) _logger.debug("Docker image: %s", image)
# detect if docker image already exists # detect if docker image already exists
docker_client = docker_api(base_url='unix://var/run/docker.sock') docker_client = docker_api(base_url='unix://var/run/docker.sock')
image_list = docker_client.images(name=image, quiet=True) image_list = docker_client.images(name=image, quiet=True)
if not image_list: if not image_list:
...@@ -316,6 +316,6 @@ ...@@ -316,6 +316,6 @@
# detect if docker image already exists # detect if docker image already exists
docker_client = docker_api(base_url='unix://var/run/docker.sock') docker_client = docker_api(base_url='unix://var/run/docker.sock')
image_list = docker_client.images(name=image, quiet=True) image_list = docker_client.images(name=image, quiet=True)
if not image_list: if not image_list:
logging.info("Image %s does not exist", image) _logger.info("Image %s does not exist", image)
else: else:
...@@ -321,3 +321,3 @@ ...@@ -321,3 +321,3 @@
else: else:
logging.info("Image %s exists", image) _logger.info("Image %s exists", image)
if (not image_list and not nmspc.no_build) or nmspc.force_build: if (not image_list and not nmspc.no_build) or nmspc.force_build:
...@@ -323,5 +323,5 @@ ...@@ -323,5 +323,5 @@
if (not image_list and not nmspc.no_build) or nmspc.force_build: if (not image_list and not nmspc.no_build) or nmspc.force_build:
logging.info("Building image %s", image) _logger.info("Building image %s", image)
import docker_build import docker_build
arguments = [ arguments = [
'--dev' '--dev'
...@@ -416,7 +416,7 @@ ...@@ -416,7 +416,7 @@
if addresses: if addresses:
local_ip = addresses[0] local_ip = addresses[0]
except ImportError: except ImportError:
logging.warn("Consider installing python netifaces" _logger.warn("Consider installing python netifaces"
" to ease local IP detection") " to ease local IP detection")
if not local_ip: if not local_ip:
import socket import socket
...@@ -420,7 +420,7 @@ ...@@ -420,7 +420,7 @@
" to ease local IP detection") " to ease local IP detection")
if not local_ip: if not local_ip:
import socket import socket
logging.info('Contacting Google Public DNS to find our IP') _logger.info('Contacting Google Public DNS to find our IP')
local_ip = [ local_ip = [
( (
s.connect(('8.8.8.8', 53)), s.connect(('8.8.8.8', 53)),
...@@ -430,7 +430,7 @@ ...@@ -430,7 +430,7 @@
socket.socket(socket.AF_INET, socket.SOCK_DGRAM)] socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]
][0][1] ][0][1]
logging.debug('IP found %s', local_ip) _logger.debug('IP found %s', local_ip)
arg.append('--db_host') arg.append('--db_host')
arg.append(local_ip) arg.append(local_ip)
...@@ -445,7 +445,7 @@ ...@@ -445,7 +445,7 @@
user = db_user user = db_user
password = db_password password = db_password
if os.path.isfile(local_conf_path): if os.path.isfile(local_conf_path):
logging.info('Local configuration file found: %s' % local_conf_path) _logger.info('Local configuration file found: %s' % local_conf_path)
binds.append('%s:/opt/odoo/etc' % os.path.join( binds.append('%s:/opt/odoo/etc' % os.path.join(
project_path, local_conf_dir)) project_path, local_conf_dir))
cp_local = ConfigParser() cp_local = ConfigParser()
...@@ -466,7 +466,7 @@ ...@@ -466,7 +466,7 @@
# data volume handling # data volume handling
if odoo_type != 'odoo7': if odoo_type != 'odoo7':
data_volume_name = '{}_data'.format(project_name) data_volume_name = '{}_data'.format(project_name)
logging.debug('Using data volume %s', data_volume_name) _logger.debug('Using data volume %s', data_volume_name)
createVolume(docker_client, data_volume_name) createVolume(docker_client, data_volume_name)
# make sure the permission in the volume are correct # make sure the permission in the volume are correct
mount_opts = '{}:/mnt/data'.format(data_volume_name) mount_opts = '{}:/mnt/data'.format(data_volume_name)
...@@ -479,7 +479,7 @@ ...@@ -479,7 +479,7 @@
binds.append('{}:/mnt/data'.format(data_volume_name)) binds.append('{}:/mnt/data'.format(data_volume_name))
arg.append('--data-dir /mnt/data') arg.append('--data-dir /mnt/data')
else: else:
logging.debug('No data volume for this odoo version') _logger.debug('No data volume for this odoo version')
# avoid the duplication of unbind volumes with all addons # avoid the duplication of unbind volumes with all addons
# additionnal_addons only in odoo < 10 # additionnal_addons only in odoo < 10
...@@ -518,9 +518,9 @@ ...@@ -518,9 +518,9 @@
except OperationalError as exception: except OperationalError as exception:
if nmspc.create_user: if nmspc.create_user:
logging.debug('Cannot connect to database with user %s', user) _logger.debug('Cannot connect to database with user %s', user)
logging.debug(exception) _logger.debug(exception)
logging.info('Creating user %s', user) _logger.info('Creating user %s', user)
if start_postgresql: if start_postgresql:
connection = connect( connection = connect(
user='pg', user='pg',
...@@ -540,5 +540,5 @@ ...@@ -540,5 +540,5 @@
connection.commit() connection.commit()
connection.close() connection.close()
else: else:
logging.fatal( _logger.fatal(
'Cannot connect to database with user %s', user) 'Cannot connect to database with user %s', user)
...@@ -544,8 +544,8 @@ ...@@ -544,8 +544,8 @@
'Cannot connect to database with user %s', user) 'Cannot connect to database with user %s', user)
logging.fatal(exception) _logger.fatal(exception)
logging.info( _logger.info(
"You can add the --create-user argument to create it") "You can add the --create-user argument to create it")
return 16 return 16
# restore # restore
if restore_filename: if restore_filename:
restore_basename = os.path.basename(restore_filename) restore_basename = os.path.basename(restore_filename)
...@@ -547,9 +547,9 @@ ...@@ -547,9 +547,9 @@
"You can add the --create-user argument to create it") "You can add the --create-user argument to create it")
return 16 return 16
# restore # restore
if restore_filename: if restore_filename:
restore_basename = os.path.basename(restore_filename) restore_basename = os.path.basename(restore_filename)
logging.info("Copying dump file in docker") _logger.info("Copying dump file in docker")
call([ call([
'docker', 'cp', restore_filename, 'docker', 'cp', restore_filename,
'{}:/tmp/{}'.format(name, restore_basename)]) '{}:/tmp/{}'.format(name, restore_basename)])
...@@ -553,6 +553,6 @@ ...@@ -553,6 +553,6 @@
call([ call([
'docker', 'cp', restore_filename, 'docker', 'cp', restore_filename,
'{}:/tmp/{}'.format(name, restore_basename)]) '{}:/tmp/{}'.format(name, restore_basename)])
logging.info("Creating database") _logger.info("Creating database")
call([ call([
'docker', 'exec', name, 'createdb', '-U', user, database]) 'docker', 'exec', name, 'createdb', '-U', user, database])
...@@ -557,8 +557,8 @@ ...@@ -557,8 +557,8 @@
call([ call([
'docker', 'exec', name, 'createdb', '-U', user, database]) 'docker', 'exec', name, 'createdb', '-U', user, database])
logging.info("Restoring database") _logger.info("Restoring database")
restore = call([ restore = call([
'docker', 'exec', name, 'pg_restore', '-U', user, '-O', 'docker', 'exec', name, 'pg_restore', '-U', user, '-O',
'-d', database, '/tmp/{}'.format(restore_basename)]) '-d', database, '/tmp/{}'.format(restore_basename)])
if not restore: if not restore:
return 15 return 15
...@@ -560,9 +560,9 @@ ...@@ -560,9 +560,9 @@
restore = call([ restore = call([
'docker', 'exec', name, 'pg_restore', '-U', user, '-O', 'docker', 'exec', name, 'pg_restore', '-U', user, '-O',
'-d', database, '/tmp/{}'.format(restore_basename)]) '-d', database, '/tmp/{}'.format(restore_basename)])
if not restore: if not restore:
return 15 return 15
logging.info("Removing dump file in docker") _logger.info("Removing dump file in docker")
call(['docker', 'exec', name, '/tmp/{}'.format(restore_basename)]) call(['docker', 'exec', name, '/tmp/{}'.format(restore_basename)])
if not start_postgresql and not odoo_help and restore_filename: if not start_postgresql and not odoo_help and restore_filename:
...@@ -566,8 +566,8 @@ ...@@ -566,8 +566,8 @@
call(['docker', 'exec', name, '/tmp/{}'.format(restore_basename)]) call(['docker', 'exec', name, '/tmp/{}'.format(restore_basename)])
if not start_postgresql and not odoo_help and restore_filename: if not start_postgresql and not odoo_help and restore_filename:
logging.info("Creating database %s", database) _logger.info("Creating database %s", database)
createdb = call([ createdb = call([
'createdb', '-U', user, database]) 'createdb', '-U', user, database])
if not createdb: if not createdb:
return 17 return 17
...@@ -570,8 +570,8 @@ ...@@ -570,8 +570,8 @@
createdb = call([ createdb = call([
'createdb', '-U', user, database]) 'createdb', '-U', user, database])
if not createdb: if not createdb:
return 17 return 17
logging.info("Restoring database %s", database) _logger.info("Restoring database %s", database)
restore = call([ restore = call([
'pg_restore', '-U', user, '-O', 'pg_restore', '-U', user, '-O',
'-d', database, restore_filename]) '-d', database, restore_filename])
...@@ -614,7 +614,7 @@ ...@@ -614,7 +614,7 @@
cmd.extend(options) cmd.extend(options)
cmd.append(image) cmd.append(image)
cmd.extend(arg) cmd.extend(arg)
logging.debug(' '.join(cmd)) _logger.debug(' '.join(cmd))
result = call(cmd) result = call(cmd)
return result return result
...@@ -624,6 +624,6 @@ ...@@ -624,6 +624,6 @@
""" """
volumes = docker_client.volumes(filters={'name': data_volume_name}) volumes = docker_client.volumes(filters={'name': data_volume_name})
if volumes['Volumes']: if volumes['Volumes']:
logging.debug('Volume %s already exist', data_volume_name) _logger.debug('Volume %s already exist', data_volume_name)
return volumes['Volumes'][0] return volumes['Volumes'][0]
else: else:
...@@ -628,6 +628,6 @@ ...@@ -628,6 +628,6 @@
return volumes['Volumes'][0] return volumes['Volumes'][0]
else: else:
logging.debug('Creating volume %s', data_volume_name) _logger.debug('Creating volume %s', data_volume_name)
return docker_client.create_volume(name=data_volume_name) return docker_client.create_volume(name=data_volume_name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment