-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottleapp.py
64 lines (54 loc) · 1.46 KB
/
bottleapp.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
from bottle import route, run
from dbfsapi import DatabricksFileAPI
import json
from jinja2 import Template
dbfapi = DatabricksFileAPI(
host='http://localhost:8001',
token='',
api_route='/'
)
template = Template(
"""<html><body>
<table style="border: 10px solid white; width: 100%;" rules="groups">
<thead style="border-bottom: 1px solid black; text-align: left;">
<tr>
<th>Path</th><th>Directory</th><th>Size</th>
</tr>
</thead>
<tbody>
{% for row in directories %}
<tr>
<td><a href=/{{ row.path }}>{{ row.path.split('/')[-1] }}</a></td>
<td>{{ row.is_dir }}</td>
<td>{{ row.file_size }}</td>
</tr>
{% endfor %}
{% for row in files %}
<tr>
<td>{{ row.path.split('/')[-1] }}</td>
<td>{{ row.is_dir }}</td>
<td>{{ row.file_size }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body></html>
"""
)
def table(j):
d = sorted(
filter(lambda x: x.get('is_dir'), j),
key=lambda x: (not x.get('is_dir'), x.get('path').lower())
)
f = sorted(
filter(lambda x: not x.get('is_dir'), j),
key=lambda x: (not x.get('is_dir'), x.get('path').lower())
)
return template.render(directories=d, files=f)
@route('<apiurl:path>')
def test(apiurl):
apiurl = apiurl.lstrip('/')
print('SHOWING:', apiurl)
ret = dbfapi.List(apiurl)
return table(ret)
run(host='localhost', port=8002)