-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject_builder
More file actions
executable file
·68 lines (53 loc) · 2.34 KB
/
project_builder
File metadata and controls
executable file
·68 lines (53 loc) · 2.34 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
63
64
65
66
67
68
#!/usr/bin/python
import subprocess
import sys
import os
from sys import platform as _platform
if len(sys.argv) < 2:
print 'usage: project_builder <name>'
sys.exit()
script_path = os.path.realpath(sys.argv[0])
script_dir = os.path.dirname(script_path)
project_name = sys.argv[1]
project_path = os.path.abspath(project_name)
template = 'autotools_project_template'
template_label = '%' + template + '%'
template_path = project_path + '/' + template
print project_path
retrieve_command = 'mkdir ' + project_path + ' && cd ' + project_path + ' && cp -a ' + script_dir + '/template ' + template
print retrieve_command
subprocess.check_call(retrieve_command, shell=True)
print 'project_path: ', project_path
new_files = []
trunk, dirs, files = next(os.walk(template_path))
valid_files = filter(lambda a: a[0] != '.', files)
valid_dirs = filter(lambda a: a[0] != '.', dirs)
for a in valid_files:
new_files.append(trunk + '/' + a)
for b in valid_dirs:
trunk, sub_dirs, other_files = next(os.walk(template_path + '/' + b))
for c in other_files:
new_files.append(trunk + '/' + c)
pattern = '\'s/' + template_label + '/' + project_name + '/g\''
for file in new_files:
if _platform == "linux" or _platform == "linux2":
# linux
replace_command = 'sed -i ' + pattern + ' ' + file
elif _platform == "darwin":
# MAC OS X
replace_command = 'sed -i \'\' ' + pattern + ' ' + file
subprocess.check_call(replace_command, shell=True)
merge_command = 'cd ' + project_path + ' && rsync -avz ' + template_path + '/' + ' ' + project_path
subprocess.check_call(merge_command, shell=True)
subprocess.check_call('rm -rf ' + template_path, shell=True)
subprocess.check_call('rm -rf ' + project_path + '/.git', shell=True)
pattern = '\'s/' + template + '/' + project_name + '/g\''
for e in valid_dirs:
if os.system('ls ' + project_path + '/' + e + '/' + template + '*') == 0:
if _platform == "linux" or _platform == "linux2":
# linux
rename_command = 'cd ' + project_path + '/' + e + ' && rename \'' + template + '\' \'' + project_name + '\' ' + template + '*.*'
elif _platform == "darwin":
# MAC OS X
rename_command = 'cd ' + project_path + '/' + e + ' && rename \'' + template + '\' \'' + project_name + '\' *'
subprocess.check_call(rename_command, shell=True)