Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing icons #95

Merged
merged 2 commits into from
Feb 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions grip/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from urlparse import urlparse, urljoin
except ImportError:
from urllib.parse import urlparse, urljoin
try:
from urllib import urlretrieve
except:
from urllib.request import urlretrieve
from traceback import format_exc
from flask import (Flask, abort, make_response, render_template, request,
safe_join, send_from_directory, url_for)
Expand Down Expand Up @@ -132,6 +136,10 @@ def render(filename=None):
render_offline, render_wide,
style_urls, styles, favicon)

@app.route(cache_url + '/octicons/octicons/<filename>')
def render_octicon(filename=None):
return send_from_directory(cache_path, filename)

@app.route(cache_url + '/<path:filename>')
def render_cache(filename=None):
return send_from_directory(cache_path, filename)
Expand Down Expand Up @@ -384,9 +392,8 @@ def _cache_contents(style_urls, asset_pattern, asset_pattern_sub, cache_path):

for asset_url in asset_urls:
filename = _cache_filename(asset_url, cache_path)
contents = requests.get(asset_url, verify=False).text
# Write file and show message
_write_file(filename, contents)
# Retrieve file and show message
urlretrieve(asset_url, filename)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this more robust than using requests and writing to a file?

Requests handles things like following redirects for you.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I just read your description.

What was causing the "wrong file size"? Was it requests, or the _write_file? If it's _write_file, that should probably be fixed instead of worked around so that other uses of function don't fail.

print(' * Cached', asset_url, 'in', cache_path)


Expand Down