-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
55 lines (47 loc) · 1.14 KB
/
index.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
#-*- coding:utf-8 -*-
import web
import json
import sys
import os
from fontTools import subset
from bae.core.wsgi import WSGIApplication
urls = (
'/(.*)', 'generate'
)
BUF_SIZE = 262144
#app_root = os.path.dirname(_file_)
#sys.path.insert(0, app_root)
#templates_root = os.path.join(app_root, 'templates')
#render = web.template.render(templates_root)
app = web.application(urls, globals()).wsgifunc()
class generate:
def GET(self, name):
#data = json.loads(web.data())
name = "fangzheng.TTF"
data = "--text=我们"
arg = [name,data]
#fontTools.subset.main(arg)
subset.main(arg)
outputFile = "/tmp/" + name + ".subset"
if (os.path.isfile(outputFile)):
try:
f = open(outputFile, "rb")
web.header('Content-Type','application/octet-stream')
web.header('Content-disposition','attachment; filename=%s.dat' % outputFile)
while True:
c = f.read(BUF_SIZE)
if c:
yield c
else:
break
except Exception, e:
yield e
#yield 'Error when read font file'
finally:
if f:
f.close()
#return "success"
#else:
#return "fail"
#return "yes"
application = WSGIApplication(app)