Repository navigation
save original uploads of icons and previews too - #7586
Conversation
EnTeQuAk
left a comment
There was a problem hiding this comment.
r+wc
That's really great and looks good to me. Most comments are really just nits imho
|
|
||
| def resize_image(src, dst, size=None, remove_src=True, locally=False): | ||
| """Resizes and image from src, to dst. Returns width and height. | ||
| def resize_image(src, dst, size=None): |
There was a problem hiding this comment.
this is really just a nit… but I hate 3-char "words", can't we just name them source and destination (or target if it has to be shorter) maybe? Note that this might pull through the whole system so this is just me thinking loud without any need to change the current state :)
| delete = os.unlink if locally else storage.delete | ||
|
|
||
| with open_(src, 'rb') as fp: | ||
| with storage.open(src, 'rb') as fp: |
| resize_image(src, dst, (size, size), remove_src=True, | ||
| locally=locally) | ||
| dest_file = None | ||
| for s in sizes: |
There was a problem hiding this comment.
pep08 hates one-character names, let's maybe call sizes target_sizes instead and name s as size?
| @task | ||
| @set_modified_on | ||
| def resize_icon(src, dst, size, locally=False, **kw): | ||
| def resize_icon(src, dest_folder, sizes, **kw): |
There was a problem hiding this comment.
kudos to bravely renaming size to sizes 🗡
| resize_size = [resize_size] | ||
| uploadto = user_media_path('addon_icons') | ||
| try: | ||
| os.makedirs(uploadto) |
There was a problem hiding this comment.
This should really move to pytest but I see that it's copied so this can be a follow-up
There was a problem hiding this comment.
this is in a test already... or what do you mean by move to pytest?
There was a problem hiding this comment.
Eh, yeah, I meant this should be moved to conftest.py to pregenerate those folders for our test-suite
There was a problem hiding this comment.
going to leave this to a follow-up because it's a bit more messy to refactor.
| os.makedirs(uploadto) | ||
| except OSError: | ||
| pass | ||
| for rsize, fsize in zip(resize_size, final_size): |
There was a problem hiding this comment.
can we rename fsize expected_size instead since that's what we're testing here right? I'm a fan of the assert given_value == expected_value pattern and try to name things appropriately
| assert not os.path.exists(dest_image) | ||
| os.remove(orig_image) | ||
| assert not os.path.exists(orig_image) | ||
| shutil.rmtree(uploadto) |
There was a problem hiding this comment.
I'm glad I recently fixed pytest tmp-folder behavior and it now is much more compatible for our multi-processing usage 😆 I don't want to know what else our tests create / remove
fixes mozilla/addons#5131. I was tempted to include a fix for mozilla/addons#4510 and look at some other related issues like mozilla/addons#3095, mozilla/addons#1751, mozilla/addons#221 but we can look into as follow-ups