-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn03_CodeAutoBuild.py
More file actions
62 lines (48 loc) · 1.41 KB
/
Copy pathlearn03_CodeAutoBuild.py
File metadata and controls
62 lines (48 loc) · 1.41 KB
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
# coding:utf8
import os
import re
import time
autCodeStr = """
package <packageName>;
public class <fileName> {
/*
* 第一个java程序,将打印helloworld
*/
public static void main(String []args) {
System.out.println("hello world");
}
}
"""
class MakeModel:
packageName = ''
fileName = ''
def __init__(self, packageName, fileName):
self.packageName = packageName
self.fileName = fileName
print 'start'
def createFile(self):
f = open('test.java', 'w+')
# str_a = autCodeStr.replace(self.packageName, '<packageName>')
# str_b = str_a.replace(self.fileName, '<fileName>')
table_a = ['<packageName>', '<fileName>']
table_b = [self.packageName, self.fileName]
replace_str = self.replace_var(table_a, table_b, autCodeStr)
print replace_str
f.write(replace_str)
f.close()
def replace_var(self, a, b, c):
strinfo = re.compile(a[1])
h = strinfo.sub(b[1], c)
print '-------------------------'
for x in range(len(a)):
print 'a'+a[x]
print 'b'+b[x]
c = self.replace(a[x], b[x], c)
print '========================'
return c
def replace(self,a,b,c):
strinfo = re.compile(a)
return strinfo.sub(b,c)
if __name__ == '__main__':
javaModle = MakeModel('learnCodeAuto', 'test')
javaModle.createFile()