-
Notifications
You must be signed in to change notification settings - Fork 184
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
Refactor ./container/dangerzone.py #167
Conversation
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.
Overall, I think this is a great refactor, simplifying a lot of stuff. Thanks a lot for your contribution!
I have made some suggestions.
Hi @gmarmstrong. Would you have the time to address this review feedback I gave a while ago? (It should be pretty minor) |
Thanks! Now I think you're only missing catching that |
Should be good now! Do double-check that it works, of course. |
Awesome! I am just going to do some final testing tomorrow but all looks great. Thanks! I may do a rebase prior to merging, OK? |
Go for it! |
cdfef25
to
097fe7d
Compare
Rebased, tested on a Linux and Windows system and made lint happy. |
Nice, giving it a look as well. |
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.
Did a quick check, and I have some minor comments. Other than that, this is a great improvement to the codebase.
run_command( | ||
[ | ||
"gm", | ||
"convert", | ||
"-size", | ||
f"{width}x{height}", | ||
"-depth", | ||
"8", | ||
f"rgb:{rgb_filename}", | ||
f"pdf:{pdf_filename}", | ||
], | ||
error_message=f"Page {page}/{num_pages} conversion to PDF failed", | ||
timeout_message=f"Error converting RGB to PDF, convert timed out after {DEFAULT_TIMEOUT} seconds", | ||
) |
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.
We define the same gm
command twice, regardless of whether we want OCR or not. Shouldn't we factor it out?
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.
Almost the same, but not exactly the same. The first is from RGB to PNG, the second is from RGB to PDF.
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.
Oh, you're right, thanks for pointing it out. Still, I think we can do the factoring out (e.g., gm_convert_to()
, and add the target file type and filename as arguments to that command).
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.
I see your point, although gm convert
is also used (very differently) in the document_to_pixels
function, so that function should be named gm_convert_pixels_to
. Alternatively, it could be a nested function, but that could be counterproductive to readability.
Since the duplicate code wasn't introduced in this PR, I think it would be better to address it in a later PR. This one introduces the run_command
function, which shrank the two gm convert
steps considerably already.
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.
Sure, makes sense. We're good to go then!
@deeplow do you want to merge this, or should I go ahead?
Thanks @apyrgio, I'll take a look this weekend. |
Standardize calls to subprocess.run to shrink file by about 100 lines
Co-authored-by: deeplow <[email protected]>
Co-authored-by: deeplow <[email protected]>
Co-authored-by: deeplow <[email protected]>
Co-authored-by: deeplow <[email protected]>
2566445
to
2085405
Compare
Rebased and merged. Thanks again @gmarmstrong and sorry that this took so long. |
Cleans up the container script by consolidating all calls to
subprocess.run
to a single function. Shrinkscontainer/dangerzone.py
from 541 lines to 397 total.Everything (except
__main__
itself) has been refactored to raise exceptions instead of returning an integer. Intended to cause no noticeable changes to program behavior.