-
Notifications
You must be signed in to change notification settings - Fork 15
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
Frapell enhancements #398
base: master
Are you sure you want to change the base?
Frapell enhancements #398
Changes from all commits
cd6e944
d3ae6e2
0955591
aea0177
6b2a2d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ progress | |
pytest | ||
pytest-mock | ||
lxml | ||
python-magic |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,25 @@ def replace(tag): | |
logger.warning("Unsupported image with GET args. Won't be included: %s", dsk_url) | ||
return None, None | ||
|
||
# Make sure dsk_url lenght is below filesystem limit | ||
limit = config.IMG_MAX_NAME_LEN | ||
basedir, filename = os.path.split(dsk_url) | ||
name, ext = os.path.splitext(filename) | ||
if len(filename) > limit: | ||
# We cannot simply get the [:limit] part of the name, since we | ||
# cannot know if we will have conflicts with other image names, | ||
# so we'll split the filename into subfolders. | ||
# superbigfilename.png would be super/bigfi/lename.png | ||
logger.debug("Filename too long for %r", dsk_url) | ||
new_split_name = [] | ||
for i in range((len(name)//limit)+1): | ||
new_part = name[i*limit:(i+1)*limit] | ||
new_part.replace('.', '').replace('-', '').replace('/', '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No entiendo el por qué de estos replaces... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. El There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No agreguemos código "por las dudas". Si no podés crear un test en |
||
new_split_name.append(new_part) | ||
new_dir = os.path.join(*new_split_name) | ||
dsk_url = os.path.join(basedir,new_dir) | ||
dsk_url += ext | ||
|
||
logger.debug("web url: %r, dsk_url %r", web_url, dsk_url) | ||
|
||
# Replace the width and height by a querystring in the src of the image | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,11 +130,16 @@ def fetch_html(url): | |
try: | ||
req = urllib.request.Request(url, headers=REQUEST_HEADERS) | ||
resp = urllib.request.urlopen(req, timeout=60) | ||
compressedstream = io.BytesIO(resp.read()) | ||
resp_content = resp.read() | ||
compressedstream = io.BytesIO(resp_content) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¿este cambio para qué es? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Es porque corté el branch de antes que se mergee #397 suponia que luego de mergearse no iba a mostrar el diff, no se por que lo sigue mostrando... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En tu máquina local, contra master, no ves esta parte del diff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fijate que este PR dice que está "outdated contra master", quizás te falta actualizar tu branch, y por eso se sigue viendo acá? |
||
gzipper = gzip.GzipFile(fileobj=compressedstream) | ||
html = gzipper.read().decode('utf-8') | ||
return html | ||
|
||
except gzip.BadGzipFile: | ||
# response content is uncompressed | ||
return resp_content.decode('utf-8') | ||
|
||
except Exception as err: | ||
if isinstance(err, urllib.error.HTTPError) and err.code == 404: | ||
raise FetchingError("Failed with HTTPError 404 on url %r", url) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hay casos donde preguntamos por la imagen y la misma no está?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No debería, pero
mimetype.from_file
levanta una excepción si no encuentra el archivo y tenés que arrancar todo el proceso de nuevo... Me parece mas prudente dejar que termine y después uno decide si la imagen que faltó (y que no debería) amerita empezar la corrida nuevamente.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Te cambio el punto de vista de la pregunta.
Esa imagen siempre está, no vale la pena preguntar si existe. Si esa imagen no está, realmente tenemos un bug en otro lado (fijate de donde se llama a esta función). Entonces, no preguntes si la imagen está, porque estás escondiendo un potencial problema.