Skip to content

Commit

Permalink
Merge pull request #778 from sbrunner/jsonschema-default
Browse files Browse the repository at this point in the history
Use the default from the jsonschema
  • Loading branch information
sbrunner committed Aug 16, 2022
2 parents 34bbc47 + c4b21ab commit a17ad59
Show file tree
Hide file tree
Showing 10 changed files with 1,009 additions and 553 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ the images.

### Add a mask

If your scanner add some margin around the scanned image it will relay case some issue the deskew and the
If your scanner add some margin around the scanned image it will relay case some issue the skew and the
content detection.

To solve that you can add a black and white image named `mask.png` in the root folder and draw in black the
Expand Down
20 changes: 10 additions & 10 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
- **`extension`** _(string)_: The extension of generate image (png or tiff). Default: `png`.
- **`default_args`**: Refer to _#/definitions/args_.
- **`viewer`** _(string)_: The command used to start the viewer. Default: `eog`.
- **`modes`** _(object)_: Customize the modes. Can contain additional properties.
- **`modes`** _(object)_: Customize the modes. Can contain additional properties. Default: `{'adf': {'scanimage_arguments': ['--source=ADF']}, 'double': {'scanimage_arguments': ['--source=ADF'], 'auto_bash': True, 'rotate_even': True}, 'multi': {'scanimage_arguments': ['--batch-prompt']}, 'one': {'scanimage_arguments': ['--batch-count=1']}}`.
- **Additional Properties** _(object)_
- **`scanimage_arguments`** _(array)_: Additional scanimage arguments.
- **Items** _(string)_
- **`auto_bash`** _(boolean)_: Run the ADF in tow step odd and even, needed for scanner that don't support double face.
- **`rotate_even`** _(boolean)_: Rotate the even pages, to use in conjunction with auto_bash.
- **`auto_bash`** _(boolean)_: Run the ADF in tow step odd and even, needed for scanner that don't support double face. Default: `False`.
- **`rotate_even`** _(boolean)_: Rotate the even pages, to use in conjunction with auto_bash. Default: `False`.

## Definitions

Expand All @@ -35,16 +35,16 @@
- **Items** _(integer)_
- **`de_noise_morphology`** _(boolean)_: Apply a morphology operation to remove noise. Default: `True`.
- **`inverse_mask`** _(boolean)_: Inverse the mask. Default: `False`.
- **`de_noise_size`** _(integer)_: The size of the artifact that will be de noise. Default: `20`.
- **`de_noise_size`** _(integer)_: The size of the artifact that will be de noise. Default: `1000`.
- **`de_noise_level`** _(integer)_: The threshold level used in de noise on the blurry image. Default: `220`.
- **`buffer_size`** _(integer)_: The size of the buffer add on the mask. Default: `50 an case of mask, 20 in case of cut`.
- **`buffer_size`** _(integer)_: The size of the buffer add on the mask. Default: `20`.
- **`buffer_level`** _(integer)_: The threshold level used in buffer on the blurry image. Default: `20`.
- **`additional_filename`** _(string)_: An image file used to add on the mask.
- **`args`** _(object)_: Cannot contain additional properties.
- **`level`** _(['boolean', 'integer'])_: true: => do level on 15% - 85% (under 15 % will be black above 85% will be white), false: => 0% - 100%, <number>: => (0 + <number>)% - (100 - number)%.
- **`level`** _(['boolean', 'integer'])_: true: => do level on 15% - 85% (under 15 % will be black above 85% will be white), false: => 0% - 100%, <number>: => (0 + <number>)% - (100 - number)%. Default: `False`.
- **`auto_level`** _(boolean)_: If no level specified, do auto level. Default: `False`.
- **`min_level`** _(number)_: Min level if no level end no auto-level. Default: `15`.
- **`max_level`** _(number)_: Max level if no level end no auto-level. Default: `15`.
- **`max_level`** _(number)_: Max level if no level end no auto-level. Default: `85`.
- **`cut_white`** _(number)_: Set the near white pixels on the image to white. Default: `250`.
- **`cut_black`** _(number)_: Set the near black pixels on the image to black. Default: `0`.
- **`no_crop`** _(boolean)_: Don't do any crop. Default: `False`.
Expand All @@ -53,7 +53,7 @@
- **`dpi`** _(number)_: The DPI used to convert the mm to pixel. Default: `300`.
- **`sharpen`** _(boolean)_: Do the sharpen. Default: `False`.
- **`dither`** _(boolean)_: Do the dither. Default: `False`.
- **`tesseract`** _(boolean)_: Use tesseract to to an OCR on the document. Default: `False`.
- **`tesseract`** _(boolean)_: Use tesseract to to an OCR on the document. Default: `True`.
- **`tesseract_lang`** _(string)_: The used language for tesseract. Default: `fra+eng`.
- **`append_credit_card`** _(boolean)_: Do an assisted split. Default: `False`.
- **`assisted_split`** _(boolean)_: Do an assisted split. Default: `False`.
Expand All @@ -67,7 +67,7 @@
- **`contour_kernel_size_empty`** _(number)_: The block size used in a box on content find if the page is empty [mm]. Default: `1.5`.
- **`threshold_block_size_empty`** _(number)_: The block size used in a box on threshold for content find if the page is empty [mm]. Default: `1.5`.
- **`threshold_value_c_empty`** _(number)_: A variable used on threshold, should be low on low contrast image, used in a box on content find if the page is empty. Default: `70`.
- **`min_box_size_limit`** _(number)_: The minimum box size to find the limits based on content [mm]. Default: `3`.
- **`min_box_size_limit`** _(number)_: The minimum box size to find the limits based on content [mm]. Default: `10`.
- **`min_box_black_limit`** _(number)_: The minimum black in a box on content find the limits based on content [%]. Default: `2`.
- **`contour_kernel_size_limit`** _(number)_: The block size used in a box on content find the limits based on content [mm]. Default: `1.5`.
- **`threshold_block_size_limit`** _(number)_: The block size used in a box on threshold for content find the limits based on content [mm]. Default: `1.5`.
Expand All @@ -83,7 +83,7 @@
- **`jpeg_quality`** _(integer)_: The JPEG quality. Default: `90`.
- **`background_color`** _(array)_: The background color. Default: `[255, 255, 255]`.
- **Items** _(integer)_
- **`auto_mask`**: The auto mask configuration, the mask is used to mask the image on crop and deskew calculation. Refer to _#/definitions/auto_mask_.
- **`auto_mask`**: The auto mask configuration, the mask is used to mask the image on crop and skew calculation. Refer to _#/definitions/auto_mask_.
- **`auto_cut`**: The auto mask configuration, the mask is used to definitively mask the source image. Refer to _#/definitions/auto_mask_.
- **`deskew_min_angle`** _(number)_: The minimum angle to detect the image skew [degree]. Default: `-10`.
- **`deskew_max_angle`** _(number)_: The maximum angle to detect the image skew [degree]. Default: `10`.
Expand Down
14 changes: 7 additions & 7 deletions process.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
- **Items** _(integer)_
- **`de_noise_morphology`** _(boolean)_: Apply a morphology operation to remove noise. Default: `True`.
- **`inverse_mask`** _(boolean)_: Inverse the mask. Default: `False`.
- **`de_noise_size`** _(integer)_: The size of the artifact that will be de noise. Default: `20`.
- **`de_noise_size`** _(integer)_: The size of the artifact that will be de noise. Default: `1000`.
- **`de_noise_level`** _(integer)_: The threshold level used in de noise on the blurry image. Default: `220`.
- **`buffer_size`** _(integer)_: The size of the buffer add on the mask. Default: `50 an case of mask, 20 in case of cut`.
- **`buffer_size`** _(integer)_: The size of the buffer add on the mask. Default: `20`.
- **`buffer_level`** _(integer)_: The threshold level used in buffer on the blurry image. Default: `20`.
- **`additional_filename`** _(string)_: An image file used to add on the mask.
- **`args`** _(object)_
- **`level`** _(['boolean', 'integer'])_: true: => do level on 15% - 85% (under 15 % will be black above 85% will be white), false: => 0% - 100%, <number>: => (0 + <number>)% - (100 - number)%.
- **`level`** _(['boolean', 'integer'])_: true: => do level on 15% - 85% (under 15 % will be black above 85% will be white), false: => 0% - 100%, <number>: => (0 + <number>)% - (100 - number)%. Default: `False`.
- **`auto_level`** _(boolean)_: If no level specified, do auto level. Default: `False`.
- **`min_level`** _(number)_: Min level if no level end no auto-level. Default: `15`.
- **`max_level`** _(number)_: Max level if no level end no auto-level. Default: `15`.
- **`max_level`** _(number)_: Max level if no level end no auto-level. Default: `85`.
- **`cut_white`** _(number)_: Set the near white pixels on the image to white. Default: `250`.
- **`cut_black`** _(number)_: Set the near black pixels on the image to black. Default: `0`.
- **`no_crop`** _(boolean)_: Don't do any crop. Default: `False`.
Expand All @@ -71,7 +71,7 @@
- **`dpi`** _(number)_: The DPI used to convert the mm to pixel. Default: `300`.
- **`sharpen`** _(boolean)_: Do the sharpen. Default: `False`.
- **`dither`** _(boolean)_: Do the dither. Default: `False`.
- **`tesseract`** _(boolean)_: Use tesseract to to an OCR on the document. Default: `False`.
- **`tesseract`** _(boolean)_: Use tesseract to to an OCR on the document. Default: `True`.
- **`tesseract_lang`** _(string)_: The used language for tesseract. Default: `fra+eng`.
- **`append_credit_card`** _(boolean)_: Do an assisted split. Default: `False`.
- **`assisted_split`** _(boolean)_: Do an assisted split. Default: `False`.
Expand All @@ -85,7 +85,7 @@
- **`contour_kernel_size_empty`** _(number)_: The block size used in a box on content find if the page is empty [mm]. Default: `1.5`.
- **`threshold_block_size_empty`** _(number)_: The block size used in a box on threshold for content find if the page is empty [mm]. Default: `1.5`.
- **`threshold_value_c_empty`** _(number)_: A variable used on threshold, should be low on low contrast image, used in a box on content find if the page is empty. Default: `70`.
- **`min_box_size_limit`** _(number)_: The minimum box size to find the limits based on content [mm]. Default: `3`.
- **`min_box_size_limit`** _(number)_: The minimum box size to find the limits based on content [mm]. Default: `10`.
- **`min_box_black_limit`** _(number)_: The minimum black in a box on content find the limits based on content [%]. Default: `2`.
- **`contour_kernel_size_limit`** _(number)_: The block size used in a box on content find the limits based on content [mm]. Default: `1.5`.
- **`threshold_block_size_limit`** _(number)_: The block size used in a box on threshold for content find the limits based on content [mm]. Default: `1.5`.
Expand All @@ -101,7 +101,7 @@
- **`jpeg_quality`** _(integer)_: The JPEG quality. Default: `90`.
- **`background_color`** _(array)_: The background color. Default: `[255, 255, 255]`.
- **Items** _(integer)_
- **`auto_mask`**: The auto mask configuration, the mask is used to mask the image on crop and deskew calculation. Refer to _#/definitions/auto_mask_.
- **`auto_mask`**: The auto mask configuration, the mask is used to mask the image on crop and skew calculation. Refer to _#/definitions/auto_mask_.
- **`auto_cut`**: The auto mask configuration, the mask is used to definitively mask the source image. Refer to _#/definitions/auto_mask_.
- **`deskew_min_angle`** _(number)_: The minimum angle to detect the image skew [degree]. Default: `-10`.
- **`deskew_max_angle`** _(number)_: The maximum angle to detect the image skew [degree]. Default: `10`.
Expand Down
12 changes: 6 additions & 6 deletions scan_to_paperless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from ruamel.yaml.main import YAML

if sys.version_info.minor >= 8:
from scan_to_paperless import config as stp_config
from scan_to_paperless import config as schema
else:
from scan_to_paperless import config_old as stp_config # type: ignore
from scan_to_paperless import config_old as schema # type: ignore

CONFIG_FILENAME = "scan-to-paperless.yaml"

Expand All @@ -23,13 +23,13 @@
CONFIG_PATH = os.path.join(CONFIG_FOLDER, CONFIG_FILENAME)


def get_config(config_filename: str) -> stp_config.Configuration:
def get_config(config_filename: str) -> schema.Configuration:
"""Get the configuration."""
if os.path.exists(config_filename):
yaml = YAML()
yaml.default_flow_style = False
with open(config_filename, encoding="utf-8") as config_file:
config = cast(stp_config.Configuration, yaml.load(config_file))
config = cast(schema.Configuration, yaml.load(config_file))
if "exteds" in config:

base_config = get_config(
Expand All @@ -38,7 +38,7 @@ def get_config(config_filename: str) -> stp_config.Configuration:
)
)

strategies_config = cast(stp_config.MergeStrategies, config.get("strategies", {}))
strategies_config = cast(schema.MergeStrategies, config.get("strategies", {}))
merger = Merger(
[
(list, strategies_config.get("list", ["override"])),
Expand All @@ -47,7 +47,7 @@ def get_config(config_filename: str) -> stp_config.Configuration:
strategies_config.get("fallback", ["merge"]),
strategies_config.get("type_conflict", ["merge"]),
)
config = cast(stp_config.Configuration, merger.merge(base_config, config))
config = cast(schema.Configuration, merger.merge(base_config, config))
return config
print(f"Missing config file: {config_filename}")
return {}
Loading

0 comments on commit a17ad59

Please sign in to comment.