-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproTemp.py
147 lines (116 loc) · 5.1 KB
/
proTemp.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import sys
import sublime
import sublime_plugin
import functools
all_pro_info = sublime.active_window().extract_variables()
project_path = all_pro_info['folder']
def Window():
'''Get current active window'''
return sublime.active_window()
def get_project_name():
'''Get project name'''
project_data = sublime.active_window().project_data()
project = os.path.basename(
project_data['folders'][0]['path']) if project_data else None
return project
def get_file_path(path):
'''Get absolute path of the file'''
return 'undefined' if path is None else path
def get_file_name(path):
'''Get name of the file'''
return 'undefined' if path is None else os.path.basename(path)
def get_file_name_without_extension(file_name):
'''Get name of the file without extension'''
return '.'.join(file_name.split('.')[:-1]) or file_name
def remove_project(project, module):
'''Remove created project folders and files'''
return '''-'''+project+'''/json/'''+module+'''/getlist.js
-'''+project+'''/json/'''+module+'''/add.js
-'''+project+'''/json/'''+module+'''/delete.js
-'''+project+'''/json/'''+module+'''/getedit.js
-'''+project+'''/json/'''+module+'''/setedit.js
-'''+project+'''/json/'''+module+'''/
-'''+project+'''/json/
-'''+project+'''/view/'''+module+'''/list.html
-'''+project+'''/view/'''+module+'''/detail.html
-'''+project+'''/view/'''+module+'''/
-'''+project+'''/view/
-'''+project+'''/
-res/src/'''+project+'''/css/'''+module+'''/'''+module+'''.less
-res/src/'''+project+'''/css/'''+module+'''/
-res/src/'''+project+'''/css/
-res/src/'''+project+'''/js/'''+module+'''/list.html
-res/src/'''+project+'''/js/'''+module+'''/list.js
-res/src/'''+project+'''/js/'''+module+'''/detail.html
-res/src/'''+project+'''/js/'''+module+'''/detail.js
-res/src/'''+project+'''/js/'''+module+'''/
-res/src/'''+project+'''/js/
-res/src/'''+project+'''/'''
def add_new_project(project, module):
'''Create project folders and files'''
return project + '''/json(
''' + module + '''/getlist.js
''' + module + '''/saveadd.js
''' + module + '''/delete.js
''' + module + '''/getedit.js
''' + module + '''/saveedit.js
)
''' + project + '''/view(
''' + module + '''/list.html
''' + module + '''/detail.html
)
res/src/''' + project + '''/css/''' + module + '''/''' + module + '''.less
res/src/''' + project + '''/js(
''' + module + '''/list.html
''' + module + '''/list.js
''' + module + '''/detail.html
''' + module + '''/detail.js
)'''
def setProjectTree(args, args2):
'''Set project folders and files'''
le_solution = args2.split('/')[0]
newModule = args2.split('/')[1]
folders = sublime.active_window().project_data()
print('get_project_name:'+get_project_name())
from os.path import dirname, realpath
print(dirname(realpath(__file__)))
file_object = open( project_path + '/' + newModule + '.stprj', 'w')
try:
if le_solution[0] == '-':
le_solution=le_solution.replace('-','')
all_the_text = remove_project(le_solution, newModule)
else:
all_the_text = add_new_project(le_solution, newModule)
file_object.write(all_the_text)
finally:
# file_object.flush( )
file_object.close()
#endof setProjectTree
def delProjectConfig(arg1, file_name):
'''Delete project config files'''
print('print_filename:'+file_name)
if file_name == '*':
n = 0
for root, dirs, files in os.walk(project_path + '/'):
for name in files:
if(name.endswith(".stprj")):
n += 1
os.remove(os.path.join(root, name))
else:
file_object = os.remove( project_path + '/' + file_name + '.stprj')
#endof delProjectConfig
class ProjectStprjUpdateFileCommand(sublime_plugin.TextCommand):
'''Set project folders and files command'''
Window().run_command('hide_panel')
def run(a, b):
Window().show_input_panel('Add/Remove Project:', 'project/module', functools.partial(
setProjectTree, '')
, None, None)
class projectDeleteConfigCommand(sublime_plugin.TextCommand):
'''Delete project folders and files command'''
Window().run_command('hide_panel')
def run(a, b):
Window().show_input_panel('Add/Remove Project:', '*', functools.partial(
delProjectConfig, '')
, None, None)