-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommitpermodule
executable file
·146 lines (126 loc) · 4.51 KB
/
commitpermodule
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python
# -*- coding: utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
import argparse
import argcomplete
import os
import pprint
class CommitPerModule(object):
"""
This object pretend to get and odoo addons path and aplicate one commit for
every module.
It is usefull when apply a gobal change in all the modules via script and
want to commit the change per module.
"""
epilog = '\n'.join([
'Odoo Developer Comunity Tool',
'Developed by Katherine Zaoral <[email protected]>'
' <github.com/zaoral>',
'Source code at git:vauxoo-dev/gist-vauxoo.',
' '
])
description = '\n'.join([
'Make a commit per module.\n',
'NOTE: It is usefull when apply a gobal change in all the modules via',
' script and want to commit the change per module.',
])
def __init__(self):
"""
Initialization of the class.
@return: None
"""
self.args = self.argument_parser()
self.path = self.args['path']
self.msg = self.args['msg']
if self.args.get('no_confirm', False):
pass
else:
self.confirm_run(self.args)
return None
def argument_parser(self):
"""
This function create the help command line, manage and filter the
parameters of this script (default values, choices values).
@return dictionary of the arguments.
"""
parser = argparse.ArgumentParser(
prog='commitpermodule',
formatter_class=argparse.RawTextHelpFormatter,
description=self.description,
epilog=self.epilog)
parser.add_argument(
'--no-confirm',
action='store_true',
help=('Do not ask user for confirmation before run the script.'
'\nDefault is True'))
parser.add_argument(
'-p', '--path',
metavar='PATH',
type=str,
required=True,
help='The addons module path were you want to apply the new'
'\ncommits.')
parser.add_argument(
'-m', '--msg',
metavar='MESSAGE',
type=str,
required=True,
help='\n'.join([
'The commit message to use. You can add {module} tag to',
'reference the module name in the commit. Example:\n',
' "[ADD] Move {module} module description from',
' the openerp descriptor to a README.md file."',
]))
argcomplete.autocomplete(parser)
return parser.parse_args().__dict__
def confirm_run(self, args):
"""
Manual confirmation before runing the script. Very usefull.
@param args: dictionary of arguments.
@return True or exit the program in the confirm is no.
"""
pprint.pprint('\n... Configuration of Parameters Set')
for (parameter, value) in args.iteritems():
pprint.pprint('%s = %s' % (parameter, value))
question = 'Confirm the run with the above parameters?'
answer = 'The script parameters were confirmed by the user'
self.confirmation(question, answer)
return True
def confirmation(self, question, answer):
"""
Manual confirmation for the user.
@return True or exit the program in the confirmation in negative.
"""
confirm_flag = False
while confirm_flag not in ['y', 'n']:
confirm_flag = raw_input(question + ' [y/n]: ')
if confirm_flag == 'y':
pprint.pprint(answer)
elif confirm_flag == 'n':
pprint.pprint('The user cancel the operation')
exit()
else:
pprint.pprint('The entry is not valid, please enter y or n.')
return True
def run(self):
"""
run the given command in the command line.
@return True
"""
for root, dirnames, filenames in os.walk(self.path):
dirnames = dirnames
if '__openerp__.py' in filenames:
module = os.path.basename(root)
os.system(
'echo "Commit to {module} module"'.format(module=module))
os.system('cd {path} && git commit . -m "{msg}"'.format(
path=root,
msg=self.msg.format(module=module)
))
return True
def main():
obj = CommitPerModule()
obj.run()
return True
if __name__ == '__main__':
main()