Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Processing the input directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
walter-weinmann committed Feb 9, 2022
1 parent 275c042 commit 12b5a24
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 109 deletions.
2 changes: 1 addition & 1 deletion run_dcr.bat
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ REM > %LOG_FILE% 2>&1 (
goto normal_exit
)

echo Usage: "./run_dcr.sh all | db_c | m_d | m_p | p_i"
echo Usage: "run_dcr[.bat] all | db_c | m_d | m_p | p_i"
exit -1073741510

:normal_exit
Expand Down
111 changes: 111 additions & 0 deletions run_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
@echo off

rem ----------------------------------------------------------------------------
rem
rem run_test.bat: Document Content Recognition.
rem
rem ----------------------------------------------------------------------------

setlocal EnableDelayedExpansion

set DCR_CHOICE_ACTION_DEFAULT=db_c

if ["%1"] EQU [""] (
echo =========================================================
echo all - Run the complete processing of all new documents
echo db_c - Create the database
echo m_d - Run the installation of the necessary 3rd party packages for development and run the development ecosystem
echo m_p - Run the installation of the necessary 3rd party packages for production and compile all packages and modules
echo p_i - Process input folder
echo ---------------------------------------------------------
set /P DCR_CHOICE_ACTION="Enter the desired action [default: %DCR_CHOICE_ACTION_DEFAULT%] "

if ["!DCR_CHOICE_ACTION!"] EQU [""] (
set DCR_CHOICE_ACTION=%DCR_CHOICE_ACTION_DEFAULT%
)
) else (
set DCR_CHOICE_ACTION=%1
)

echo.
echo Script %0 is now running

set LOG_FILE=run_test.log
if exist run_test.log del /f /q run_test.log
if exist run_test_debug.log del /f /q run_test_debug.log

echo.
echo You can find the run log in the file %LOG_FILE%
echo.
echo Please wait ...
echo.

REM > %LOG_FILE% 2>&1 (

echo =======================================================================
echo Start %0
echo -----------------------------------------------------------------------
echo DCR - Document Content Recognition.
echo -----------------------------------------------------------------------
echo CHOICE_ACTION : %DCR_CHOICE_ACTION%
echo -----------------------------------------------------------------------
echo:| TIME
echo =======================================================================

set _CHOICE=

if ["%DCR_CHOICE_ACTION%"] EQU ["m_d"] (
make pipenv-dev
if ERRORLEVEL 1 (
echo Processing of the script: %0 - step: 'make inst_dev' was aborted
)
make dev
if ERRORLEVEL 1 (
echo Processing of the script: %0 - step: 'make eco_dev' was aborted
)
goto normal_exit
)

if ["%DCR_CHOICE_ACTION%"] EQU ["m_p"] (
make pipenv-prod
if ERRORLEVEL 1 (
echo Processing of the script: %0 - step: 'make prod' was aborted
)
make compileall
if ERRORLEVEL 1 (
echo Processing of the script: %0 - step: 'make prod' was aborted
)
goto normal_exit
)

if ["%DCR_CHOICE_ACTION%"] EQU ["all"] set _CHOICE=%DCR_CHOICE_ACTION%

if ["%DCR_CHOICE_ACTION%"] EQU ["db_c"] (
if exist data\dcr.db del /f /q data\dcr.db
set _CHOICE=%DCR_CHOICE_ACTION%
)

if ["%DCR_CHOICE_ACTION%"] EQU ["p_i"] (
if exist data\inbox rmdir /s /q data\inbox
mkdir data\inbox
xcopy /E /I tests\inbox data\inbox
set _CHOICE=%DCR_CHOICE_ACTION%
)

if ["%_CHOICE%"] EQU ["%DCR_CHOICE_ACTION%"] (
pipenv run python src\dcr\dcr.py %DCR_CHOICE_ACTION%
if ERRORLEVEL 1 (
echo Processing of the script: %0 - step: 'python src\dcr\dcr.py %DCR_CHOICE_ACTION%' was aborted
)
goto normal_exit
)

echo Usage: "run_test[.bat] all | db_c | m_d | m_p | p_i"

:normal_exit
echo -----------------------------------------------------------------------
echo:| TIME
echo -----------------------------------------------------------------------
echo End %0
echo =======================================================================
REM )
15 changes: 11 additions & 4 deletions src/dcr/dcr.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ def main(argv: List[str]) -> None:

if args[cfg.RUN_ACTION_CREATE_DB]:
# Create the database tables.
utils.progress_msg(logger, "Start: Create the database tables ...")
db.create_db_tables(logger)
db.create_database(logger)
db.create_dbt_version_row(logger)
else:
# Process the documents.
utils.progress_msg(logger, "Start: Process the documents ...")
process_documents(logger, args)

print("End dcr.py")
Expand All @@ -188,14 +186,19 @@ def process_documents(logger: logging.Logger, args: dict[str, bool]) -> None:
logger (logging.Logger): Current logger.
args (dict[str, bool]): The processing steps based on CLI arguments.
"""
logger.debug(cfg.LOGGER_START)

print("")
utils.progress_msg(logger, "Start: Process the documents ...")

# Connect to the database.
db.connect_db(logger)

# Check the version of the database.
db.check_db_up_to_date(logger)

# Creation of the run entry in the database.
db.create_dbt_run_row(logger)
db.insert_dbt_run_row(logger)

# Process the documents in the inbox file directory.
if args[cfg.RUN_ACTION_PROCESS_INBOX]:
Expand All @@ -207,6 +210,10 @@ def process_documents(logger: logging.Logger, args: dict[str, bool]) -> None:
# Disconnect from the database.
db.disconnect_db(logger)

utils.progress_msg(logger, "End : Process the documents ...")

logger.debug(cfg.LOGGER_END)


# -----------------------------------------------------------------------------
# Terminate the current entry in the database table run.
Expand Down
4 changes: 4 additions & 0 deletions src/dcr/libs/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
JOURNAL_ACTION_01_001: str = (
"01.001 New document detected in the 'inbox' file directory"
)
JOURNAL_ACTION_01_901: str = (
"01.901 Document rejected because of unknown extension"
)

LOCALE: str = "en_US.UTF-8"
LOGGER_CFG_FILE: str = "logging_cfg.yaml"
Expand All @@ -85,6 +88,7 @@
STATUS_NEW: str = "new"
STATUS_NEXT_PANDOC: str = "next_pandoc"
STATUS_NEXT_TESSERACT: str = "next_tesseract"
STATUS_REJECTED: str = "rejected"
STATUS_START: str = "start"

# -----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/dcr/libs/cfg.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ FILE_TYPE_PDF: str
FILE_TYPE_TXT: str

JOURNAL_ACTION_01_001: str
JOURNAL_ACTION_01_901: str

LOCALE: str
LOGGER_CFG_FILE: str
Expand All @@ -83,6 +84,7 @@ STATUS_INVALID_FILE_TYPE: str
STATUS_NEW: str
STATUS_NEXT_PANDOC: str
STATUS_NEXT_TESSERACT: str
STATUS_REJECTED: str
STATUS_START: str

# -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 12b5a24

Please sign in to comment.