[IMP]Odoo Scripts : make them as runnable containers
This commit is contained in:
parent
ca714c6074
commit
7fb85c8b87
11
odoo/scripts/Dockerfile
Normal file
11
odoo/scripts/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM debian:jessie
|
||||
MAINTAINER Yaltik - Fabien Bourgeois <fabien@yaltik.com>
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends python2.7-minimal python-pip
|
||||
RUN pip2 install odoorpc
|
||||
# Packages cleanup
|
||||
RUN apt-get purge -y --auto-remove && apt-get clean
|
||||
RUN useradd odoo -m -s /bin/bash
|
||||
USER odoo
|
||||
COPY *.py /home/odoo/
|
||||
WORKDIR /home/odoo
|
52
odoo/scripts/backup.py
Normal file
52
odoo/scripts/backup.py
Normal file
@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime
|
||||
import argparse
|
||||
import common
|
||||
|
||||
|
||||
def datefmt():
|
||||
""" Get adapted date format """
|
||||
today = datetime.today()
|
||||
return today.strftime('%Y-%m-%d_%Hh%Mm%Ss')
|
||||
|
||||
|
||||
def dump(odoo, bakpath, password, dbname):
|
||||
""" Dumps a database """
|
||||
dump = odoo.db.dump(password, dbname)
|
||||
fpath = '{bakpath}/{date}_{dbname}.zip'.format(bakpath=bakpath,
|
||||
dbname=dbname,
|
||||
date=datefmt())
|
||||
with open(fpath, 'wb') as zipf:
|
||||
zipf.write(dump.read())
|
||||
return fpath
|
||||
|
||||
|
||||
def dump_all(odoo, bakpath, password):
|
||||
""" Dump all databases """
|
||||
return [dump(bakpath, password, db) for db in odoo.db.list()]
|
||||
|
||||
|
||||
def main():
|
||||
""" Main function with argument parsing """
|
||||
parser = argparse.ArgumentParser(description='Backup Odoo databases')
|
||||
parser = common.parser(parser)
|
||||
parser.add_argument('-pw', '--password', type=str, required=True,
|
||||
help='the odoo master password')
|
||||
parser.add_argument('-D', '--directory', type=str, required=True,
|
||||
help='the directory path where to save backups')
|
||||
parser.add_argument('-n', '--name', type=str,
|
||||
help='optional database name (default:all)')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Connection
|
||||
odoo = common.connection(args)
|
||||
|
||||
# Backup actions
|
||||
if not args.name:
|
||||
dump_all(odoo, args.directory, args.password)
|
||||
else:
|
||||
dump(odoo, args.directory, args.password, args.name)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
19
odoo/scripts/common.py
Normal file
19
odoo/scripts/common.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import odoorpc
|
||||
|
||||
|
||||
def parser(parser):
|
||||
""" Helper that takes an arg parser, add common options and return it """
|
||||
parser.add_argument('-oh', '--host', type=str, default='odoo',
|
||||
help='the odoo host')
|
||||
parser.add_argument('-op', '--port', type=int, default=8069,
|
||||
help='the odoo port')
|
||||
return parser
|
||||
|
||||
|
||||
def connection(args):
|
||||
""" Helper that takes args and return an odoo connection """
|
||||
odoo = odoorpc.ODOO(args.host, port=args.port)
|
||||
odoo.config['timeout'] = 600
|
||||
return odoo
|
53
odoo/scripts/databases.py
Normal file
53
odoo/scripts/databases.py
Normal file
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import common
|
||||
|
||||
|
||||
def str2bool(v):
|
||||
return v.lower() in ('yes', 'true', '1')
|
||||
|
||||
|
||||
def main():
|
||||
""" Main function with argument parsing """
|
||||
parser = argparse.ArgumentParser(description='Odoo database creation '
|
||||
'according to their names')
|
||||
parser = common.parser(parser)
|
||||
parser.add_argument('-a', '--action', type=str, default='create',
|
||||
help='action for the database,' +
|
||||
'default to create')
|
||||
parser.add_argument('-d', '--database', type=str, required=True,
|
||||
help='the targetted database')
|
||||
parser.add_argument('-pw', '--password', type=str, required=True,
|
||||
help='the odoo superadmin password')
|
||||
parser.add_argument('-dm', '--demo', type=str, default='False',
|
||||
help='demonstration data')
|
||||
parser.add_argument('-l', '--lang', type=str, default='fr_FR',
|
||||
help='default language')
|
||||
parser.add_argument('-dbpw', '--database_password', type=str,
|
||||
required=True,
|
||||
help='the database admin password')
|
||||
|
||||
args = parser.parse_args()
|
||||
# Connection
|
||||
odoo = common.connection(args)
|
||||
|
||||
# Databases actions
|
||||
dblist = odoo.db.list()
|
||||
if args.action == 'create':
|
||||
if args.database in dblist:
|
||||
print 'database already exists'
|
||||
else:
|
||||
odoo.db.create(args.password, args.database, str2bool(args.demo),
|
||||
args.lang, args.database_password)
|
||||
else:
|
||||
if args.database not in dblist:
|
||||
print 'database not found'
|
||||
elif args.action == 'drop':
|
||||
odoo.db.drop(args.password, args.database)
|
||||
elif args.action == 'duplicate':
|
||||
odoo.db.duplicate(args.password, args.database, args.database +
|
||||
'_copy')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
48
odoo/scripts/modules.py
Normal file
48
odoo/scripts/modules.py
Normal file
@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import common
|
||||
|
||||
|
||||
def main():
|
||||
""" Main function with argument parsing """
|
||||
parser = argparse.ArgumentParser(description='Manage Odoo modules '
|
||||
'according to their names')
|
||||
parser = common.parser(parser)
|
||||
parser.add_argument('-db', '--database', type=str, required=True,
|
||||
help='the targetted database')
|
||||
parser.add_argument('-dbpw', '--database-password', type=str,
|
||||
required=True,
|
||||
help='the odoo database admin password')
|
||||
parser.add_argument('-a', '--action', type=str, required=True,
|
||||
choices=['listupdate', 'install', 'update', 'remove'],
|
||||
help='the action asked : listupdate, install, update '
|
||||
'or remove')
|
||||
parser.add_argument('-n', '--names', type=str, default='base',
|
||||
help='module names coma separated')
|
||||
args = parser.parse_args()
|
||||
if args.names:
|
||||
args.names = args.names.split(',')
|
||||
|
||||
# Connection
|
||||
odoo = common.connection(args)
|
||||
print args
|
||||
odoo.login(args.database, 'admin', args.database_password)
|
||||
|
||||
# Modules actions
|
||||
Module = odoo.env['ir.module.module']
|
||||
if args.action == 'listupdate':
|
||||
Module.update_list()
|
||||
else:
|
||||
if len(args.names) > 0:
|
||||
mids = Module.search([('name', 'in', args.names)])
|
||||
if args.action == 'install':
|
||||
Module.button_immediate_install(mids)
|
||||
elif args.action == 'update':
|
||||
Module.button_immediate_upgrade(mids)
|
||||
else:
|
||||
Module.button_immediate_uninstall(mids)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user