-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels_sanitizer.py
58 lines (44 loc) · 1.73 KB
/
models_sanitizer.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
# -*- coding: utf-8 -*-
# Copyright 2011 Machinalis: http://www.machinalis.com/
#
# 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, see <http://www.gnu.org/licenses/>.
__author__ = "Matias Herranz ([email protected])"
__version__ = "0.1"
import os
import re
# Base directory path from where to walk template directories.
# Set the paths according to your project.
CURRENT_PATH = os.path.realpath(".")
BASE_PATH = CURRENT_PATH + '/trunk/'
print BASE_PATH
def sanitizer():
for root, dirs, files in os.walk(BASE_PATH):
for name in files:
if ('.svn' not in root) and (name == 'models.py'):
print '==> root: ', root
print 'root: ', root
print 'name: ', name
print''
make_replacements(root, name)
def make_replacements(root, name):
filepath = os.path.join(root, name)
data = open(filepath).read()
o = open(filepath, "w")
# uncomment here to change one or another:
# this should be a parameter of the function. A TODO :-)
# o.write(re.sub("maxlength", "max_length", data))
o.write(re.sub("FloatField", "DecimalField", data))
o.close()
if __name__ == '__main__':
sanitizer()