Skip to content

Commit 7f39922

Browse files
committed
Uber Nice display + do not include hidden files
1 parent f4064c9 commit 7f39922

File tree

3 files changed

+180
-56
lines changed

3 files changed

+180
-56
lines changed

browse.json

+100-21
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,190 @@
11
{
22
"css": {
33
"isDir": true,
4+
"kind": "folder",
5+
"mDate": "2014-06-23 14:08:20",
46
"name": "css",
57
"subFolder": {
68
"fonts": {
79
"isDir": true,
10+
"kind": "folder",
11+
"mDate": "2014-06-23 13:56:34",
812
"name": "fonts",
913
"subFolder": {
1014
"fontawesome-webfont.svg": {
1115
"isDir": false,
16+
"kind": "svg",
17+
"mDate": "2014-06-23 13:54:56",
18+
"name": "fontawesome-webfont.svg",
1219
"url": "http://127.0.0.1/css/fonts/fontawesome-webfont.svg",
13-
"name": "fontawesome-webfont.svg"
20+
"size": "158.2 KB"
1421
},
1522
"Titillium-webfont.svg": {
1623
"isDir": false,
24+
"kind": "svg",
25+
"mDate": "2014-06-23 13:54:56",
26+
"name": "Titillium-webfont.svg",
1727
"url": "http://127.0.0.1/css/fonts/Titillium-webfont.svg",
18-
"name": "Titillium-webfont.svg"
28+
"size": "46.9 KB"
1929
},
2030
"Titillium-webfont.woff": {
2131
"isDir": false,
32+
"kind": "woff",
33+
"mDate": "2014-06-23 13:54:56",
34+
"name": "Titillium-webfont.woff",
2235
"url": "http://127.0.0.1/css/fonts/Titillium-webfont.woff",
23-
"name": "Titillium-webfont.woff"
36+
"size": "21.9 KB"
2437
},
2538
"fontawesome-webfont.woff": {
2639
"isDir": false,
40+
"kind": "woff",
41+
"mDate": "2014-06-23 13:54:56",
42+
"name": "fontawesome-webfont.woff",
2743
"url": "http://127.0.0.1/css/fonts/fontawesome-webfont.woff",
28-
"name": "fontawesome-webfont.woff"
44+
"size": "33.6 KB"
2945
}
30-
}
46+
},
47+
"size": "-"
3148
},
3249
"wuala_theme.css": {
3350
"isDir": false,
51+
"kind": "css",
52+
"mDate": "2014-06-23 13:54:56",
53+
"name": "wuala_theme.css",
3454
"url": "http://127.0.0.1/css/wuala_theme.css",
35-
"name": "wuala_theme.css"
55+
"size": "463 B"
3656
},
3757
"main.css": {
3858
"isDir": false,
59+
"kind": "css",
60+
"mDate": "2014-06-23 13:54:56",
61+
"name": "main.css",
3962
"url": "http://127.0.0.1/css/main.css",
40-
"name": "main.css"
63+
"size": "603 B"
4164
},
4265
"wuala_foundation.min.css": {
4366
"isDir": false,
67+
"kind": "css",
68+
"mDate": "2014-06-23 13:54:56",
69+
"name": "wuala_foundation.min.css",
4470
"url": "http://127.0.0.1/css/wuala_foundation.min.css",
45-
"name": "wuala_foundation.min.css"
71+
"size": "44.8 KB"
4672
},
4773
"wuala_style-all.min.css": {
4874
"isDir": false,
75+
"kind": "css",
76+
"mDate": "2014-06-23 14:08:00",
77+
"name": "wuala_style-all.min.css",
4978
"url": "http://127.0.0.1/css/wuala_style-all.min.css",
50-
"name": "wuala_style-all.min.css"
79+
"size": "47.9 KB"
5180
}
52-
}
81+
},
82+
"size": "-"
5383
},
5484
"img": {
5585
"isDir": true,
86+
"kind": "folder",
87+
"mDate": "2014-06-23 13:54:56",
5688
"name": "img",
5789
"subFolder": {
5890
"Folder.svg": {
5991
"isDir": false,
92+
"kind": "svg",
93+
"mDate": "2014-06-23 13:54:56",
94+
"name": "Folder.svg",
6095
"url": "http://127.0.0.1/img/Folder.svg",
61-
"name": "Folder.svg"
96+
"size": "1.0 KB"
6297
},
6398
"Files.svg": {
6499
"isDir": false,
100+
"kind": "svg",
101+
"mDate": "2014-06-23 13:54:56",
102+
"name": "Files.svg",
65103
"url": "http://127.0.0.1/img/Files.svg",
66-
"name": "Files.svg"
104+
"size": "2.1 KB"
67105
}
68-
}
106+
},
107+
"size": "-"
69108
},
70109
"js": {
71110
"isDir": true,
111+
"kind": "folder",
112+
"mDate": "2014-06-23 16:27:31",
72113
"name": "js",
73114
"subFolder": {
74115
"jquery-1.11.1.min.js": {
75116
"isDir": false,
117+
"kind": "js",
118+
"mDate": "2014-06-23 13:54:56",
119+
"name": "jquery-1.11.1.min.js",
76120
"url": "http://127.0.0.1/js/jquery-1.11.1.min.js",
77-
"name": "jquery-1.11.1.min.js"
121+
"size": "93.5 KB"
78122
},
79123
"wuala_theme.js": {
80124
"isDir": false,
125+
"kind": "js",
126+
"mDate": "2014-06-23 16:27:31",
127+
"name": "wuala_theme.js",
81128
"url": "http://127.0.0.1/js/wuala_theme.js",
82-
"name": "wuala_theme.js"
129+
"size": "7.5 KB"
83130
},
84131
"jquery-1.11.1.js": {
85132
"isDir": false,
133+
"kind": "js",
134+
"mDate": "2014-06-23 13:54:56",
135+
"name": "jquery-1.11.1.js",
86136
"url": "http://127.0.0.1/js/jquery-1.11.1.js",
87-
"name": "jquery-1.11.1.js"
137+
"size": "276.1 KB"
88138
},
89139
"main.js": {
90140
"isDir": false,
141+
"kind": "js",
142+
"mDate": "2014-06-23 14:34:08",
143+
"name": "main.js",
91144
"url": "http://127.0.0.1/js/main.js",
92-
"name": "main.js"
145+
"size": "4.6 KB"
93146
}
94-
}
147+
},
148+
"size": "-"
149+
},
150+
"README.md": {
151+
"isDir": false,
152+
"kind": "md",
153+
"mDate": "2014-06-23 15:29:54",
154+
"name": "README.md",
155+
"url": "http://127.0.0.1/README.md",
156+
"size": "308 B"
157+
},
158+
"LICENSE": {
159+
"isDir": false,
160+
"kind": "",
161+
"mDate": "2014-06-23 15:05:01",
162+
"name": "LICENSE",
163+
"url": "http://127.0.0.1/LICENSE",
164+
"size": "1.0 KB"
95165
},
96166
"browse.json": {
97167
"isDir": false,
168+
"kind": "json",
169+
"mDate": "2014-06-23 16:32:47",
170+
"name": "browse.json",
98171
"url": "http://127.0.0.1/browse.json",
99-
"name": "browse.json"
172+
"size": "5.1 KB"
100173
},
101174
"generator.py": {
102175
"isDir": false,
176+
"kind": "py",
177+
"mDate": "2014-06-23 16:35:44",
178+
"name": "generator.py",
103179
"url": "http://127.0.0.1/generator.py",
104-
"name": "generator.py"
180+
"size": "2.5 KB"
105181
},
106182
"index.html": {
107183
"isDir": false,
184+
"kind": "html",
185+
"mDate": "2014-06-23 14:24:58",
186+
"name": "index.html",
108187
"url": "http://127.0.0.1/index.html",
109-
"name": "index.html"
188+
"size": "601 B"
110189
}
111190
}

generator.py

+76-32
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,81 @@
33
import os
44
import json
55
from collections import OrderedDict
6+
import datetime
7+
8+
TO_NICE_DISPLAY = {
9+
0: 'B',
10+
1: 'KB',
11+
2: 'MB',
12+
3: 'GB',
13+
4: 'TB'
14+
}
15+
16+
17+
def size_to_nice_display(size):
18+
"""
19+
Display size with the correct unit
20+
Works only for stuff < 9999 TB
21+
see http://svn.lacie.com/svn/playground/blegrand/tests/nice_number_display.py
22+
for tests
23+
"""
24+
from math import pow
25+
if -1 == size:
26+
return '-'
27+
division = 0
28+
result_size = size
29+
30+
while ((len(TO_NICE_DISPLAY) - 1) > division) and (1024 <= result_size):
31+
division += 1
32+
result_size = size / (pow(1024, division))
33+
34+
if 0 != division:
35+
# We want to keep at most 1 decimal
36+
result_size = int(result_size * 10)
37+
#We have to recast into float in order to keep the deciman
38+
result_size = float(result_size) / 10
39+
return "%s %s" % (result_size, TO_NICE_DISPLAY[division])
40+
641

742
if __name__ == "__main__":
8-
if 4 != len(sys.argv):
9-
print("usage: %s path_to_browse url_prefix outputFile" % sys.argv[0])
10-
sys.exit(1)
11-
path = sys.argv[1]
12-
13-
if not os.path.isdir(path):
14-
print("Path: %s does not exist", path)
15-
sys.exit(2)
16-
if path[-1] != "/":
17-
path = path + "/"
18-
result_dict = OrderedDict()
19-
for root, dirs, files in os.walk(path):
20-
fakePath = root[len(path):]
21-
currentDictSplitted = fakePath.split("/")
22-
workOn = result_dict
23-
for key in currentDictSplitted:
24-
if 0 != len(key):
25-
workOn = workOn[key]["subFolder"]
26-
for d in dirs:
27-
workOn[d] = {
28-
"isDir": True,
29-
"name": d,
30-
"subFolder": OrderedDict()
31-
}
32-
for f in files:
33-
workOn[f] = {
34-
"isDir": False,
35-
"name": f,
36-
"url": os.path.join(sys.argv[2], fakePath, f)
37-
}
38-
with open(sys.argv[3], "w") as f:
39-
json.dump(result_dict, f, indent=2)
43+
if 4 != len(sys.argv):
44+
print("usage: %s path_to_browse url_prefix outputFile" % sys.argv[0])
45+
sys.exit(1)
46+
path = sys.argv[1]
47+
48+
if not os.path.isdir(path):
49+
print("Path: %s does not exist", path)
50+
sys.exit(2)
51+
if path[-1] != "/":
52+
path = path + "/"
53+
result_dict = OrderedDict()
54+
for root, dirs, files in os.walk(path):
55+
fakePath = root[len(path):]
56+
currentDictSplitted = fakePath.split("/")
57+
workOn = result_dict
58+
for key in currentDictSplitted:
59+
if 0 != len(key):
60+
workOn = workOn[key]["subFolder"]
61+
for d in dirs:
62+
if d.startswith("."):
63+
continue
64+
workOn[d] = {
65+
"isDir": True,
66+
"name": d,
67+
"subFolder": OrderedDict(),
68+
"size": "-",
69+
"kind": "folder",
70+
"mDate": datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root, d))).strftime('%Y-%m-%d %H:%M:%S')
71+
}
72+
dirs[:] = [d for d in dirs if not d.startswith(".")]
73+
for f in files:
74+
workOn[f] = {
75+
"isDir": False,
76+
"name": f,
77+
"url": os.path.join(sys.argv[2], fakePath, f),
78+
"size": size_to_nice_display(os.path.getsize(os.path.join(root, f))),
79+
"kind": os.path.splitext(os.path.join(root, f))[1][1:],
80+
"mDate": datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(root, f))).strftime('%Y-%m-%d %H:%M:%S')
81+
}
82+
with open(sys.argv[3], "w") as f:
83+
json.dump(result_dict, f, indent=2)

js/wuala_theme.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,20 @@ WualaDisplay.prototype.AddElement = function(list, element, displayName, onBrows
183183

184184
//Size
185185
th = document.createElement("td");
186-
th.innerHTML = "-";
186+
th.innerHTML = element.size;
187+
187188
th.className = "hide-for-small";
188189
tr.appendChild(th);
189190

190191
//Mdate
191192
th = document.createElement("td");
192-
th.innerHTML = "-";
193+
th.innerHTML = element.mDate;
193194
th.className = "hide-for-small";
194195
tr.appendChild(th);
195196

196197
//kind
197198
th = document.createElement("td");
198-
th.innerHTML = "-";
199+
th.innerHTML = element.kind;
199200
th.className = "hide-for-small";
200201
tr.appendChild(th);
201202

0 commit comments

Comments
 (0)