From a9679dea4799da1cea5a9f2d244e9f815d16cb25 Mon Sep 17 00:00:00 2001 From: Artyom Semidolin <43622365+Artanias@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:10:09 +0300 Subject: [PATCH] feat: adds setting for changing log level and extends information about checking files. Refs: #162. --- Makefile | 2 +- locales/codeplag.pot | 88 +++++++++--------- .../translations/en/LC_MESSAGES/codeplag.po | 89 +++++++++--------- .../translations/ru/LC_MESSAGES/codeplag.po | 90 ++++++++++--------- src/codeplag/__init__.py | 4 +- src/codeplag/codeplagcli.py | 15 ++-- src/codeplag/config.py | 2 + src/codeplag/consts.tmp.py | 3 + src/codeplag/handlers/check.py | 30 +++++-- src/codeplag/logger.py | 16 ++-- src/codeplag/types.py | 2 + test/auto/conftest.py | 6 ++ test/auto/functional/test_settings.py | 30 ++++--- test/auto/functional/test_stream_log.py | 2 +- test/auto/utils.py | 19 ++-- test/unit/codeplag/test_config.py | 4 + 16 files changed, 233 insertions(+), 169 deletions(-) diff --git a/Makefile b/Makefile index eebaaec..a745c11 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -UTIL_VERSION := 0.4.10 +UTIL_VERSION := 0.4.11 UTIL_NAME := codeplag PWD := $(shell pwd) diff --git a/locales/codeplag.pot b/locales/codeplag.pot index a2aee73..91e1b0d 100644 --- a/locales/codeplag.pot +++ b/locales/codeplag.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: codeplag 0.4.9\n" +"Project-Id-Version: codeplag 0.4.11\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-07-05 19:20+0300\n" +"POT-Creation-Date: 2024-07-13 23:45+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Artyom Semidolin\n" "Language-Team: LANGUAGE \n" @@ -17,47 +17,47 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.15.0\n" -#: src/codeplag/codeplagcli.py:44 +#: src/codeplag/codeplagcli.py:45 msgid "You cannot specify the same value multiple times. You provided '{values}'." msgstr "" -#: src/codeplag/codeplagcli.py:61 +#: src/codeplag/codeplagcli.py:62 msgid "Directory '{path}' not found or not a directory." msgstr "" -#: src/codeplag/codeplagcli.py:76 +#: src/codeplag/codeplagcli.py:77 msgid "File '{path}' not found or not a file." msgstr "" -#: src/codeplag/codeplagcli.py:88 +#: src/codeplag/codeplagcli.py:89 msgid "Modifies and shows static settings of the '{util_name}' util." msgstr "" -#: src/codeplag/codeplagcli.py:94 +#: src/codeplag/codeplagcli.py:95 msgid "Settings commands of the '{util_name}' util." msgstr "" -#: src/codeplag/codeplagcli.py:105 +#: src/codeplag/codeplagcli.py:106 msgid "Manage the '{util_name}' util settings." msgstr "" -#: src/codeplag/codeplagcli.py:112 +#: src/codeplag/codeplagcli.py:113 msgid "Path to the environment file with GitHub access token." msgstr "" -#: src/codeplag/codeplagcli.py:118 +#: src/codeplag/codeplagcli.py:119 msgid "If defined, then saves reports about suspect works into provided path." msgstr "" -#: src/codeplag/codeplagcli.py:127 +#: src/codeplag/codeplagcli.py:128 msgid "Extension of saved report files." msgstr "" -#: src/codeplag/codeplagcli.py:134 +#: src/codeplag/codeplagcli.py:135 msgid "Show progress of searching plagiarism." msgstr "" -#: src/codeplag/codeplagcli.py:141 +#: src/codeplag/codeplagcli.py:142 msgid "" "Threshold of analyzer which classifies two work as same. If this number " "is too large, such as 99, then completely matching jobs will be found. " @@ -65,125 +65,127 @@ msgid "" "minimal similarity will be found." msgstr "" -#: src/codeplag/codeplagcli.py:155 +#: src/codeplag/codeplagcli.py:156 msgid "The language of help messages, generated reports, errors." msgstr "" #: src/codeplag/codeplagcli.py:162 -msgid "The maximum number of processes that can be used to compare works." +msgid "" +"Sets the threshold for the '{util_name}' util loggers'. Logging messages " +"that are less severe than the level will be ignored." msgstr "" #: src/codeplag/codeplagcli.py:172 +msgid "The maximum number of processes that can be used to compare works." +msgstr "" + +#: src/codeplag/codeplagcli.py:182 msgid "Show the '{util_name}' util settings." msgstr "" -#: src/codeplag/codeplagcli.py:176 +#: src/codeplag/codeplagcli.py:186 msgid "Start searching similar works." msgstr "" -#: src/codeplag/codeplagcli.py:182 +#: src/codeplag/codeplagcli.py:192 msgid "Absolute or relative path to a local directories with project files." msgstr "" -#: src/codeplag/codeplagcli.py:194 +#: src/codeplag/codeplagcli.py:204 msgid "Absolute or relative path to files on a computer." msgstr "" -#: src/codeplag/codeplagcli.py:201 +#: src/codeplag/codeplagcli.py:211 msgid "" "Choose one of the following modes of searching plagiarism. The " "'many_to_many' mode may require more free memory." msgstr "" -#: src/codeplag/codeplagcli.py:212 +#: src/codeplag/codeplagcli.py:222 msgid "" "A regular expression for filtering checked works by name. Used with " "options 'directories', 'github-user' and 'github-project-folders'." msgstr "" -#: src/codeplag/codeplagcli.py:221 +#: src/codeplag/codeplagcli.py:231 msgid "Ignore the threshold when checking of works." msgstr "" -#: src/codeplag/codeplagcli.py:228 +#: src/codeplag/codeplagcli.py:238 msgid "Extension responsible for the analyzed programming language." msgstr "" -#: src/codeplag/codeplagcli.py:238 +#: src/codeplag/codeplagcli.py:248 msgid "Searching in all branches." msgstr "" -#: src/codeplag/codeplagcli.py:245 +#: src/codeplag/codeplagcli.py:255 msgid "A regular expression to filter searching repositories on GitHub." msgstr "" -#: src/codeplag/codeplagcli.py:252 +#: src/codeplag/codeplagcli.py:262 msgid "URL to file in a GitHub repository." msgstr "" -#: src/codeplag/codeplagcli.py:258 +#: src/codeplag/codeplagcli.py:268 msgid "GitHub organization/user name." msgstr "" -#: src/codeplag/codeplagcli.py:265 +#: src/codeplag/codeplagcli.py:275 msgid "URL to a GitHub project folder." msgstr "" -#: src/codeplag/codeplagcli.py:275 +#: src/codeplag/codeplagcli.py:285 msgid "" "Handling generated by the {util_name} reports as creating html report " "file or show it on console." msgstr "" -#: src/codeplag/codeplagcli.py:283 +#: src/codeplag/codeplagcli.py:293 msgid "Report commands of the '{util_name}' util." msgstr "" -#: src/codeplag/codeplagcli.py:294 +#: src/codeplag/codeplagcli.py:304 msgid "Generate general report from created some time ago report files." msgstr "" -#: src/codeplag/codeplagcli.py:299 +#: src/codeplag/codeplagcli.py:309 msgid "" "Path to save generated report. If it's a directory, then create a file in" " it." msgstr "" -#: src/codeplag/codeplagcli.py:309 +#: src/codeplag/codeplagcli.py:319 msgid "Type of the created report file." msgstr "" -#: src/codeplag/codeplagcli.py:319 +#: src/codeplag/codeplagcli.py:329 msgid "" "Program help to find similar parts of source codes for the different " "languages." msgstr "" -#: src/codeplag/codeplagcli.py:327 +#: src/codeplag/codeplagcli.py:337 msgid "Print current version number and exit." msgstr "" -#: src/codeplag/codeplagcli.py:333 -msgid "Show debug messages." -msgstr "" - -#: src/codeplag/codeplagcli.py:338 +#: src/codeplag/codeplagcli.py:343 msgid "Commands help." msgstr "" -#: src/codeplag/codeplagcli.py:354 +#: src/codeplag/codeplagcli.py:359 msgid "No command is provided; please choose one from the available (--help)." msgstr "" -#: src/codeplag/codeplagcli.py:369 +#: src/codeplag/codeplagcli.py:374 msgid "There is nothing to modify; please provide at least one argument." msgstr "" -#: src/codeplag/codeplagcli.py:374 +#: src/codeplag/codeplagcli.py:379 msgid "The'repo-regexp' option requires the provided 'github-user' option." msgstr "" -#: src/codeplag/codeplagcli.py:384 +#: src/codeplag/codeplagcli.py:389 msgid "" "The'path-regexp' option requires the provided 'directories', 'github-" "user', or 'github-project-folder' options." diff --git a/locales/translations/en/LC_MESSAGES/codeplag.po b/locales/translations/en/LC_MESSAGES/codeplag.po index cb319f0..c6fd31c 100644 --- a/locales/translations/en/LC_MESSAGES/codeplag.po +++ b/locales/translations/en/LC_MESSAGES/codeplag.po @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: codeplag 0.4.8\n" +"Project-Id-Version: codeplag 0.4.11\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "POT-Creation-Date: 2024-05-21 09:28+0300\n" "PO-Revision-Date: 2024-05-16 19:15+0300\n" @@ -18,47 +18,47 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.15.0\n" -#: src/codeplag/codeplagcli.py:44 +#: src/codeplag/codeplagcli.py:45 msgid "You cannot specify the same value multiple times. You provided '{values}'." msgstr "You cannot specify the same value multiple times. You provided '{values}'." -#: src/codeplag/codeplagcli.py:61 +#: src/codeplag/codeplagcli.py:62 msgid "Directory '{path}' not found or not a directory." msgstr "Directory '{path}' not found or not a directory." -#: src/codeplag/codeplagcli.py:76 +#: src/codeplag/codeplagcli.py:77 msgid "File '{path}' not found or not a file." msgstr "File '{path}' not found or not a file." -#: src/codeplag/codeplagcli.py:88 +#: src/codeplag/codeplagcli.py:89 msgid "Modifies and shows static settings of the '{util_name}' util." msgstr "Modifies and shows static settings of the '{util_name}' util." -#: src/codeplag/codeplagcli.py:94 +#: src/codeplag/codeplagcli.py:95 msgid "Settings commands of the '{util_name}' util." msgstr "Settings commands of the '{util_name}' util." -#: src/codeplag/codeplagcli.py:105 +#: src/codeplag/codeplagcli.py:106 msgid "Manage the '{util_name}' util settings." msgstr "Manage the '{util_name}' util settings." -#: src/codeplag/codeplagcli.py:112 +#: src/codeplag/codeplagcli.py:113 msgid "Path to the environment file with GitHub access token." msgstr "Path to the environment file with GitHub access token." -#: src/codeplag/codeplagcli.py:118 +#: src/codeplag/codeplagcli.py:119 msgid "If defined, then saves reports about suspect works into provided path." msgstr "If defined, then saves reports about suspect works into provided path." -#: src/codeplag/codeplagcli.py:127 +#: src/codeplag/codeplagcli.py:128 msgid "Extension of saved report files." msgstr "Extension of saved report files." -#: src/codeplag/codeplagcli.py:134 +#: src/codeplag/codeplagcli.py:135 msgid "Show progress of searching plagiarism." msgstr "Show progress of searching plagiarism." -#: src/codeplag/codeplagcli.py:141 +#: src/codeplag/codeplagcli.py:142 msgid "" "Threshold of analyzer which classifies two work as same. If this number " "is too large, such as 99, then completely matching jobs will be found. " @@ -70,31 +70,39 @@ msgstr "" "Otherwise, if this number is small, such as 50, then all work with " "minimal similarity will be found." -#: src/codeplag/codeplagcli.py:155 +#: src/codeplag/codeplagcli.py:156 msgid "The language of help messages, generated reports, errors." msgstr "The language of help messages, generated reports, errors." #: src/codeplag/codeplagcli.py:162 +msgid "" +"Sets the threshold for the '{util_name}' util loggers'. Logging messages " +"that are less severe than the level will be ignored." +msgstr "" +"Sets the threshold for the '{util_name}' util loggers'. Logging messages " +"that are less severe than the level will be ignored." + +#: src/codeplag/codeplagcli.py:172 msgid "The maximum number of processes that can be used to compare works." msgstr "The maximum number of processes that can be used to compare works." -#: src/codeplag/codeplagcli.py:172 +#: src/codeplag/codeplagcli.py:182 msgid "Show the '{util_name}' util settings." msgstr "Show the '{util_name}' util settings." -#: src/codeplag/codeplagcli.py:176 +#: src/codeplag/codeplagcli.py:186 msgid "Start searching similar works." msgstr "Start searching similar works." -#: src/codeplag/codeplagcli.py:182 +#: src/codeplag/codeplagcli.py:192 msgid "Absolute or relative path to a local directories with project files." msgstr "Absolute or relative path to a local directories with project files." -#: src/codeplag/codeplagcli.py:194 +#: src/codeplag/codeplagcli.py:204 msgid "Absolute or relative path to files on a computer." msgstr "Absolute or relative path to files on a computer." -#: src/codeplag/codeplagcli.py:201 +#: src/codeplag/codeplagcli.py:211 msgid "" "Choose one of the following modes of searching plagiarism. The " "'many_to_many' mode may require more free memory." @@ -102,7 +110,7 @@ msgstr "" "Choose one of the following modes of searching plagiarism. The " "'many_to_many' mode may require more free memory." -#: src/codeplag/codeplagcli.py:212 +#: src/codeplag/codeplagcli.py:222 msgid "" "A regular expression for filtering checked works by name. Used with " "options 'directories', 'github-user' and 'github-project-folders'." @@ -110,35 +118,35 @@ msgstr "" "A regular expression for filtering checked works by name. Used with " "options 'directories', 'github-user' and 'github-project-folders'." -#: src/codeplag/codeplagcli.py:221 +#: src/codeplag/codeplagcli.py:231 msgid "Ignore the threshold when checking of works." msgstr "Ignore the threshold when checking of works." -#: src/codeplag/codeplagcli.py:228 +#: src/codeplag/codeplagcli.py:238 msgid "Extension responsible for the analyzed programming language." msgstr "Extension responsible for the analyzed programming language." -#: src/codeplag/codeplagcli.py:238 +#: src/codeplag/codeplagcli.py:248 msgid "Searching in all branches." msgstr "Searching in all branches." -#: src/codeplag/codeplagcli.py:245 +#: src/codeplag/codeplagcli.py:255 msgid "A regular expression to filter searching repositories on GitHub." msgstr "A regular expression to filter searching repositories on GitHub." -#: src/codeplag/codeplagcli.py:252 +#: src/codeplag/codeplagcli.py:262 msgid "URL to file in a GitHub repository." msgstr "URL to file in a GitHub repository." -#: src/codeplag/codeplagcli.py:258 +#: src/codeplag/codeplagcli.py:268 msgid "GitHub organization/user name." msgstr "GitHub organization/user name." -#: src/codeplag/codeplagcli.py:265 +#: src/codeplag/codeplagcli.py:275 msgid "URL to a GitHub project folder." msgstr "URL to a GitHub project folder." -#: src/codeplag/codeplagcli.py:275 +#: src/codeplag/codeplagcli.py:285 msgid "" "Handling generated by the {util_name} reports as creating html report " "file or show it on console." @@ -146,15 +154,15 @@ msgstr "" "Handling generated by the {util_name} reports as creating html report " "file or show it on console." -#: src/codeplag/codeplagcli.py:283 +#: src/codeplag/codeplagcli.py:293 msgid "Report commands of the '{util_name}' util." msgstr "Report commands of the '{util_name}' util." -#: src/codeplag/codeplagcli.py:294 +#: src/codeplag/codeplagcli.py:304 msgid "Generate general report from created some time ago report files." msgstr "Generate general report from created some time ago report files." -#: src/codeplag/codeplagcli.py:299 +#: src/codeplag/codeplagcli.py:309 msgid "" "Path to save generated report. If it's a directory, then create a file in" " it." @@ -162,11 +170,11 @@ msgstr "" "Path to save generated report. If it's a directory, then create a file in" " it." -#: src/codeplag/codeplagcli.py:309 +#: src/codeplag/codeplagcli.py:319 msgid "Type of the created report file." msgstr "Type of the created report file." -#: src/codeplag/codeplagcli.py:319 +#: src/codeplag/codeplagcli.py:329 msgid "" "Program help to find similar parts of source codes for the different " "languages." @@ -174,31 +182,27 @@ msgstr "" "Program help to find similar parts of source codes for the different " "languages." -#: src/codeplag/codeplagcli.py:327 +#: src/codeplag/codeplagcli.py:337 msgid "Print current version number and exit." msgstr "Print current version number and exit." -#: src/codeplag/codeplagcli.py:333 -msgid "Show debug messages." -msgstr "Show debug messages." - -#: src/codeplag/codeplagcli.py:338 +#: src/codeplag/codeplagcli.py:343 msgid "Commands help." msgstr "Commands help." -#: src/codeplag/codeplagcli.py:354 +#: src/codeplag/codeplagcli.py:359 msgid "No command is provided; please choose one from the available (--help)." msgstr "No command is provided; please choose one from the available (--help)." -#: src/codeplag/codeplagcli.py:369 +#: src/codeplag/codeplagcli.py:374 msgid "There is nothing to modify; please provide at least one argument." msgstr "There is nothing to modify; please provide at least one argument." -#: src/codeplag/codeplagcli.py:374 +#: src/codeplag/codeplagcli.py:379 msgid "The'repo-regexp' option requires the provided 'github-user' option." msgstr "The'repo-regexp' option requires the provided 'github-user' option." -#: src/codeplag/codeplagcli.py:384 +#: src/codeplag/codeplagcli.py:389 msgid "" "The'path-regexp' option requires the provided 'directories', 'github-" "user', or 'github-project-folder' options." @@ -314,4 +318,3 @@ msgstr "Part of the file that is being checked" #: src/templates/sources.templ:68 msgid "Part of a similar file" msgstr "Part of a similar file" - diff --git a/locales/translations/ru/LC_MESSAGES/codeplag.po b/locales/translations/ru/LC_MESSAGES/codeplag.po index 4386389..d63b335 100644 --- a/locales/translations/ru/LC_MESSAGES/codeplag.po +++ b/locales/translations/ru/LC_MESSAGES/codeplag.po @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: codeplag 0.4.8\n" +"Project-Id-Version: codeplag 0.4.11\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "POT-Creation-Date: 2024-05-21 09:28+0300\n" "PO-Revision-Date: 2024-05-11 12:05+0300\n" @@ -19,51 +19,51 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.15.0\n" -#: src/codeplag/codeplagcli.py:44 +#: src/codeplag/codeplagcli.py:45 msgid "You cannot specify the same value multiple times. You provided '{values}'." msgstr "" "Нельзя указать одно и тоже значение несколько раз. Было указано " "'{values}'." -#: src/codeplag/codeplagcli.py:61 +#: src/codeplag/codeplagcli.py:62 msgid "Directory '{path}' not found or not a directory." msgstr "Каталог '{path}' не найден или он не является каталогом." -#: src/codeplag/codeplagcli.py:76 +#: src/codeplag/codeplagcli.py:77 msgid "File '{path}' not found or not a file." msgstr "Файл '{path}' не найден или он не является файлом." -#: src/codeplag/codeplagcli.py:88 +#: src/codeplag/codeplagcli.py:89 msgid "Modifies and shows static settings of the '{util_name}' util." msgstr "Изменение и отображение статических настроек утилиты '{util_name}'." -#: src/codeplag/codeplagcli.py:94 +#: src/codeplag/codeplagcli.py:95 msgid "Settings commands of the '{util_name}' util." msgstr "Команды настройки утилиты '{util_name}'." -#: src/codeplag/codeplagcli.py:105 +#: src/codeplag/codeplagcli.py:106 msgid "Manage the '{util_name}' util settings." msgstr "Модификация настроек утилиты '{util_name}'." -#: src/codeplag/codeplagcli.py:112 +#: src/codeplag/codeplagcli.py:113 msgid "Path to the environment file with GitHub access token." msgstr "Путь к файлу окружения с токеном доступа к GitHub." -#: src/codeplag/codeplagcli.py:118 +#: src/codeplag/codeplagcli.py:119 msgid "If defined, then saves reports about suspect works into provided path." msgstr "" "Если значение определено, то сохраняет отчеты о подозрительных работах по" " указанному пути." -#: src/codeplag/codeplagcli.py:127 +#: src/codeplag/codeplagcli.py:128 msgid "Extension of saved report files." msgstr "Расширение сохраняемых файлов отчёта." -#: src/codeplag/codeplagcli.py:134 +#: src/codeplag/codeplagcli.py:135 msgid "Show progress of searching plagiarism." msgstr "Показывать прогресс выполнения поиска схожих работ." -#: src/codeplag/codeplagcli.py:141 +#: src/codeplag/codeplagcli.py:142 msgid "" "Threshold of analyzer which classifies two work as same. If this number " "is too large, such as 99, then completely matching jobs will be found. " @@ -76,33 +76,42 @@ msgstr "" "будет невелико, например, 50, то будут найдены все работы с минимальным " "сходством." -#: src/codeplag/codeplagcli.py:155 +#: src/codeplag/codeplagcli.py:156 msgid "The language of help messages, generated reports, errors." msgstr "Язык справочных сообщений, сгенерированных отчетов, ошибок." #: src/codeplag/codeplagcli.py:162 +msgid "" +"Sets the threshold for the '{util_name}' util loggers'. Logging messages " +"that are less severe than the level will be ignored." +msgstr "" +"Устанавливает пороговое значение логирования утилиты '{util_name}'. " +"Сообщения, которые менее серьезны, чем это значение, будут " +"игнорироваться." + +#: src/codeplag/codeplagcli.py:172 msgid "The maximum number of processes that can be used to compare works." msgstr "" "Максимальное количество процессов, которые можно задействовать для " "сравнения работ." -#: src/codeplag/codeplagcli.py:172 +#: src/codeplag/codeplagcli.py:182 msgid "Show the '{util_name}' util settings." msgstr "Показать настройки утилиты '{util_name}'." -#: src/codeplag/codeplagcli.py:176 +#: src/codeplag/codeplagcli.py:186 msgid "Start searching similar works." msgstr "Начать поиск схожих работ." -#: src/codeplag/codeplagcli.py:182 +#: src/codeplag/codeplagcli.py:192 msgid "Absolute or relative path to a local directories with project files." msgstr "Абсолютный или относительный путь к локальным папкам с файлами проекта." -#: src/codeplag/codeplagcli.py:194 +#: src/codeplag/codeplagcli.py:204 msgid "Absolute or relative path to files on a computer." msgstr "Абсолютный или относительный путь к файлам на компьютере." -#: src/codeplag/codeplagcli.py:201 +#: src/codeplag/codeplagcli.py:211 msgid "" "Choose one of the following modes of searching plagiarism. The " "'many_to_many' mode may require more free memory." @@ -110,7 +119,7 @@ msgstr "" "Выберите один из следующих режимов поиска схожих работ. Режим " "'many_to_many' может требовать больше свободной памяти." -#: src/codeplag/codeplagcli.py:212 +#: src/codeplag/codeplagcli.py:222 msgid "" "A regular expression for filtering checked works by name. Used with " "options 'directories', 'github-user' and 'github-project-folders'." @@ -119,35 +128,35 @@ msgstr "" "Используется с аргументами 'directories', 'github-user' или 'github-" "project-folders'." -#: src/codeplag/codeplagcli.py:221 +#: src/codeplag/codeplagcli.py:231 msgid "Ignore the threshold when checking of works." msgstr "Игнорировать пороговое значение при проверке работ." -#: src/codeplag/codeplagcli.py:228 +#: src/codeplag/codeplagcli.py:238 msgid "Extension responsible for the analyzed programming language." msgstr "Расширение проверяемых работ." -#: src/codeplag/codeplagcli.py:238 +#: src/codeplag/codeplagcli.py:248 msgid "Searching in all branches." msgstr "Поиск по всем веткам." -#: src/codeplag/codeplagcli.py:245 +#: src/codeplag/codeplagcli.py:255 msgid "A regular expression to filter searching repositories on GitHub." msgstr "Регулярное выражение для фильтрации искомых репозиториев на GitHub." -#: src/codeplag/codeplagcli.py:252 +#: src/codeplag/codeplagcli.py:262 msgid "URL to file in a GitHub repository." msgstr "URL до файла в репозитории на GitHub." -#: src/codeplag/codeplagcli.py:258 +#: src/codeplag/codeplagcli.py:268 msgid "GitHub organization/user name." msgstr "Название организации или имя пользователя на GitHub." -#: src/codeplag/codeplagcli.py:265 +#: src/codeplag/codeplagcli.py:275 msgid "URL to a GitHub project folder." msgstr "URL до какой-либо папки проекта на GitHub." -#: src/codeplag/codeplagcli.py:275 +#: src/codeplag/codeplagcli.py:285 msgid "" "Handling generated by the {util_name} reports as creating html report " "file or show it on console." @@ -155,15 +164,15 @@ msgstr "" "Обработка отчетов, сгенерированных с помощью {util_name}, в виде создания" " файла отчета в формате html или отображения его на консоли." -#: src/codeplag/codeplagcli.py:283 +#: src/codeplag/codeplagcli.py:293 msgid "Report commands of the '{util_name}' util." msgstr "Команды для работы с отчётами утилиты '{util_name}'." -#: src/codeplag/codeplagcli.py:294 +#: src/codeplag/codeplagcli.py:304 msgid "Generate general report from created some time ago report files." msgstr "Создание общего отчёта из созданных ранее файлов отчётов." -#: src/codeplag/codeplagcli.py:299 +#: src/codeplag/codeplagcli.py:309 msgid "" "Path to save generated report. If it's a directory, then create a file in" " it." @@ -171,11 +180,11 @@ msgstr "" "Путь для сохранения созданного отчёта. Если передан путь до папки, то " "создаёт отчёт в ней." -#: src/codeplag/codeplagcli.py:309 +#: src/codeplag/codeplagcli.py:319 msgid "Type of the created report file." msgstr "Тип создаваемого файла отчёта." -#: src/codeplag/codeplagcli.py:319 +#: src/codeplag/codeplagcli.py:329 msgid "" "Program help to find similar parts of source codes for the different " "languages." @@ -183,35 +192,31 @@ msgstr "" "Программа помогает находить схожие части исходных кодов для разных языков" " программирования." -#: src/codeplag/codeplagcli.py:327 +#: src/codeplag/codeplagcli.py:337 msgid "Print current version number and exit." msgstr "Выводит текущую версию программы." -#: src/codeplag/codeplagcli.py:333 -msgid "Show debug messages." -msgstr "Отображать отладочные сообщения в выводе." - -#: src/codeplag/codeplagcli.py:338 +#: src/codeplag/codeplagcli.py:343 msgid "Commands help." msgstr "Справка по командам." -#: src/codeplag/codeplagcli.py:354 +#: src/codeplag/codeplagcli.py:359 msgid "No command is provided; please choose one from the available (--help)." msgstr "" "Ни одна из команд не выбрана, пожалуйста, выбери одну из доступных команд" " (--help)." -#: src/codeplag/codeplagcli.py:369 +#: src/codeplag/codeplagcli.py:374 msgid "There is nothing to modify; please provide at least one argument." msgstr "" "Нечего модифицировать, пожалуйста, выберите один из параметров для " "модификации." -#: src/codeplag/codeplagcli.py:374 +#: src/codeplag/codeplagcli.py:379 msgid "The'repo-regexp' option requires the provided 'github-user' option." msgstr "Аргумент 'repo-regexp' требует заданного параметра 'github-user'." -#: src/codeplag/codeplagcli.py:384 +#: src/codeplag/codeplagcli.py:389 msgid "" "The'path-regexp' option requires the provided 'directories', 'github-" "user', or 'github-project-folder' options." @@ -327,4 +332,3 @@ msgstr "Часть проверяемого файла" #: src/templates/sources.templ:68 msgid "Part of a similar file" msgstr "Часть схожего файла" - diff --git a/src/codeplag/__init__.py b/src/codeplag/__init__.py index d2360c8..a6a22e8 100644 --- a/src/codeplag/__init__.py +++ b/src/codeplag/__init__.py @@ -6,6 +6,7 @@ def main() -> Literal[0, 1, 2]: import pandas as pd from codeplag.codeplagcli import CodeplagCLI + from codeplag.config import read_settings_conf from codeplag.consts import LOG_PATH from codeplag.logger import codeplag_logger as logger from codeplag.logger import set_handlers @@ -21,7 +22,8 @@ def main() -> Literal[0, 1, 2]: cli = CodeplagCLI() argcomplete.autocomplete(cli) parsed_args = vars(cli.parse_args()) - set_handlers(logger, LOG_PATH, bool(parsed_args["verbose"])) + settings_conf = read_settings_conf() + set_handlers(logger, LOG_PATH, settings_conf["log_level"]) try: codeplag_util = CodeplagEngine(parsed_args) code = codeplag_util.run() diff --git a/src/codeplag/codeplagcli.py b/src/codeplag/codeplagcli.py index 8b9c2f0..e57f44e 100644 --- a/src/codeplag/codeplagcli.py +++ b/src/codeplag/codeplagcli.py @@ -15,6 +15,7 @@ DEFAULT_REPORT_TYPE, EXTENSION_CHOICE, LANGUAGE_CHOICE, + LOG_LEVEL_CHOICE, MODE_CHOICE, REPORT_TYPE_CHOICE, REPORTS_EXTENSION_CHOICE, @@ -156,6 +157,15 @@ def __add_settings_path(self, subparsers: argparse._SubParsersAction) -> None: type=str, choices=LANGUAGE_CHOICE, ) + settings_modify.add_argument( + "--log-level", + help=_( + "Sets the threshold for the '{util_name}' util loggers'. " + "Logging messages that are less severe than the level will be ignored." + ).format(util_name=UTIL_NAME), + type=str, + choices=LOG_LEVEL_CHOICE, + ) settings_modify.add_argument( "-w", "--workers", @@ -328,11 +338,6 @@ def __init__(self): action="version", version=f"{UTIL_NAME} {UTIL_VERSION}", ) - self.add_argument( - "--verbose", - help=_("Show debug messages."), - action="store_true", - ) subparsers = self.add_subparsers( help=_("Commands help."), diff --git a/src/codeplag/config.py b/src/codeplag/config.py index 98af217..81f73be 100644 --- a/src/codeplag/config.py +++ b/src/codeplag/config.py @@ -5,6 +5,7 @@ from codeplag.consts import ( CONFIG_PATH, DEFAULT_LANGUAGE, + DEFAULT_LOG_LEVEL, DEFAULT_REPORT_EXTENSION, DEFAULT_THRESHOLD, DEFAULT_WORKERS, @@ -84,5 +85,6 @@ def write_settings_conf(settings: Settings) -> None: show_progress=0, reports_extension=DEFAULT_REPORT_EXTENSION, language=DEFAULT_LANGUAGE, + log_level=DEFAULT_LOG_LEVEL, workers=DEFAULT_WORKERS, ) diff --git a/src/codeplag/consts.tmp.py b/src/codeplag/consts.tmp.py index a924fe1..21065a7 100644 --- a/src/codeplag/consts.tmp.py +++ b/src/codeplag/consts.tmp.py @@ -7,6 +7,7 @@ Extension, Extensions, Language, + LogLevel, Mode, ReportsExtension, ReportType, @@ -30,6 +31,7 @@ DEFAULT_THRESHOLD: Final[Threshold] = 65 DEFAULT_WEIGHTS: Final[tuple[float, float, float, float]] = (1.0, 0.4, 0.4, 0.4) DEFAULT_LANGUAGE: Final[Language] = "en" +DEFAULT_LOG_LEVEL: Final[LogLevel] = "info" DEFAULT_REPORT_EXTENSION: Final[ReportsExtension] = "csv" DEFAULT_GENERAL_REPORT_NAME: Final[str] = "report.html" DEFAULT_SOURCES_REPORT_NAME: Final[str] = "sources.html" @@ -67,6 +69,7 @@ ) EXTENSION_CHOICE: Final[tuple[Extension, ...]] = get_args(Extension) LANGUAGE_CHOICE: Final[tuple[Language, ...]] = get_args(Language) +LOG_LEVEL_CHOICE: Final[tuple[LogLevel, ...]] = get_args(LogLevel) WORKERS_CHOICE: Final[list[int]] = list(range(1, DEFAULT_WORKERS + 1)) REPORT_TYPE_CHOICE: Final[tuple[ReportType, ...]] = get_args(ReportType) # ======= diff --git a/src/codeplag/handlers/check.py b/src/codeplag/handlers/check.py index e5517ee..a51c43d 100644 --- a/src/codeplag/handlers/check.py +++ b/src/codeplag/handlers/check.py @@ -146,7 +146,7 @@ def check( github_project_folders = [] logger.debug( - f"Mode: {self.mode}; " f"Extension: {self.features_getter.extension}." + "Mode: %s; Extension: %s.", self.mode, self.features_getter.extension ) begin_time = monotonic() features_from_files = self.features_getter.get_from_files(files) @@ -171,7 +171,7 @@ def check( github_project_folders, github_user, ) - logger.debug(f"Time for all {monotonic() - begin_time:.2f}s") + logger.debug("Time for all %.2fs.", monotonic() - begin_time) logger.info("Ending searching for plagiarism ...") if isinstance(self.reporter, CSVReporter): self.reporter._write_df_to_fs() @@ -195,7 +195,13 @@ def __many_to_many_check( if self.show_progress: count_works = len(works) - self.progress = Progress(_calc_iterations(count_works)) + iterations = _calc_iterations(count_works) + logger.info( + "Works to be checked: %s; Number of checks: %s.", + count_works, + iterations, + ) + self.progress = Progress(iterations) with ProcessPoolExecutor(max_workers=self.workers) as executor: processed: list[ProcessingWorksInfo] = [] for i, work1 in enumerate(works): @@ -230,19 +236,27 @@ def __one_to_one_check( if self.show_progress: combined_elements = list(combined_elements) count_sequences = len(combined_elements) - self.progress = ComplexProgress( - _calc_iterations(count_sequences, self.mode) + iterations = _calc_iterations(count_sequences, self.mode) + logger.info( + "Work sequences to check: %s; Number of external checks: %s.", + count_sequences, + iterations, ) + self.progress = ComplexProgress(iterations) cases = combinations(combined_elements, r=2) with ProcessPoolExecutor(max_workers=self.workers) as executor: processed: list[ProcessingWorksInfo] = [] - for case in cases: + for internal_iteration, case in enumerate(cases, start=1): first_sequence, second_sequence = case if self.progress is not None: assert isinstance(self.progress, ComplexProgress) - self.progress.add_internal_progress( - len(first_sequence) * len(second_sequence) + internal_iterations = len(first_sequence) * len(second_sequence) + logger.debug( + "Internal iteration: %s; Number of internal checks: %s.", + internal_iteration, + internal_iterations, ) + self.progress.add_internal_progress(internal_iterations) for work1 in first_sequence: for work2 in second_sequence: self._do_step(executor, processed, work1, work2) diff --git a/src/codeplag/logger.py b/src/codeplag/logger.py index 48a7835..14608e5 100644 --- a/src/codeplag/logger.py +++ b/src/codeplag/logger.py @@ -2,8 +2,9 @@ import sys from pathlib import Path -from codeplag.consts import UTIL_NAME +from codeplag.consts import DEFAULT_LOG_LEVEL, UTIL_NAME from codeplag.display import clear_line, error, info, red_bold, warning +from codeplag.types import LogLevel class StreamFormatter(logging.Formatter): @@ -71,13 +72,14 @@ def filter(self, record: logging.LogRecord) -> bool: return stdout_handler -def set_handlers(logger: logging.Logger, filename: Path, verbose: bool = False) -> None: - if verbose: - logger.setLevel(logging.DEBUG) - else: - logger.setLevel(logging.INFO) +def set_handlers( + logger: logging.Logger, filename: Path, log_level: LogLevel = DEFAULT_LOG_LEVEL +) -> None: + levelno = getattr(logging, log_level.upper()) + logger.setLevel(levelno) logger.addHandler(get_file_handler(filename)) - logger.addHandler(get_stdout_handler()) + if levelno in [logging.INFO, logging.DEBUG]: + logger.addHandler(get_stdout_handler()) logger.addHandler(get_stderr_handler()) diff --git a/src/codeplag/types.py b/src/codeplag/types.py index caa00ca..0f79e29 100644 --- a/src/codeplag/types.py +++ b/src/codeplag/types.py @@ -21,6 +21,7 @@ ReportsExtension = Literal["json", "csv"] ReportType = Literal["general", "sources"] Language = Literal["en", "ru"] +LogLevel = Literal["debug", "info", "warning", "error"] # fmt: off Threshold = Literal[ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, @@ -143,6 +144,7 @@ class CLIException(Exception): class Settings(TypedDict): environment: NotRequired[Path] language: Language + log_level: LogLevel reports: NotRequired[Path] reports_extension: ReportsExtension show_progress: Flag diff --git a/test/auto/conftest.py b/test/auto/conftest.py index 9e77530..26a5904 100644 --- a/test/auto/conftest.py +++ b/test/auto/conftest.py @@ -4,6 +4,7 @@ import pytest from const import REPORTS_FOLDER +from utils import modify_settings @pytest.fixture @@ -15,3 +16,8 @@ def create_reports_folder(): yield shutil.rmtree(REPORTS_FOLDER) + + +@pytest.fixture(scope="session", autouse=True) +def set_logging_level(): + modify_settings(log_level="debug") diff --git a/test/auto/functional/test_settings.py b/test/auto/functional/test_settings.py index 2e71db5..48b7bd4 100644 --- a/test/auto/functional/test_settings.py +++ b/test/auto/functional/test_settings.py @@ -5,7 +5,7 @@ import pytest from codeplag.consts import CONFIG_PATH, UTIL_NAME -from codeplag.types import Language, ReportsExtension, Threshold +from codeplag.types import Language, LogLevel, ReportsExtension, Threshold from utils import modify_settings @@ -14,15 +14,16 @@ def teardown(): yield CONFIG_PATH.write_text("{}") + modify_settings(log_level="debug") class TestSettingsModify: @pytest.mark.parametrize( - "env,reports,threshold,show_progress,reports_extension,language,workers", + "env,reports,threshold,show_progress,reports_extension,language,log_level,workers", [ - (f"src/{UTIL_NAME}/types.py", "src", 83, 0, "json", "en", 1), - ("setup.py", "test", 67, 1, "csv", "ru", os.cpu_count() or 1), - (f"src/{UTIL_NAME}/utils.py", "debian", 93, 0, "json", "en", 1), + (f"src/{UTIL_NAME}/types.py", "src", 83, 0, "json", "en", "debug", 1), + ("setup.py", "test", 67, 1, "csv", "ru", "info", os.cpu_count() or 1), + (f"src/{UTIL_NAME}/utils.py", "debian", 93, 0, "json", "en", "warning", 1), ], ) def test_modify_settings( @@ -33,6 +34,7 @@ def test_modify_settings( show_progress: Literal[0, 1], reports_extension: ReportsExtension, language: Language, + log_level: LogLevel, workers: int, ): result = modify_settings( @@ -42,6 +44,7 @@ def test_modify_settings( show_progress=show_progress, reports_extension=reports_extension, language=language, + log_level=log_level, workers=workers, ) result.assert_success() @@ -53,25 +56,30 @@ def test_modify_settings( "show_progress": show_progress, "workers": workers, "language": language, + "log_level": log_level, "reports_extension": reports_extension, } @pytest.mark.parametrize( - "env, reports, threshold", + "env,reports,threshold,log_level", [ - (".env", "src", 101), - ("setup.py", "test983hskdfue", 67), - (f"src/{UTIL_NAME}/utils.pyjlsieuow0", "debian", 93), + (".env", "src", 101, "debug"), + ("setup.py", "test983hskdfue", 67, "info"), + (f"src/{UTIL_NAME}/utils.pyjlsieuow0", "debian", 93, "warning"), + (f"src/{UTIL_NAME}/types.py", "src", 83, "foobar"), ], ids=[ "Incorrect threshold.", "Path to reports doesn't exists.", "Path to environment doesn't exists.", + "Invalid log level.", ], ) - def test_modify_settings_with_invalid_arguments(self, env, reports, threshold): + def test_modify_settings_with_invalid_arguments( + self, env: str, reports: str, threshold: Threshold, log_level: LogLevel + ): modify_settings( - environment=env, reports=reports, threshold=threshold + environment=env, reports=reports, threshold=threshold, log_level=log_level ).assert_failed() def test_modify_settings_with_no_arguments_failed(self): diff --git a/test/auto/functional/test_stream_log.py b/test/auto/functional/test_stream_log.py index 8417bf7..ee945b6 100644 --- a/test/auto/functional/test_stream_log.py +++ b/test/auto/functional/test_stream_log.py @@ -4,7 +4,7 @@ def test_splitted_streams(): # Try to get a file that does not exist github_file = "https://github.com/OSLL/code-plagiarism/blob/main/skfjkljflsd" - result = run_check(["--github-files", github_file], extension="cpp", verbose=True) + result = run_check(["--github-files", github_file], extension="cpp") stdout = result.cmd_res.stdout.decode("utf-8") stderr = result.cmd_res.stderr.decode("utf-8") diff --git a/test/auto/utils.py b/test/auto/utils.py index e52180d..24ddbcc 100644 --- a/test/auto/utils.py +++ b/test/auto/utils.py @@ -3,7 +3,14 @@ from typing import Any, Literal from codeplag.consts import UTIL_NAME -from codeplag.types import Flag, Language, ReportsExtension, ReportType, Threshold +from codeplag.types import ( + Flag, + Language, + LogLevel, + ReportsExtension, + ReportType, + Threshold, +) class CmdResult: @@ -26,16 +33,14 @@ def run_cmd(cmd: list[str]) -> CmdResult: def run_util( cmd: list[str], root: Literal["check", "settings", "report"] | None = None, - verbose: bool = True, ) -> CmdResult: - verbose_opt = ["--verbose"] if verbose else [] root_cmd = [] if root is None else [root] - return run_cmd([UTIL_NAME] + verbose_opt + root_cmd + cmd) + return run_cmd([UTIL_NAME] + root_cmd + cmd) -def run_check(cmd: list[str], extension: str = "py", verbose: bool = True) -> CmdResult: - return run_util(["--extension", extension] + cmd, root="check", verbose=verbose) +def run_check(cmd: list[str], extension: str = "py") -> CmdResult: + return run_util(["--extension", extension] + cmd, root="check") def create_report(path: Path, report_type: ReportType) -> CmdResult: @@ -51,6 +56,7 @@ def modify_settings( show_progress: Flag | None = None, reports_extension: ReportsExtension | None = None, language: Language | None = None, + log_level: LogLevel | None = None, workers: int | None = None, ) -> CmdResult: def create_opt(key: str, value: Any | None) -> list[str]: @@ -64,6 +70,7 @@ def create_opt(key: str, value: Any | None) -> list[str]: + create_opt("show_progress", show_progress) + create_opt("reports_extension", reports_extension) + create_opt("language", language) + + create_opt("log-level", log_level) + create_opt("workers", workers), root="settings", ) diff --git a/test/unit/codeplag/test_config.py b/test/unit/codeplag/test_config.py index 2299f3f..07dfd35 100644 --- a/test/unit/codeplag/test_config.py +++ b/test/unit/codeplag/test_config.py @@ -115,6 +115,7 @@ def test_read_default_settings_conf(settings_config: Settings | None): "show_progress": 0, "reports_extension": "csv", "language": "en", + "log_level": "info", "workers": os.cpu_count() or 1, }, ], @@ -125,6 +126,7 @@ def test_read_default_settings_conf(settings_config: Settings | None): "show_progress": 1, "reports_extension": "json", "language": "ru", + "log_level": "error", "workers": 128, }, { @@ -133,6 +135,7 @@ def test_read_default_settings_conf(settings_config: Settings | None): "show_progress": 1, "reports_extension": "json", "language": "ru", + "log_level": "error", "workers": 128, }, ], @@ -144,6 +147,7 @@ def test_read_default_settings_conf(settings_config: Settings | None): "show_progress": 0, "reports_extension": "csv", "language": "en", + "log_level": "info", "workers": os.cpu_count() or 1, }, ],