-
Notifications
You must be signed in to change notification settings - Fork 2
/
oe_list_models
executable file
·74 lines (61 loc) · 2.38 KB
/
oe_list_models
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
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python
"""List fields in an OpenERP model.
"""
import sys
import argparse
import csv
from oekit import oe_client_env
from itertools import starmap
def main(options):
"""Main program."""
cl = oe_client_env.OEClientEnv()
oe = cl.get_proxy()
heads = ['model', 'name', 'osv_memory', 'state']
retrieve_fields = list(heads)
module = options.module
if 'modules' not in retrieve_fields and module:
retrieve_fields.append('modules')
model_ids = oe.execute('ir.model', 'search', [], 0, False, 'model,id')
models = oe.execute('ir.model', 'read', model_ids, retrieve_fields)
if module:
models = [m for m in models if module in modules_of(m)]
if options.model_only:
sys.stdout.writelines(('%s\n' % m['model']) for m in models)
else:
outcsv = csv.DictWriter(sys.stdout, heads, extrasaction='ignore',)
outcsv.writeheader()
outcsv.writerows(models)
return
def modules_of(model):
return model['modules'].split(', ')
def get_options():
"""Get options for the script."""
parser = argparse.ArgumentParser(
description="get list of OpenERP models as a CSV report",
)
parser.add_argument('-m', '--model-only', action='store_true',
help='only list model codes, with no header'
)
parser.add_argument('-M', '--module', default=None, type=str,
help='list only models touched by given module'
)
options = parser.parse_args()
# extra processing of options here
return options
if __name__ == "__main__":
main(get_options())
__COPYRIGHT__ = """
This program is part of oekit: https://github.com/nmbooker/oekit
Copyright (c) 2015 Nicholas Booker <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""