-
Notifications
You must be signed in to change notification settings - Fork 153
/
chmove.py
41 lines (33 loc) · 1.11 KB
/
chmove.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
#!/usr/bin/python
#
# This tool is used to "rename" chapter examples.
#
import sys, os
DRYRUN = 0
start = 17
end = 21
print "Retrieving projects list...."
projectDirs = [d for d in os.listdir(os.getcwd()) if d.startswith("nucleo-")]
for i in reversed(range(start, end+1)):
srcCH = "ch%d" % i
dstCH = "ch%d" % (i + 1)
srcCHdes = "Chapter %d" % i
dstCHdes = "Chapter %d" % (i + 1)
print "Moving %s to %s" % (srcCH, dstCH)
for projectDir in projectDirs:
cproject = open(os.path.join(os.getcwd(), projectDir, ".cproject"), "r+")
cprojectData = cproject.read()
cprojectData = cprojectData.replace(srcCH, dstCH)
cprojectData = cprojectData.replace(srcCH.upper(), dstCH.upper())
cprojectData = cprojectData.replace(srcCHdes, dstCHdes)
cproject.seek(0)
print "Changing projects: ", cproject.name
if not DRYRUN:
cproject.write(cprojectData)
cproject.close()
try:
print "Renaming directory: ", os.path.join(os.getcwd(), projectDir, "src", srcCH)
if not DRYRUN:
os.rename(os.path.join(os.getcwd(), projectDir, "src", srcCH), os.path.join(os.getcwd(), projectDir, "src", dstCH))
except OSError:
pass