forked from gdometrics/django-erp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_version.py
48 lines (42 loc) · 1.55 KB
/
update_version.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
# -*- coding: utf-8 -*-
import os
import sys
from datetime import datetime
def replace(root, replace_dict):
if root[-1] == "/":
root = root[0:-1]
for x in os.listdir(root):
path = root + "/" + x
if os.path.isdir(path):
replace(path, replace_dict)
else:
p, sep, ext = path.partition('.')
if ext in ("py", "py.tmpl"):
replaced = False
infile = open(path, "r+")
text = infile.read()
infile.seek(0)
for old_string, new_string in replace_dict.items():
if text.find(old_string) != -1:
text = text.replace(old_string, new_string)
replaced = True
infile.seek(0)
infile.truncate()
infile.write(text)
if replaced:
print "Replaced in " + path
infile.close()
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: %s <new_version>" % sys.argv[0]
sys.exit(1)
ref_file = open("djangoerp/__init__.py")
text = ref_file.read()
ref_file.close()
replace_dict = {}
for line in text.split("\n"):
if line.startswith("__copyright__"):
replace_dict[line] = "__copyright__ = 'Copyright (c) 2013-%d, django ERP Team'" % datetime.now().year
if line.startswith("__version__"):
replace_dict[line] = "__version__ = '%s'" % sys.argv[1]
replace("djangoerp", replace_dict)