forked from openSUSE/countdown.o.o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-conf.py
executable file
·112 lines (94 loc) · 2.92 KB
/
render-conf.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Release countdown banner generation script
# by Pascal Bleser <[email protected]>
# Artwork by jimmac
#
import sys
import datetime
import fileinput
from optparse import OptionParser
import os
import subprocess
import tempfile
import shutil
import atexit
#VERSION = 2011
RELEASE_BEGIN = datetime.datetime(2019, 05, 22, 12, 0, 0)
RELEASE_END = datetime.datetime(2019, 05, 22, 0, 0)
VERSION = RELEASE_BEGIN.year
# dimensions are tuples of (width,height,name)
#sizes = [(600,105,"wide"), (400,400,"large"), (256,256,"medium"), (130,130,"small")]
sizes = [(400,400,"large"), (256,256,"medium"), (130,130,"small")]
variants = [ '' ] #, '-terminal' ]
options = None
optionParser = OptionParser(usage="%prog [options] [<output directory>]",
description="render countdown image")
optionParser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
help='be verbose')
(options, args) = optionParser.parse_args(sys.argv)
if len(args) >= 2:
prefix = args[1]
else:
prefix = "../output/conf/%s" % VERSION
pass
nao = datetime.datetime.now()
diff_begin = (RELEASE_BEGIN - nao)
diff_end = (nao - RELEASE_END)
if diff_end.days >= 1:
days = -1
else:
days = diff_begin.days
pass
color = (255, 255, 255, 255)
workdir = None
def on_exit():
if workdir != None and os.path.exists(workdir):
shutil.rmtree(workdir)
pass
pass
atexit.register(on_exit)
workdir = tempfile.mkdtemp(prefix='countdown', suffix='tmp')
if not os.path.exists(prefix):
print "Created output directory %s" % prefix
os.makedirs(prefix)
pass
def render(d, variant):
if d >= 1:
days = "%d" % d
ext = ""
elif d < 0:
days = None
ext = "-done"
else:
days = None
ext = "-outnow"
pass
for size in sizes:
template = "osconf%s%s%s.svg" % (VERSION, variant, ext)
workfile = os.path.join(workdir, "work.svg")
out = open(workfile, "wb")
for line in fileinput.FileInput(template, mode="rb"):
#line = unicode(line)
if days != None:
line = line.replace("@@", days)
pass
out.write(line)
pass
out.close()
outfile = "%s/%s%s.png" % (prefix, size[2], variant)
#inkscape --export-png=foo.png --export-area-page -w 400 -h 400 osconf10_.svg
rc = subprocess.call(["inkscape", "-z", "--export-png=%s" % outfile, "--export-area-page", "-w", str(size[0]), "-h", str(size[1]), workfile])
#rc = subprocess.call(["rsvg-convert", "-w", str(size[0]), "-h", str(size[1]), "-f", "png", "-o", outfile, workfile])
if rc != 0:
print >>sys.stderr, "ERROR: call to inkscape failed for %s" % workfile
pass
pass
if options.verbose:
print "days: %d" % (days)
pass
for variant in variants:
render(days, variant)
pass
# vim: set sw=4 ts=4 et: