summaryrefslogtreecommitdiff
path: root/openerpcommand
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2014-04-08 14:51:22 +0200
committerRaphael Collet <rco@openerp.com>2014-04-08 14:51:22 +0200
commit6bc60505f4e25d5ce7181f30d33692a8e7d08fe0 (patch)
treefec08c9fd2716b38973bec28db672e05ec6fdc91 /openerpcommand
parentb49f536baff6fab13884f4b2b6fdee1cb407f128 (diff)
[IMP] registry: add method get_cursor() to simply retrieve a new cursor, and refactor code to use it
bzr revid: rco@openerp.com-20140408125122-ki0zmin3m21k2itd
Diffstat (limited to 'openerpcommand')
-rw-r--r--openerpcommand/module.py5
-rw-r--r--openerpcommand/read.py5
-rw-r--r--openerpcommand/uninstall.py5
3 files changed, 3 insertions, 12 deletions
diff --git a/openerpcommand/module.py b/openerpcommand/module.py
index 550e0a2be28..284c0186785 100644
--- a/openerpcommand/module.py
+++ b/openerpcommand/module.py
@@ -33,12 +33,9 @@ def run(args):
xs = []
ir_module_module = registry.get('ir.module.module')
- cr = registry.db.cursor() # TODO context manager
- try:
+ with registry.cursor() as cr:
ids = ir_module_module.search(cr, openerp.SUPERUSER_ID, [], {})
xs = ir_module_module.read(cr, openerp.SUPERUSER_ID, ids, [], {})
- finally:
- cr.close()
if xs:
print "Modules (database `%s`):" % (args.database,)
diff --git a/openerpcommand/read.py b/openerpcommand/read.py
index 5b68fb26ef0..61c05117875 100644
--- a/openerpcommand/read.py
+++ b/openerpcommand/read.py
@@ -20,15 +20,12 @@ def run(args):
registry = openerp.modules.registry.RegistryManager.get(
args.database, update_module=False)
model = registry[args.model]
- cr = registry.db.cursor() # TODO context manager
field_names = [args.field] if args.field else []
if args.short:
# ignore --field
field_names = ['name']
- try:
+ with registry.cursor() as cr:
xs = model.read(cr, 1, args.id, field_names, {})
- finally:
- cr.close()
if xs:
print "Records (model `%s`, database `%s`):" % (args.model, args.database)
diff --git a/openerpcommand/uninstall.py b/openerpcommand/uninstall.py
index 27e4e04002a..244b0575e53 100644
--- a/openerpcommand/uninstall.py
+++ b/openerpcommand/uninstall.py
@@ -43,15 +43,12 @@ def run(args):
args.database, update_module=False)
ir_module_module = registry.get('ir.module.module')
- cr = registry.db.cursor() # TODO context manager
- try:
+ 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,)
- finally:
- cr.close()
def add_parser(subparsers):
parser = subparsers.add_parser('uninstall',