Commit graph

604 commits

Author SHA1 Message Date
Alex Pyrgiotis
43617366a5
Update poetry.lock
Run `poetry update` to update the `poetry.lock` file to the latest
version.
2022-11-07 11:46:41 +02:00
deeplow
b1892077fa
Add fedora 37 support in CI
Fedora 37 had been removed (commit d7cbe41) due to lack of support by
packagecloud (our package hosting solution at the time). This will no
longer be true and thus we can add this distro to the list of supported.
2022-10-27 14:53:17 +01:00
deeplow
52bd7b3033
Add long description to setup.py
Building stdeb on bookworm is failing [1] on a missing long_description:

    File "/usr/lib/python3/dist-packages/stdeb/util.py", line 934, in __init__
        for line in long_description.split('\n'):
    AttributeError: 'NoneType' object has no attribute 'split'

[1]: https://app.circleci.com/pipelines/github/freedomofpress/dangerzone/484/workflows/38c579d5-b335-49ab-b56d-9539d93ef16e/jobs/2110
2022-10-27 14:49:25 +01:00
deeplow
77c7cba563
Add support for Debian Bookworm
Fixes #172
2022-10-27 14:49:23 +01:00
Alex Pyrgiotis
a14b4e9620
Fix a minor typo 2022-10-27 13:44:18 +01:00
deeplow
649e427486
Make DangerzoneGui a subclass of DangerzoneCore
Simplify state sharing by having all dangerzone core logic in one
single class instead of two.
2022-10-27 13:44:16 +01:00
deeplow
dca290fb6b
Rename gui.common.GuiCommon class to gui.logic.DangerzoneGui
Rename the `gui.common` module and `gui.common.GuiCommon` class
to `gui.logic` and `gui.logic.DangerzoneGui` respectively. We keep as is
the original names of the variables that hold instances of this class,
since they will change in subsequent commits.

This change is part of the initial refactor to make the DangerzoneGui
class handle the GUI logic of the Dangerzone project.
2022-10-27 13:44:15 +01:00
deeplow
cb8130042e
Rename global_common.GlobalCommon class to logic.Dangerzone
Rename the `global_common` module and `global_common.GlobalCommon` class
to `logic` and `logic.Dangerzone` respectively. Also rename variables
that hold instances of this class.

This change is part of the initial refactor to make the Dangerzone class
handle the core logic of the Dangerzone project.
2022-10-27 13:44:13 +01:00
deeplow
2bed3c10e4
Move safe PDF naming logic to document.py
Let the Document class suggest the default filename for the safe PDF,
based on the provided input filename, appended with the extension
`-safe.pdf`.

Previously, this logic was copy-pasted throughout the code, which made
it difficult to maintain.
2022-10-27 13:44:12 +01:00
deeplow
7aa08457bd
Always resolve relative paths in Document class
Make the Document class always resolve relative input/output file paths,
which are usually passed as arguments by users.

Previously, resolving relative filepaths was a job left to the
instantiators of the Document class. This was error-prone since this
conversion must happen in all the places where we instantiated the
Document class.
2022-10-27 13:44:11 +01:00
deeplow
be5a942a73
Add unit tests for document.py 2022-10-27 13:44:09 +01:00
Alex Pyrgiotis
a068770ab4
Validate filename arguments through Click
Implement Click's callback interface and create validators for the
input/output filenames, using the logic from the Document class. This
way, we can catch user errors as early as possible.
2022-10-27 13:44:08 +01:00
deeplow
db17bd0915
Validate I/O filenames in Document class
Factor out the filename validation logic and move it into the Document
class. Previously, the filename validation logic was scattered across
the CLI and GUI code.

Also, introduce a new errors.py module whose purpose is to handle
document-related errors, by providing:

* A special exception for them (DocumentFilenameExcpetion)
* A decorator that handles DocumentFilenameException, logs it and the
  underlying cause, and exits the program gracefully.
2022-10-27 13:44:06 +01:00
deeplow
e8b56627c9
Rename select_document() function to new_window()
Rename select_document() to new_window() to better encapsulate the fact
that this function is opening a new Dangerzone window.
2022-10-27 13:44:04 +01:00
deeplow
e487b7f0a9
Instantiate documents with a filename
Avoid setting document's filename via document.filename and instead
do it via object instantiation where possible.

Incidentally this has to change some window logic. When
select_document() is called it no longer checks if there is already an
open window with no document selected yet. The user can open as many
windows with unselected documents as they want.
2022-10-27 13:44:03 +01:00
deeplow
0493aca036
Rename common.Common class to document.Document
Rename the `common` module and `common.Common` class to `document` and
`document.Document` respectively. Also, rename the variables that hold
instances of this class.

This change reflects the fact that the class is responsible for tracking
the state of the document. When we add bulk document conversion,
allowing us to keep track of a document's state will be key. This name
change is a step towards that.
2022-10-27 13:44:01 +01:00
Alex Pyrgiotis
03c3541bdc
tests: Run Mypy against tests
Run Mypy static checks against our tests. This brings them inline with
the rest of the codebase, and we have an extra level of certainty that
the tests (and unit tests in particular) will not significantly diverge
from the code they are testing.
2022-10-25 19:09:23 +03:00
Alex Pyrgiotis
2279d48807
tests: Fix a Windows-only test 2022-10-25 19:09:23 +03:00
Alex Pyrgiotis
7d218e5522
tests: Fix path separator issues on Windows
Concatenate directories and filenames in a platform-independent way, by
using pathlib.Path. This fixes issues in the tests where the "/" path
separator made the tests fail on Windows.
2022-10-25 19:09:22 +03:00
Alex Pyrgiotis
ae67dfa5a9
tests: Test filenames with spaces in them
Add two tests that check if Dangerzone properly handles input and output
filenames with spaces in them. Previously this was not straight-forward
because we didn't tokenize arguments, which lead to Click splitting
filenames with spaces in two.
2022-10-25 19:09:22 +03:00
Alex Pyrgiotis
51d4fb04c8
tests: Tokenize CLI arguments
Pass tokenized arguments (i.e., arguments as lists of strings) to CLI
invocations, else Click will attempt to tokenize them internally. The
problem with leaving tokenization to Click is that it uses
`shlex.split()`, which is Unix-oriented, and may miss some cases in
Windows.
2022-10-25 19:09:22 +03:00
Alex Pyrgiotis
6b7797639c
tests: Wrap Click results with extra functionality
Wrap Click results (`Result`) with a new class (`CLIResult`), which
includes:

1. Assertion statements.
2. Logic for formatting and printing a Click result.
3. Invocation arguments, which are missing from the original `Result`
   class.
2022-10-25 19:09:17 +03:00
deeplow
a6c2b943f4
document new windows dev dep.: MS Visual C++ >= 14
On a windows system when running `pip install` it fails to install
`cx_Logging-3.0` with the error:

    error: Microsoft Visual C++ 14.0 or greater is required. Get it
    with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

Installing this dependency solves the issue.
2022-10-25 10:23:02 +01:00
Guthrie McAfee Armstrong
e552411db2
Support Python 3.10
PySide2 5.15.2.1 added support for Python 3.10
2022-10-25 10:23:00 +01:00
deeplow
225cb2b1d2
Merge pull request #203 from origin/166-static-methods
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
2022-09-15 15:19:10 +01:00
deeplow
aecacee315
fix return type for container.install()
Note: the container installation failure is not addressed here. See
https://github.com/freedomofpress/dangerzone/issues/193
2022-09-15 13:26:05 +01:00
deeplow
82ac22e837
remove hardcoded 'docker' logging reference
Closes #122 as this was the last remaining hardcoded docker
reference where the code also applied to podman.
2022-09-15 12:17:22 +01:00
deeplow
57e455bbf1
remove "container" from container.py method names
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()
2022-09-15 12:09:38 +01:00
deeplow
6202c0dba9
deduplicate container-tech-checking logic
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
2022-09-15 12:09:37 +01:00
deeplow
a822870853
move global_common container logic to container.py
Container-specific methods in global_common class were basically
static methods. So it made sense to move these to container.py
2022-09-15 12:09:34 +01:00
deeplow
272281a29e
move to util: get_subprocess_startupinfo 2022-09-15 10:40:36 +01:00
deeplow
2d6826afa9
move ocr_languages from global_common to share/
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.
2022-09-15 10:40:34 +01:00
deeplow
c0f0e7bf6a
move banner() code to cli & version() to util
- 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.
2022-09-15 10:40:31 +01:00
deeplow
ce57fc0449
move get_resource_path to util.py
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
2022-09-15 09:24:11 +01:00
deeplow
0f4e6e9156
create non-ascii filename test cases dynamically instead of static PDF
originally PDF files were included for these edge-cases but in
reality all we want to test is the filename itself. So it reduces
repo size if we have them generated dynamically.
2022-09-13 13:38:33 +01:00
deeplow
d5eefeab3d
report non-containerized code coverage 2022-09-13 13:17:22 +01:00
deeplow
01a5e3b7ca
fix type hints for gui-common (CI would fail)
CI fails: https://app.circleci.com/pipelines/github/freedomofpress/dangerzone/397/workflows/cba836ed-98df-41f8-8f34-abcde5a8c015/jobs/1538
2022-09-13 13:17:20 +01:00
deeplow
75fe45cfb6
replace automated test code in CI 2022-09-13 13:17:15 +01:00
deeplow
9e3d404ed8
make test: add to Makefile & enabled parallel runs
parallel pytest via pytest-xdist
2022-09-13 13:08:01 +01:00
deeplow
d3f478b17f
migrate to pytest & test_docs -> tests/test_docs
Use pytest instead of unittest to have greater flexibility in test
parametrization.
2022-09-13 13:07:58 +01:00
deeplow
4251d824ab
add pytest dep. for testing
The parameterizatin features of pytest over the default unittest
will be useful to reduce test code. Furthermore, pytest is already
used by folks at FPF so there won't be any learning curve if folks
want to work on it.
2022-09-13 13:07:15 +01:00
deeplow
f10446c309
make dz-cli exit(1) when it fails
Otherwise the failure cannot be detected easily by the calling
tests.
2022-09-13 13:07:13 +01:00
deeplow
84acf116c7
remove non-implemented tests
Since we're not doing test-drive-development, we should not have
tests for unimplemented features.
2022-09-13 13:07:12 +01:00
deeplow
377665c459
move tests to project root 2022-09-13 13:07:10 +01:00
Guthrie McAfee Armstrong
36d96ccb5c
Add unit tests 2022-09-13 13:06:59 +01:00
deeplow
e923c5a803
Merge pull request #200 from freedomofpress/missing-0.3.2-changelog 2022-09-12 08:41:21 +01:00
deeplow
20679c3159
Add missing entry in 0.3.2 changelog
The issue https://github.com/freedomofpress/dangerzone/pull/197 ended up being added in the release but had not been updated in the changelog.
2022-09-07 05:46:48 -04:00
Micah Lee
d7cbe419cc
Comment out deploying to fedora 37, because packagecloud.io does not support it yet 2022-09-06 10:43:18 -07:00
Micah Lee
5dd23d13f4
Update download links to 0.3.2 in readme 2022-09-06 10:27:40 -07:00
Micah Lee
b5249284a4
Merge pull request #197 from freedomofpress/196-container-leakage
remove container after use
2022-09-06 10:20:03 -07:00