Forward port of branch 7.0 up to rev 8abd003
[odoo/odoo.git] / openerpcommand / scaffold.py
1 """
2 Generate an OpenERP module skeleton.
3 """
4
5 import os
6 import sys
7
8 def run(args):
9     assert args.module
10     module = args.module
11
12     if os.path.exists(module):
13         print "The path `%s` already exists."
14         sys.exit(1)
15
16     os.mkdir(module)
17     os.mkdir(os.path.join(module, 'models'))
18     with open(os.path.join(module, '__openerp__.py'), 'w') as h:
19         h.write(MANIFEST)
20     with open(os.path.join(module, '__init__.py'), 'w') as h:
21         h.write(INIT_PY)
22     with open(os.path.join(module, 'models', '__init__.py'), 'w') as h:
23         h.write(MODELS_PY % (module,))
24
25 def add_parser(subparsers):
26     parser = subparsers.add_parser('scaffold',
27         description='Generate an OpenERP module skeleton.')
28     parser.add_argument('module', metavar='MODULE',
29         help='the name of the generated module')
30
31     parser.set_defaults(run=run)
32
33 MANIFEST = """\
34 # -*- coding: utf-8 -*-
35 {
36     'name': '<Module name>',
37     'version': '0.0',
38     'category': '<Category>',
39     'description': '''
40 <Long description>
41 ''',
42     'author': '<author>',
43     'maintainer': '<maintainer>',
44     'website': 'http://<website>',
45     # Add any module that are necessary for this module to correctly work in
46     # the `depends` list.
47     'depends': ['base'],
48     'data': [
49     ],
50     'test': [
51     ],
52     # Set to False if you want to prevent the module to be known by OpenERP
53     # (and thus appearing in the list of modules).
54     'installable': True,
55     # Set to True if you want the module to be automatically whenever all its
56     # dependencies are installed.
57     'auto_install': False,
58 }
59 """
60
61 INIT_PY = """\
62 # -*- coding: utf-8 -*-
63 import models
64 """
65
66 MODELS_PY = """\
67 # -*- coding: utf-8 -*-
68 import openerp
69
70 # Define a new model.
71 class my_model(openerp.osv.osv.Model):
72
73     _name = '%s.my_model'
74
75     _columns = {
76     }
77 """