-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.py
63 lines (53 loc) · 2.06 KB
/
uninstall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Install OpenERP on a new (by default) database.
"""
import os
import sys
import common
# TODO turn template1 in a parameter
# This should be exposed from openerp (currently in
# openerp/service/web_services.py).
def create_database(database_name):
import openerp
db = openerp.sql_db.db_connect('template1')
cr = db.cursor() # TODO `with db as cr:`
try:
cr.autocommit(True)
cr.execute("""CREATE DATABASE "%s"
ENCODING 'unicode' TEMPLATE "template1" """ \
% (database_name,))
finally:
cr.close()
def run(args):
assert args.database
assert args.module
import openerp
config = openerp.tools.config
config['log_handler'] = [':CRITICAL']
if args.addons:
args.addons = args.addons.split(':')
else:
args.addons = []
config['addons_path'] = ','.join(args.addons)
openerp.netsvc.init_logger()
# Install the import hook, to import openerp.addons.<module>.
openerp.modules.module.initialize_sys_path()
registry = openerp.modules.registry.RegistryManager.get(
args.database, update_module=False)
ir_module_module = registry.get('ir.module.module')
with registry.cursor() as cr:
ids = ir_module_module.search(cr, openerp.SUPERUSER_ID, [('name', 'in', args.module), ('state', '=', 'installed')], {})
if len(ids) == len(args.module):
ir_module_module.button_immediate_uninstall(cr, openerp.SUPERUSER_ID, ids, {})
else:
print "At least one module not found (database `%s`)." % (args.database,)
def add_parser(subparsers):
parser = subparsers.add_parser('uninstall',
description='Uninstall some modules from an OpenERP database.')
parser.add_argument('-d', '--database', metavar='DATABASE',
**common.required_or_default('DATABASE', 'the database to modify'))
common.add_addons_argument(parser)
parser.add_argument('--module', metavar='MODULE', action='append',
help='specify a module to uninstall'
' (this option can be repeated)')
parser.set_defaults(run=run)