Skip to content

Commit

Permalink
Use the default from the jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 16, 2022
1 parent f92b730 commit 009b71e
Show file tree
Hide file tree
Showing 9 changed files with 985 additions and 529 deletions.
12 changes: 6 additions & 6 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 @@ -41,10 +41,10 @@
- **`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 @@ -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 Down
6 changes: 3 additions & 3 deletions process.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
- **`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 @@ -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 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 009b71e

Please sign in to comment.