Skip to content

Commit

Permalink
in-memory input files passed to check-ttf
Browse files Browse the repository at this point in the history
lots of capabilities are restricted on google app engine though, so I had to disable them when running as a webapp.
(issue fonttools#1121)
  • Loading branch information
felipesanches committed Oct 25, 2016
1 parent 16134d4 commit 444d098
Show file tree
Hide file tree
Showing 8 changed files with 888 additions and 847 deletions.
1,614 changes: 834 additions & 780 deletions fontbakery-check-ttf.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
beautifulsoup4==4.5.1
bs4==0.0.1
defusedxml==0.4.1
fontaine==1.3.12
#fontaine==1.3.12
fonttools==3.0
lxml==3.4.2
lxml==3.5.0
protobuf==3.0.0
PyICU==1.9.3
python-magic==0.4.12
Expand All @@ -12,4 +12,4 @@ six==1.10.0
tabulate==0.7.5
Unidecode==0.4.19
wheel==0.24.0
GitPython==0.3.2rc1
GitPython==0.3.2rc1
15 changes: 0 additions & 15 deletions test_inmem_check_ttf.py

This file was deleted.

5 changes: 5 additions & 0 deletions webapp/app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ handlers:
static_dir: static/js
- url: /runchecks
script: main.app

libraries:
- name: lxml
version: latest

1 change: 1 addition & 0 deletions webapp/app/fbCheckTTF.py
1 change: 1 addition & 0 deletions webapp/app/fonts_public_pb2.py
92 changes: 43 additions & 49 deletions webapp/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,59 @@
import json
import zipfile
app = Flask(__name__)

check_ttf = __import__("fbCheckTTF").fontbakery_check_ttf

def _unpack(stream):
# L = unsignedlong 4 bytes
while True:
head = stream.read(8)
if not head:
break
jsonlen, fontlen = struct.unpack('II', head)
desc = json.loads(stream.read(jsonlen).decode('utf-8'))
font = TTFont(BytesIO(stream.read(fontlen)))
yield (desc, font)

def check_font(desc, font):
#familyName = desc['familyName']
#weightName = desc['weightName']
#isItalic = desc['isItalic']
#version = desc['version']
#vendorID = desc['vendorID']

print("Checking '{}'...".format(desc))

#TODO: invoke FB here!
return

# L = unsignedlong 4 bytes
while True:
head = stream.read(8)
if not head:
break
jsonlen, fontlen = struct.unpack('II', head)
desc = json.loads(stream.read(jsonlen).decode('utf-8'))
font = TTFont(BytesIO(stream.read(fontlen)))
yield (desc, font)

@app.route('/runchecks', methods=['POST'])
def run_fontbakery():
hotfixing = False # TODO: let the user choose.
hotfixing = False # TODO: let the user choose.

if hotfixing:
result = BytesIO()
zipf = zipfile.ZipFile(result, "w")

if hotfixing:
result = BytesIO()
zipf = zipfile.ZipFile(result, "w")
config = {
'verbose': True,
'ghm': True,
'json': False,
'error': False,
'autofix': False,
'inmem': True,
'filepaths': None,
'files': _unpack(request.stream)
}

i=0
for desc, font in _unpack(request.stream):
i += 1
check_font(desc, font)
filename = desc['filename']
print('checked', filename)
check_ttf(config)

if hotfixing:
# write the font file to the zip
fontIO = BytesIO()
font.save(fontIO)
fontData = fontIO.getvalue()
zipf.writestr(filename, fontData)
# TODO:
# if hotfixing:
# # write the font file to the zip
# fontIO = BytesIO()
# font.save(fontIO)
# fontData = fontIO.getvalue()
# zipf.writestr(filename, fontData)

if hotfixing:
zipf.close()
data = result.getvalue()
response = make_response(data)
response.headers['Content-Type'] = 'application/octet-stream'
response.headers['Content-Disposition'] = 'attachment; filename=fonts-with-changed-names.zip'
else:
response = make_response("Fontbakery check results will show up here!")
response.headers['Content-Type'] = 'text/html'
if hotfixing:
zipf.close()
data = result.getvalue()
response = make_response(data)
response.headers['Content-Type'] = 'application/octet-stream'
response.headers['Content-Disposition'] = 'attachment; filename=fonts-with-changed-names.zip'
else:
response = make_response("Fontbakery check results will show up here!")
response.headers['Content-Type'] = 'text/html'

return response
return response

@app.errorhandler(500)
def server_error(e):
Expand Down
1 change: 1 addition & 0 deletions webapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
fonttools
gcloud

0 comments on commit 444d098

Please sign in to comment.