-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_bulk_action.py
More file actions
38 lines (30 loc) · 1.23 KB
/
file_bulk_action.py
File metadata and controls
38 lines (30 loc) · 1.23 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
import os
import string
def task(source,target):
files = os.listdir(source)
target_files = {}
for source_file in files:
if source_file.endswith('.java'):
file_list = source_file.split('.')
new_file = file_list[0]+'Test.java'
new_class = file_list[0]+'Test'
target_files.update({new_class:new_file})
for new_class,target_file in target_files.items():
absolute_file = target + target_file
file_stream = open(absolute_file,'a')
code_template = '''
public class $class {
@Test
public void test$source(){
}
}
'''
t = string.Template(code_template)
file_stream.write(t.substitute({'class':new_class,'source':new_class.strip('Test')}));
file_stream.close()
if __name__ == '__main__':
print 'The task starts'
source_directory = 'F:\eclipse\workspace\ZenJava\src\main\java\com\wonderfan\\'
target_directory = 'F:\eclipse\workspace\ZenJava\src\test\java\com\wonderfan\\'
task(source_directory,target_directory)
print 'The task is over'