-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.py
executable file
·335 lines (261 loc) · 10.2 KB
/
compile.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/python3.4
from bottle import route, run, template, request
import bottle
import json
import sys
import subprocess
import os
#from urlparse import urlparse
from bottle import static_file
@route('/static/:path#.+#', name='static')
def static(path):
return static_file(path, root='static')
sys.path.append('workspace/py/path.py')
from path import Path
def do_command(args, path ):
d = Path('workspace')
if path :
d = d / path
print ("going into {0}".format(d))
if (not d.exists()):
raise Exception(d3)
p = subprocess.Popen(args,
shell=True,
#stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=d)
stdout = p.stdout
stderr = p.stderr
stdout_o = stdout.read().decode("utf-8").split("\n") #.read()
stderr_o = stderr.read().decode("utf-8").split("\n")
retcode = p.wait();
data = json.dumps({
'path' : d,
'stdout': stdout_o,
'stderr': stderr_o,
'cmd' : args,
'retcode' : retcode,
})
print (data)
if not retcode == 0:
raise Exception("bad return")
return data
# cmd is array of args
@route('/run/<cwd>/<cmd>')
def run_command(cmd, cwd):
d = Path('workspace')
args = [cmd]
path = bottle.request.params.get('path')
if path :
cwd = cwd / path
qpairs= bottle._parse_qsl(bottle.request.query_string)
for key, value in qpairs :
if key == 'args':
args.append(value)
data = do_command(args, cwd )
return """<html>
<head>
<!-- bower:css -->
<link rel="stylesheet" href="/static/js/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="/static/js/angular-ui-tree/dist/angular-ui-tree.min.css" />
<!-- uigrid -->
<link rel="stylesheet" href="/static/js/angular-ui-grid/ui-grid.css" />
<link rel="stylesheet" href="/static/js/animate.css/animate.css" />
<link rel="stylesheet" href="/static/js/fontawesome/css/font-awesome.css" />
<link rel="stylesheet" href="/static/css/introspector.css" />
<!-- endbower -->
</head>
<body ng-app="introspectorApp">
<!-- bower:js -->
<script src="/static/js/jquery/dist/jquery.js"></script>
<script src="/static/js/angular/angular.js"></script>
<script src="/static/js/bootstrap/dist/js/bootstrap.js"></script>
<script src="/static/js/angular-animate/angular-animate.js"></script>
<script src="/static/js/angular-aria/angular-aria.js"></script>
<script src="/static/js/angular-cookies/angular-cookies.js"></script>
<script src="/static/js/angular-messages/angular-messages.js"></script>
<script src="/static/js/angular-resource/angular-resource.js"></script>
<script src="/static/js/angular-route/angular-route.js"></script>
<script src="/static/js/angular-sanitize/angular-sanitize.js"></script>
<script src="/static/js/angular-touch/angular-touch.js"></script>
<script src="/static/js/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="/static/js/angular-ui-tree/dist/angular-ui-tree.js"></script>
<script src="/static/js/angular-ui-grid/ui-grid.js"></script>
<script src="/static/js/d3/d3.js"></script>
<!-- v1 -->
<link rel="stylesheet" href="/static/js/angular-json-edit/dist/styles/jsonEditor.css">
<script src="/static/js/angular-json-edit/dist/angularJsonEdit.js"></script>
<!-- editor -->
<script type="text/javascript" src="/static/js/ace-builds/src-min-noconflict/ace.js"></script>
<script type="text/javascript" src="/static/js/angular-ui-ace/ui-ace.js"></script>
<!-- endbower -->
<script src="/static/js/introspector/default.js"></script>
<!-- warning large data object injected here! -->
<div id=raw-data-object class=raw-data data-ng-init='raw_data_object={data}'></div>
<!-- Add your site or application content here -->
<div class="header">
<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#/">introspector</a>
</div>
<div class="collapse navbar-collapse" id="js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#/">Home</a></li>
<li><a ng-href="#/tree">Tree</a></li>
<li><a ng-href="#/graph">Graph</a></li>
<li><a ng-href="#/table">Table</a></li>
<li><a ng-href="#/source">Source</a></li>
<li><a ng-href="#/about">About</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div ng-view=""></div>
</div>
<div class="footer">
<div class="container">
<p>made by the Introspector Team</p>
</div>
</div>
<script src="/static/js/introspector/app.js"></script>
<script src="/static/js/introspector/controllers/main.js"></script>
<script src="/static/js/introspector/controllers/about.js"></script>
<script src="/static/js/introspector/controllers/tree.js"></script>
<script src="/static/js/introspector/controllers/table.js"></script>
<script src="/static/js/introspector/controllers/graph.js"></script>
<script src="/static/js/introspector/controllers/source.js"></script>
</body>
</html>""".format( data=data)
else:
return template('<b>dir does not exists {{d3}}</b>!', d3=d3)
#import pygit2
#from git.objects.submodule.base import Submodule
# create a new venv
def python_create_venv ():
pass
def python_install_venv ():
# install this module into venv
pass
# add a git submodule into the project
def git_submodule(name, path, url, branch):
#print sys.path
from git.repo.base import Repo
d = str(Path('.').abspath())
repo = Repo(d) # current repo
from git.objects.submodule.base import Submodule
s = Submodule.add(repo,name,path, url, branch)
#s = self.repo.lookup_submodule(SUBM_PATH)
#self.repo.listall_submodules()
return str(Path(path).abspath())
# one time setup to install all prerequisites
# requires GitPython to be installed: https://github.com/gitpython-developers/GitPython
# remote_url = Repo().remotes.origin.url
# parsed = urlparse(remote_url)
# remote_path = parsed.path
# if parsed.netloc:
# remote_host = parsed.netloc
# else:
# remote_host = parsed.scheme
def grunt (p):
print ("running grunt in", p)
do_command('npm install',p)
do_command('npm install grunt',p)
do_command('grunt',p)
def git_my_submodule_python(source_dir=None, mount=None, original=None, my_repo=None):
if not mount:
raise Exception("no mount")
if source_dir:
p = do_mount(source_dir, mount)
else:
p = workspace_dir(mount)
if p not in sys.path:
sys.path.append(p)
return p
# update submodules for that module
def run_pip(req):
import pip
pip.main(initial_args = ['install', "-e", req ])
@route('/setup')
def requirements() :
#run_pip(
# 'git+ssh://git@github.com:gitpython-developers/gitdb.git#egg=gitdb'
#)
git_my_submodule_python(
mount='py/path.py',
original='git@github.com:jaraco/path.py.git',
my_repo='git@github.com:h4ck3rm1k3/path.py.git')
git_my_submodule_python(source_dir='../../GitPython',
mount='py/gitpython',
original='git@github.com:gitpython-developers/GitPython.git',
my_repo='git@github.com:h4ck3rm1k3/GitPython.git')
# git_submodule(name='js/requirejs',
# path='static/js/requirejs',
# url='git@github.com:jrburke/requirejs.git',
# branch="master")
# grunt(git_submodule(name='js/jquery',
# path='static/js/jquery',
# url='git@github.com:jquery/jquery.git',
# branch="master"))
# bower(git_submodule(name='js/angularjs',
# path='static/js/angularjs',
# url='git@github.com:angular/angular.js.git',
# branch="master"))
# git_submodule(name='js/d3',
# path='static/js/d3',
# url='git@github.com:mbostock/d3.git',
# branch="master")
# git_submodule(name='js/angular-ui-tree',
# path='static/js/angular-ui-tree',
# url='git@github.com:angular-ui-tree/angular-ui-tree.git',
# branch="master")
# git_submodule(name='js/angular-ui-grid',
# path='static/js/angular-ui-grid',
# url='git@github.com:angular-ui/ui-grid.git',
# branch="master")
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
@route('/clone/<url>')
def clone(name):
return template('<b>going to clone {{url}}</b>!', name=name)
def workspace_dir(name):
d = Path('workspace')
if (not d.exists()):
d.mkdir()
d3 = d / name
if (not d3.parent.exists()):
d3.parent.mkdir()
return d3.abspath()
def do_mount(path, name):
d3 = workspace_dir(name)
d2 = Path(path).abspath()
if (not d3.exists()):
if d2.exists():
d2.symlink(d3)
return d3
@route('/mount/<name>')
def mount(name):
path = bottle.request.params.get('path')
do_mount(path, name)
return template('<b>going to mount {{name}}</b> {{path}}!',
name=name,
path=path)
def test():
do_mount("/tmp", "test")
requirements()
run(host='localhost',
port=8080,
debug=True,
reloader=True,
reload_interval=1
)