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

Reduce "global_common" coupling by moving methods that could be static onto "semantically-closer" py files #203

Merged
merged 9 commits into from
Sep 15, 2022

Conversation

deeplow
Copy link
Contributor

@deeplow deeplow commented Sep 15, 2022

Based on work initially made by @gmarmstrong on #166:

  • moves container-specific code out of global_common.py and into container.py
  • creates a util.py for static methods used through the whole app
  • move banner code from global_common onto cli.py given that it's only displayed there
  • updates tests to reflect these changes
  • move ocr_languages from global_common onto its own json file in share/ocr-languages.json to simplify global_common logic

static methods that are used application-wide should belong to
the utilities python file.

inspired by @gmarmstrong's PR #166 on refactoring global_common
methods to be static and have a dzutil.py
- display_banner() was only displayed in CLI mode so it makes sense
for it to be in the CLI.
- get_version(), was mvoed to util since it is a static function
that is needed in multiple parts of the application.
ocr_languages can be treated as just a json file instead of being
in global_common. This way it is easier to maintain and makes
global_common cleaner.
Container-specific methods in global_common class were basically
static methods. So it made sense to move these to container.py
The logic for detecting if we were are running on docker or podman
and identifying its respective binary were scattered across the
codebase. This centralizes it all in container.py
Container-related methods recently moved to container.py no longer
need to have 'container' in their name as they are within the
container scope already.

Additonally it made it awkward to call from another module:

    from .. import container
    container.get_container_runtime()
Closes #122 as this was the last remaining hardcoded docker
reference where the code also applied to podman.
@deeplow
Copy link
Contributor Author

deeplow commented Sep 15, 2022

@gmarmstrong let me know what you think. I have limited the scope of this PR to moving things out of global common.
The refactor to make static the code in gui_common will be in a future PR.

Copy link
Contributor

@gmarmstrong gmarmstrong left a comment

Choose a reason for hiding this comment

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

Looks great!

dangerzone/container.py Outdated Show resolved Hide resolved
dangerzone/gui/main_window.py Show resolved Hide resolved
dangerzone/cli.py Show resolved Hide resolved
Note: the container installation failure is not addressed here. See
#193
@deeplow
Copy link
Contributor Author

deeplow commented Sep 15, 2022

Thanks for the review @gmarmstrong!

@deeplow deeplow merged commit aecacee into main Sep 15, 2022
deeplow added a commit that referenced this pull request Sep 15, 2022
Reduce "global_common" coupling by moving methods that could be
static onto "semantically-closer" py files.

Based on work initially made by @gmarmstrong on PR #166:

  - moves container-specific code out of global_common.py and into
    container.py
  - creates a util.py for static methods used through the whole app
  - move banner code from global_common onto cli.py given that it's
    only displayed there
  - updates tests to reflect these changes
  - move ocr_languages from global_common onto its own json file in
    share/ocr-languages.json to simplify global_common logic
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.

2 participants