|
@@ -1,5 +1,6 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
|
|
3
|
+import sys
|
3
|
4
|
import re
|
4
|
5
|
import itertools
|
5
|
6
|
import email.utils
|
|
@@ -7,11 +8,26 @@ import os.path
|
7
|
8
|
import time
|
8
|
9
|
import codecs
|
9
|
10
|
from datetime import datetime
|
10
|
|
-import urlparse
|
11
|
11
|
|
12
|
12
|
DEFAULT_LANG = "en"
|
13
|
13
|
BASE_URL = "https://www.xythobuz.de"
|
14
|
14
|
|
|
15
|
+# =============================================================================
|
|
16
|
+# Python 2/3 hacks
|
|
17
|
+# =============================================================================
|
|
18
|
+
|
|
19
|
+PY3 = sys.version_info[0] == 3
|
|
20
|
+
|
|
21
|
+if PY3:
|
|
22
|
+ import urllib
|
|
23
|
+ import urllib.request
|
|
24
|
+ def urlparse_foo(link):
|
|
25
|
+ return urllib.parse.parse_qs(urllib.parse.urlparse(link).query)['v'][0]
|
|
26
|
+else:
|
|
27
|
+ import urlparse
|
|
28
|
+ def urlparse_foo(link):
|
|
29
|
+ return urlparse.parse_qs(urlparse.urlparse(link).query)['v'][0]
|
|
30
|
+
|
15
|
31
|
# -----------------------------------------------------------------------------
|
16
|
32
|
# sub page helper macro
|
17
|
33
|
# -----------------------------------------------------------------------------
|
|
@@ -30,24 +46,24 @@ def backToParent():
|
30
|
46
|
# print if any parent link found
|
31
|
47
|
if len(posts) > 0:
|
32
|
48
|
p = posts[0]
|
33
|
|
- print '<span class="listdesc">[...back to ' + p.title + ' overview](' + p.url + ')</span>'
|
|
49
|
+ print('<span class="listdesc">[...back to ' + p.title + ' overview](' + p.url + ')</span>')
|
34
|
50
|
|
35
|
51
|
# -----------------------------------------------------------------------------
|
36
|
52
|
# table helper macro
|
37
|
53
|
# -----------------------------------------------------------------------------
|
38
|
54
|
|
39
|
55
|
def tableHelper(style, header, content):
|
40
|
|
- print "<table>"
|
|
56
|
+ print("<table>")
|
41
|
57
|
if (header != None) and (len(header) == len(style)):
|
42
|
|
- print "<tr>"
|
|
58
|
+ print("<tr>")
|
43
|
59
|
for h in header:
|
44
|
|
- print "<th>" + h + "</th>"
|
45
|
|
- print "</tr>"
|
|
60
|
+ print("<th>" + h + "</th>")
|
|
61
|
+ print("</tr>")
|
46
|
62
|
for ci in range(0, len(content)):
|
47
|
63
|
if len(content[ci]) != len(style):
|
48
|
64
|
# invalid call of table helper!
|
49
|
65
|
continue
|
50
|
|
- print "<tr>"
|
|
66
|
+ print("<tr>")
|
51
|
67
|
for i in range(0, len(style)):
|
52
|
68
|
s = style[i]
|
53
|
69
|
td_style = ""
|
|
@@ -70,17 +86,17 @@ def tableHelper(style, header, content):
|
70
|
86
|
if td_style != "":
|
71
|
87
|
td_args = " style=\"" + td_style + "\""
|
72
|
88
|
|
73
|
|
- print "<td" + td_args + ">"
|
|
89
|
+ print("<td" + td_args + ">")
|
74
|
90
|
|
75
|
91
|
if isinstance(content[ci][i], tuple):
|
76
|
92
|
text, link = content[ci][i]
|
77
|
|
- print "<a href=\"" + link + "\">" + text + "</a>"
|
|
93
|
+ print("<a href=\"" + link + "\">" + text + "</a>")
|
78
|
94
|
else:
|
79
|
95
|
text = content[ci][i]
|
80
|
|
- print text
|
81
|
|
- print "</td>"
|
82
|
|
- print "</tr>"
|
83
|
|
- print "</table>"
|
|
96
|
+ print(text)
|
|
97
|
+ print("</td>")
|
|
98
|
+ print("</tr>")
|
|
99
|
+ print("</table>")
|
84
|
100
|
|
85
|
101
|
# -----------------------------------------------------------------------------
|
86
|
102
|
# menu helper macro
|
|
@@ -112,7 +128,7 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
|
112
|
128
|
if year != lastyear:
|
113
|
129
|
lastyear = year
|
114
|
130
|
if yearsAsHeading:
|
115
|
|
- print "\n\n#### %s\n" % (year)
|
|
131
|
+ print("\n\n#### %s\n" % (year))
|
116
|
132
|
|
117
|
133
|
dateto = ""
|
118
|
134
|
if p.get("date", "" != ""):
|
|
@@ -127,19 +143,19 @@ def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStart
|
127
|
143
|
if nicelyFormatFullDate:
|
128
|
144
|
dateto = " - " + datetime.strptime(p.get("update", p.date), "%Y-%m-%d").strftime("%B %d, %Y")
|
129
|
145
|
|
130
|
|
- print " * **[%s](%s)**%s" % (title, p.url, dateto)
|
|
146
|
+ print(" * **[%s](%s)**%s" % (title, p.url, dateto))
|
131
|
147
|
|
132
|
148
|
if p.get("description", "") != "":
|
133
|
149
|
description = p.get("description", "")
|
134
|
150
|
if lang != "":
|
135
|
151
|
if p.get("description_" + lang, "") != "":
|
136
|
152
|
description = p.get("description_" + lang, "")
|
137
|
|
- print "<br><span class=\"listdesc\">" + description + "</span>"
|
|
153
|
+ print("<br><span class=\"listdesc\">" + description + "</span>")
|
138
|
154
|
|
139
|
155
|
if showLastCommit:
|
140
|
156
|
link = githubCommitBadge(p)
|
141
|
157
|
if len(link) > 0:
|
142
|
|
- print "<br>" + link
|
|
158
|
+ print("<br>" + link)
|
143
|
159
|
|
144
|
160
|
return lastyear
|
145
|
161
|
|
|
@@ -318,14 +334,14 @@ def lightgallery(links):
|
318
|
334
|
for v in videos:
|
319
|
335
|
link, mime, thumb, poster, alt = v
|
320
|
336
|
v_i += 1
|
321
|
|
- print '<div style="display:none;" id="video' + str(v_i) + '_' + str(v_ii) + '">'
|
322
|
|
- print '<video class="lg-video-object lg-html5" controls preload="none">'
|
323
|
|
- print '<source src="' + link + '" type="' + mime + '">'
|
324
|
|
- print '<a href="' + link + '">' + alt + '</a>'
|
325
|
|
- print '</video>'
|
326
|
|
- print '</div>'
|
|
337
|
+ print('<div style="display:none;" id="video' + str(v_i) + '_' + str(v_ii) + '">')
|
|
338
|
+ print('<video class="lg-video-object lg-html5" controls preload="none">')
|
|
339
|
+ print('<source src="' + link + '" type="' + mime + '">')
|
|
340
|
+ print('<a href="' + link + '">' + alt + '</a>')
|
|
341
|
+ print('</video>')
|
|
342
|
+ print('</div>')
|
327
|
343
|
|
328
|
|
- print '<div class="lightgallery">'
|
|
344
|
+ print('<div class="lightgallery">')
|
329
|
345
|
v_i = -1
|
330
|
346
|
for l in links:
|
331
|
347
|
if (len(l) == 3) or (len(l) == 2):
|
|
@@ -337,7 +353,7 @@ def lightgallery(links):
|
337
|
353
|
link, alt = l
|
338
|
354
|
if "youtube.com" in link:
|
339
|
355
|
img = "https://img.youtube.com/vi/"
|
340
|
|
- img += urlparse.parse_qs(urlparse.urlparse(link).query)['v'][0]
|
|
356
|
+ img += urlparse_foo(link)
|
341
|
357
|
img += "/0.jpg" # full size preview
|
342
|
358
|
#img += "/default.jpg" # default thumbnail
|
343
|
359
|
style = ' style="width:300px;"'
|
|
@@ -346,7 +362,7 @@ def lightgallery(links):
|
346
|
362
|
x = link.rfind('.')
|
347
|
363
|
img = link[:x] + '_small' + link[x:]
|
348
|
364
|
lightgallery_check_thumbnail(link, img)
|
349
|
|
- print '<div class="border" style="position:relative;" data-src="' + link + '"><a href="' + link + '"><img class="pic" src="' + img + '" alt="' + alt + '"' + style + '>' + img2 + '</a></div>'
|
|
365
|
+ print('<div class="border" style="position:relative;" data-src="' + link + '"><a href="' + link + '"><img class="pic" src="' + img + '" alt="' + alt + '"' + style + '>' + img2 + '</a></div>')
|
350
|
366
|
elif len(l) == 5:
|
351
|
367
|
v_i += 1
|
352
|
368
|
link, mime, thumb, poster, alt = videos[v_i]
|
|
@@ -357,19 +373,19 @@ def lightgallery(links):
|
357
|
373
|
x = link.rfind('.')
|
358
|
374
|
poster = link[:x] + '_poster.png'
|
359
|
375
|
lightgallery_check_thumbnail_video(link, thumb, poster)
|
360
|
|
- print '<div class="border" data-poster="' + poster + '" data-sub-html="' + alt + '" data-html="#video' + str(v_i) + '_' + str(v_ii) + '"><a href="' + link + '"><img class="pic" src="' + thumb + '"></a></div>'
|
|
376
|
+ print('<div class="border" data-poster="' + poster + '" data-sub-html="' + alt + '" data-html="#video' + str(v_i) + '_' + str(v_ii) + '"><a href="' + link + '"><img class="pic" src="' + thumb + '"></a></div>')
|
361
|
377
|
else:
|
362
|
378
|
raise NameError('Invalid number of arguments for lightgallery')
|
363
|
|
- print '</div>'
|
|
379
|
+ print('</div>')
|
364
|
380
|
|
365
|
381
|
# -----------------------------------------------------------------------------
|
366
|
382
|
# github helper macros
|
367
|
383
|
# -----------------------------------------------------------------------------
|
368
|
384
|
|
369
|
|
-import urllib, json, sys
|
|
385
|
+import json, sys
|
370
|
386
|
|
371
|
387
|
def restRequest(url):
|
372
|
|
- response = urllib.urlopen(url)
|
|
388
|
+ response = urllib.request.urlopen(url) if PY3 else urllib.urlopen(url)
|
373
|
389
|
if response.getcode() != 200:
|
374
|
390
|
sys.stderr.write("\n")
|
375
|
391
|
sys.stderr.write("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
|
|
@@ -430,11 +446,11 @@ def printLatestRelease(user, repo):
|
430
|
446
|
print("</ul></div>")
|
431
|
447
|
|
432
|
448
|
def include_url(url):
|
433
|
|
- response = urllib.urlopen(url)
|
|
449
|
+ response = urllib.request.urlopen(url) if PY3 else urllib.urlopen(url)
|
434
|
450
|
if response.getcode() != 200:
|
435
|
451
|
raise Exception("invalid response code", response.getcode())
|
436
|
452
|
data = response.read()
|
437
|
|
- print data,
|
|
453
|
+ print(data,)
|
438
|
454
|
|
439
|
455
|
# -----------------------------------------------------------------------------
|
440
|
456
|
# preconvert hooks
|
|
@@ -457,7 +473,7 @@ def hook_preconvert_anotherlang():
|
457
|
473
|
[lang.strip() for lang in text_lang[1::2]], \
|
458
|
474
|
text_lang[::2]))
|
459
|
475
|
|
460
|
|
- for lang, text in text_grouped.iteritems():
|
|
476
|
+ for lang, text in (iter(text_grouped.items()) if PY3 else text_grouped.iteritems()):
|
461
|
477
|
spath = p.fname.split(os.path.sep)
|
462
|
478
|
langs.append(lang)
|
463
|
479
|
|
|
@@ -469,19 +485,19 @@ def hook_preconvert_anotherlang():
|
469
|
485
|
vp = Page(filename, virtual=text)
|
470
|
486
|
# Copy real page attributes to the virtual page
|
471
|
487
|
for attr in p:
|
472
|
|
- if not vp.has_key(attr):
|
|
488
|
+ if not ((attr in vp) if PY3 else vp.has_key(attr)):
|
473
|
489
|
vp[attr] = p[attr]
|
474
|
490
|
# Define a title in the proper language
|
475
|
491
|
vp["title"] = p["title_%s" % lang] \
|
476
|
|
- if p.has_key("title_%s" % lang) \
|
|
492
|
+ if ((("title_%s" % lang) in p) if PY3 else p.has_key("title_%s" % lang)) \
|
477
|
493
|
else p["title"]
|
478
|
494
|
# Keep track of the current lang of the virtual page
|
479
|
495
|
vp["lang"] = lang
|
480
|
496
|
page_vpages[lang] = vp
|
481
|
497
|
|
482
|
498
|
# Each virtual page has to know about its sister vpages
|
483
|
|
- for lang, vpage in page_vpages.iteritems():
|
484
|
|
- vpage["lang_links"] = dict([(l, v["url"]) for l, v in page_vpages.iteritems()])
|
|
499
|
+ for lang, vpage in (iter(page_vpages.items()) if PY3 else page_vpages.iteritems()):
|
|
500
|
+ vpage["lang_links"] = dict([(l, v["url"]) for l, v in (iter(page_vpages.items()) if PY3 else page_vpages.iteritems())])
|
485
|
501
|
vpage["other_lang"] = langs # set other langs and link
|
486
|
502
|
|
487
|
503
|
vpages += page_vpages.values()
|
|
@@ -719,7 +735,7 @@ def hook_postconvert_size():
|
719
|
735
|
else:
|
720
|
736
|
return "<a href=\"%s\">%s</a> (%d Byte)" % (matchobj.group(1), matchobj.group(3), size)
|
721
|
737
|
except:
|
722
|
|
- print "Unable to estimate file size for %s" % matchobj.group(1)
|
|
738
|
+ print("Unable to estimate file size for %s" % matchobj.group(1))
|
723
|
739
|
return '<a href=\"%s\">%s</a>' % (matchobj.group(1), matchobj.group(3))
|
724
|
740
|
_re_url = '<a href=\"([^\"]*?\.(%s))\">(.*?)<\/a>' % file_ext
|
725
|
741
|
for p in pages:
|