mirror of
https://github.com/scito/extract_otp_secrets.git
synced 2025-12-19 16:50:34 +01:00
build: add generate result files option
This commit is contained in:
14
build.sh
14
build.sh
@@ -83,6 +83,7 @@ ignore_version_check=true
|
|||||||
clean=false
|
clean=false
|
||||||
build_docker=true
|
build_docker=true
|
||||||
run_gui=true
|
run_gui=true
|
||||||
|
generate_result_files=false
|
||||||
|
|
||||||
while test $# -gt 0; do
|
while test $# -gt 0; do
|
||||||
case $1 in
|
case $1 in
|
||||||
@@ -97,6 +98,7 @@ while test $# -gt 0; do
|
|||||||
echo "-D No docker build"
|
echo "-D No docker build"
|
||||||
echo "-G No not run gui"
|
echo "-G No not run gui"
|
||||||
echo "-c Clean"
|
echo "-c Clean"
|
||||||
|
echo "-r Generate result files"
|
||||||
echo "-h, --help Help"
|
echo "-h, --help Help"
|
||||||
quit
|
quit
|
||||||
;;
|
;;
|
||||||
@@ -116,6 +118,10 @@ while test $# -gt 0; do
|
|||||||
run_gui=false
|
run_gui=false
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-r)
|
||||||
|
generate_result_files=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-c)
|
-c)
|
||||||
clean=true
|
clean=true
|
||||||
shift
|
shift
|
||||||
@@ -286,6 +292,14 @@ cmd="extract_otp_secrets - < example_export.txt"
|
|||||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|
||||||
|
# Generate results files
|
||||||
|
|
||||||
|
if $generate_result_files; then
|
||||||
|
cmd="for color in '' '-n'; do for level in '' '-v' '-vv' '-vvv'; do $PYTHON src/extract_otp_secrets.py example_export.txt $color $level > tests/data/print_verbose_output$color$level.txt; done; done"
|
||||||
|
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||||
|
eval "$cmd"
|
||||||
|
fi
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
|
|
||||||
cmd="$PYTHON src/extract_otp_secrets.py example_export.txt"
|
cmd="$PYTHON src/extract_otp_secrets.py example_export.txt"
|
||||||
|
|||||||
@@ -242,7 +242,9 @@ def cv2_draw_box(img: Any, raw_pts: Any, color: ColorBGR) -> Any:
|
|||||||
def cv2_print_text(img: Any, text: str, line_number: int, position: TextPosition, color: ColorBGR, opposite_len: Optional[int] = None) -> None:
|
def cv2_print_text(img: Any, text: str, line_number: int, position: TextPosition, color: ColorBGR, opposite_len: Optional[int] = None) -> None:
|
||||||
text_dim, _ = cv2.getTextSize(text, FONT, FONT_SCALE, FONT_THICKNESS)
|
text_dim, _ = cv2.getTextSize(text, FONT, FONT_SCALE, FONT_THICKNESS)
|
||||||
window_dim = cv2.getWindowImageRect(WINDOW_NAME)
|
window_dim = cv2.getWindowImageRect(WINDOW_NAME)
|
||||||
out_text = text if not opposite_len or (actual_width := text_dim[TEXT_WIDTH] + opposite_len * CHAR_DX + 4 * BORDER) <= window_dim[WINDOW_WIDTH] else text[:(window_dim[WINDOW_WIDTH] - actual_width) // CHAR_DX] + '.'
|
out_text = text \
|
||||||
|
if not opposite_len or (actual_width := text_dim[TEXT_WIDTH] + opposite_len * CHAR_DX + 4 * BORDER) <= window_dim[WINDOW_WIDTH] \
|
||||||
|
else text[:(window_dim[WINDOW_WIDTH] - actual_width) // CHAR_DX] + '.'
|
||||||
text_dim, _ = cv2.getTextSize(out_text, FONT, FONT_SCALE, FONT_THICKNESS)
|
text_dim, _ = cv2.getTextSize(out_text, FONT, FONT_SCALE, FONT_THICKNESS)
|
||||||
if position == TextPosition.LEFT:
|
if position == TextPosition.LEFT:
|
||||||
pos = BORDER, START_Y + line_number * FONT_DY
|
pos = BORDER, START_Y + line_number * FONT_DY
|
||||||
|
|||||||
@@ -393,6 +393,7 @@ def test_extract_verbose(verbose_level: str, color: str, capsys: pytest.CaptureF
|
|||||||
assert actual_stdout == expected_stdout
|
assert actual_stdout == expected_stdout
|
||||||
assert captured.err == ''
|
assert captured.err == ''
|
||||||
|
|
||||||
|
|
||||||
def normalize_verbose_text(text: str) -> str:
|
def normalize_verbose_text(text: str) -> str:
|
||||||
return re.sub('^.+ version: .+$', '', text, flags=re.MULTILINE | re.IGNORECASE)
|
return re.sub('^.+ version: .+$', '', text, flags=re.MULTILINE | re.IGNORECASE)
|
||||||
|
|
||||||
|
|||||||
@@ -19,21 +19,22 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import annotations # workaround for PYTHON <= 3.10
|
from __future__ import annotations # workaround for PYTHON <= 3.10
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
|
|
||||||
import extract_otp_secrets
|
from utils import (Capturing, count_files_in_dir, read_csv, read_file_to_str,
|
||||||
from utils import (Capturing, read_csv, read_file_to_str, read_json,
|
read_json, remove_dir_with_files, remove_file)
|
||||||
remove_dir_with_files, remove_file, count_files_in_dir)
|
|
||||||
|
|
||||||
|
import extract_otp_secrets
|
||||||
|
|
||||||
# Conditional skip example
|
# Conditional skip example
|
||||||
# if sys.implementation.name == 'pypy' or sys.platform.startswith("win") or sys.version_info < (3, 10):
|
# if sys.implementation.name == 'pypy' or sys.platform.startswith("win") or sys.version_info < (3, 10):
|
||||||
# self.skipTest("Avoid encoding problems")
|
# self.skipTest("Avoid encoding problems")
|
||||||
|
|
||||||
|
|
||||||
class TestExtract(unittest.TestCase):
|
class TestExtract(unittest.TestCase):
|
||||||
|
|
||||||
def test_extract_csv(self) -> None:
|
def test_extract_csv(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user