Skip to content

save original uploads of icons and previews too - #7586

Merged
eviljeff merged 2 commits into
mozilla:masterfrom
eviljeff:7298-dont-remove-original-images
Feb 16, 2018
Merged

eviljeff merged 2 commits into
mozilla:masterfrom
eviljeff:7298-dont-remove-original-images

Conversation

@eviljeff

@eviljeff eviljeff commented Feb 16, 2018 •

Copy link
Copy Markdown
Member

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

@eviljeff
eviljeff requested a review from EnTeQuAk February 16, 2018 12:05

@EnTeQuAk EnTeQuAk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r+wc

That's really great and looks good to me. Most comments are really just nits imho

Comment thread src/olympia/amo/utils.py Outdated

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 :)

Comment thread src/olympia/amo/utils.py Outdated
delete = os.unlink if locally else storage.delete

with open_(src, 'rb') as fp:
with storage.open(src, 'rb') as fp:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😍

Comment thread src/olympia/devhub/tasks.py Outdated
resize_image(src, dst, (size, size), remove_src=True,
locally=locally)
dest_file = None
for s in sizes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pep08 hates one-character names, let's maybe call sizes target_sizes instead and name s as size?

Comment thread src/olympia/devhub/tasks.py Outdated
@task
@set_modified_on
def resize_icon(src, dst, size, locally=False, **kw):
def resize_icon(src, dest_folder, sizes, **kw):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

kudos to bravely renaming size to sizes 🗡

resize_size = [resize_size]
uploadto = user_media_path('addon_icons')
try:
os.makedirs(uploadto)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should really move to pytest but I see that it's copied so this can be a follow-up

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is in a test already... or what do you mean by move to pytest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eh, yeah, I meant this should be moved to conftest.py to pregenerate those folders for our test-suite

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

going to leave this to a follow-up because it's a bit more messy to refactor.

Comment thread src/olympia/devhub/tests/test_tasks.py Outdated
os.makedirs(uploadto)
except OSError:
pass
for rsize, fsize in zip(resize_size, final_size):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't remove original avatar (and other) images

2 participants