"
if (header != None) and (len(header) == len(style)):
print "
"
for h in header:
print "
" + h + "
"
print "
"
for ci in range(0, len(content)):
if len(content[ci]) != len(style):
# invalid call of table helper!
continue
print "
"
for i in range(0, len(style)):
s = style[i]
if "align-last-right" in s:
if ci == (len(content) - 1):
print "
"
else:
if "align-center" in s:
print "
"
else:
print "
"
elif "align-right" in s:
print "
"
elif "align-center" in s:
print "
"
else:
print "
"
if isinstance(content[ci][i], tuple):
text, link = content[ci][i]
print "" + text + ""
else:
text = content[ci][i]
print text
print "
"
print "
"
print "
"
# -----------------------------------------------------------------------------
# menu helper macro
# -----------------------------------------------------------------------------
def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStartDate = False, nicelyFormatFullDate = False, lastyear = "0", lang = ""):
title = p.title
if lang != "":
if p.get("title_" + lang, "") != "":
title = p.get("title_" + lang, "")
if p.title == "Blog":
title = p.post
year = p.get("date", "")[0:4]
if year != lastyear:
lastyear = year
if yearsAsHeading:
print "\n\n#### %s\n" % (year)
dateto = ""
if p.get("date", "" != ""):
year = p.get("date", "")[0:4]
if showOnlyStartDate:
dateto = " (%s)" % (year)
if p.get("update", "") != "" and p.get("update", "")[0:4] != year:
if showDateSpan:
dateto = " (%s - %s)" % (year, p.get("update", "")[0:4])
if nicelyFormatFullDate:
dateto = " - " + datetime.strptime(p.date, "%Y-%m-%d").strftime("%B %d, %Y")
print " * **[%s](%s)**%s" % (title, p.url, dateto)
if p.get("description", "") != "":
description = p.get("description", "")
if lang != "":
if p.get("description_" + lang, "") != "":
description = p.get("description_" + lang, "")
print " " + description + ""
return lastyear
def printRecentMenu(count = 5):
posts = [p for p in pages if "date" in p]
posts.sort(key=lambda p: p.get("date"), reverse=True)
for p in posts[0:count]:
printMenuItem(p, False, False, False, True)
def printBlogMenu():
posts = [p for p in pages if "post" in p]
posts.sort(key=lambda p: p.get("date", "9999-01-01"), reverse=True)
lastyear = "0"
for p in posts:
lastyear = printMenuItem(p, True, False, False, True, lastyear)
def printProjectsMenu():
# prints all pages with parent 'projects' or 'stuff'.
# first the ones without date, sorted by position.
# then afterwards those with date, split by year.
# also supports blog posts with parent.
enpages = [p for p in pages if p.lang == "en"]
dpages = [p for p in enpages if p.get("date", "") == ""]
mpages = [p for p in dpages if any(x in p.get("parent", "") for x in [ 'projects', 'stuff' ])]
mpages.sort(key=lambda p: [int(p.get("position", "999"))])
for p in mpages:
printMenuItem(p)
dpages = [p for p in enpages if p.get("date", "") != ""]
mpages = [p for p in dpages if any(x in p.get("parent", "") for x in [ 'projects', 'stuff' ])]
mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
lastyear = "0"
for p in mpages:
lastyear = printMenuItem(p, True, True, False, False, lastyear)
def print3DPrintingMenu():
mpages = [p for p in pages if p.get("parent", "") == "3d-printing" and p.lang == "en"]
mpages.sort(key=lambda p: int(p["position"]))
for p in mpages:
printMenuItem(p, False, True, True)
def printQuadcopterMenu():
mpages = [p for p in pages if p.get("parent", "") == "quadcopters" and p.lang == "en"]
mpages.sort(key=lambda p: int(p["position"]))
for p in mpages:
printMenuItem(p, False, True, True)
def printQuadcopterRelatedMenu():
mpages = [p for p in pages if p.get("show_in_quadcopters", "false") == "true"]
mpages.sort(key=lambda p: [p.get("date", "9999-01-01")], reverse = True)
for p in mpages:
printMenuItem(p, False, True, True)
def printRobotMenuEnglish():
mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "en"]
mpages.sort(key=lambda p: int(p["position"]))
for p in mpages:
printMenuItem(p)
def printRobotMenuDeutsch():
mpages = [p for p in pages if p.get("parent", "") == "xyrobot" and p.lang == "de"]
mpages.sort(key=lambda p: int(p["position"]))
for p in mpages:
printMenuItem(p, False, False, False, False, "0", "de")
# -----------------------------------------------------------------------------
# lightgallery helper macro
# -----------------------------------------------------------------------------
# call this macro like this
# lightgallery([
# [ "image-link", "description" ],
# [ "image-link", "thumbnail-link", "description" ],
# [ "youtube-link", "thumbnail-link", "description" ],
# [ "video-link", "mime", "thumbnail-link", "image-link", "description" ]
# ])
def lightgallery(links):
videos = [l for l in links if len(l) == 5]
v_i = 0
for v in videos:
link, mime, thumb, poster, alt = v
v_i += 1
print '
'
print ''
print '
'
print '
'
v_i = 0
for l in links:
if (len(l) == 3) or (len(l) == 2):
link = img = alt = ""
if len(l) == 3:
link, img, alt = l
else:
link, alt = l
x = link.rfind('.')
img = link[:x] + '_small' + link[x:]
print '
'
elif len(l) == 5:
v_i += 1
link, mime, thumb, poster, alt = v
print '
'
else:
raise NameError('Invalid number of arguments for lightgallery')
print '
'
# -----------------------------------------------------------------------------
# github helper macros
# -----------------------------------------------------------------------------
import urllib, json
def restRequest(url):
response = urllib.urlopen(url)
data = json.loads(response.read())
return data
def restReleases(user, repo):
s = "https://api.github.com/repos/"
s += user
s += "/"
s += repo
s += "/releases"
return restRequest(s)
def printLatestRelease(user, repo):
repo_url = "https://github.com/" + user + "/" + repo
print("
")
print("Release builds for " + repo + " are available on GitHub. \n")
releases = restReleases(user, repo)
if len(releases) <= 0:
print("No release has been published on GitHub yet.")
print("
")
return
releases.sort(key=lambda x: x["published_at"], reverse=True)
r = releases[0]
release_url = r["html_url"]
print("Latest release of " + repo + ", at the time of this writing: " + r["name"] + " (" + datetime.strptime(r["published_at"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M:%S") + ")\n")
if len(r["assets"]) <= 0:
print(" No release assets have been published on GitHub for that.")
print("")
return
print("
")
print("Release Assets:")
for a in r["assets"]:
size = int(a["size"])
ss = " "
if size >= (1024 * 1024):
ss += "(%.1f MiB)" % (size / (1024.0 * 1024.0))
elif size >= 1024:
ss += "(%d KiB)" % (size // 1024)
else:
ss += "(%d Byte)" % (size)
print("