From 984eea6b7f496ffe268b77bfa4dcd7ea076f8157 Mon Sep 17 00:00:00 2001 From: Kristinita Date: Fri, 3 Aug 2018 21:10:49 +0300 Subject: [PATCH 1/2] feat(encoding): migrate from Cyrillic 1251 to UTF-8 Because Eric 1.0 in UTF-8 --- erichek/__main__.py | 190 +++++++++--------- erichek/eric_asterisks.py | 234 +++++++++++----------- erichek/eric_body.py | 174 ++++++++-------- erichek/eric_config.py | 4 +- erichek/eric_encoding.py | 254 +++++++++++++----------- erichek/eric_head.py | 408 +++++++++++++++++++------------------- 6 files changed, 643 insertions(+), 621 deletions(-) diff --git a/erichek/__main__.py b/erichek/__main__.py index 34eb5e4..a855470 100644 --- a/erichek/__main__.py +++ b/erichek/__main__.py @@ -1,95 +1,95 @@ -# -*- coding: utf-8 -*- -# @Author: SashaChernykh -# @Date: 2018-01-22 07:32:05 -# @Last Modified time: 2018-02-01 19:15:27 -"""Run tests. - -Main file for running Erichek tests. -""" - -import erichek.eric_asterisks as eric_asterisks -import erichek.eric_body as eric_body -import erichek.eric_encoding as eric_encoding -import erichek.eric_head as eric_head -import logbook - -from clize import run -from erichek.eric_config import clize_log_level -from erichek.eric_config import v -from erichek.eric_config import version - -# Pyfancy — output color highighting -# Disabled green background, because bad color in AppVeyor -# https://github.com/appveyor/ci/issues/1138#issuecomment-355525721 -# Import class, not a module -# https://stackoverflow.com/a/4534443/5951529 -from pyfancy.pyfancy import pyfancy - -# ASCII-art printing -# [BUG] ASCII-ART output, when --help or --version -# https://github.com/epsy/clize/issues/38#issue-290426111 -# https://stackoverflow.com/a/9638532/5951529 -# import sys -# from colorama import init -# from pyfiglet import figlet_format -# from termcolor import cprint - -# strip colors if stdout is redirected -# init(strip=not sys.stdout.isatty()) - -LOG = logbook.Logger("summary logbook") - - -def red_foreground(redtext): - """Red foreground for error messages. - - Red foreground for error messages. - - Arguments: - redtext {str} -- text, which will be colored in red. - """ - LOG.error(pyfancy().red().bold(redtext)) - - -def green_foreground(greentext): - """Green foreground for notice messages. - - Green foreground for error messages. - - Arguments: - greentext {str} -- text, which will be colored in green. - """ - LOG.notice(pyfancy().green().bold(greentext)) - - -def main(): - """Run Erichek. - - Run all modules of Erichek. - If no errors — validation success, - Else — exit(1). - """ - run(clize_log_level, alt=[version, v], exit=False) - eric_encoding.eric_encoding_summary() - eric_body.eric_body_summary() - eric_asterisks.eric_asterisks_summary() - eric_head.eric_head_summary() - - # If all instead of multiple if and: - # https://stackoverflow.com/a/9504681/5951529 - if all([eric_body.BODY_EXIST, eric_encoding.ENCODING_WINDOWS_1251, eric_asterisks.ASTERISKS_EXISTS, - eric_head.HEAD_DATA]): - green_foreground( - "Congratulations! You haven't errors in your packages!") - # cprint(figlet_format('\nSuccess', font='starwars'), - # 'white', 'on_green', attrs=['bold']) - else: - red_foreground( - "You have errors in your packages. Please, fix them.") - # cprint(figlet_format('\nFailure', font='starwars'), - # 'yellow', 'on_red', attrs=['bold']) - exit(1) - - -if __name__ == '__main__': - main() +# -*- coding: utf-8 -*- +# @Author: SashaChernykh +# @Date: 2018-01-22 07:32:05 +# @Last Modified time: 2018-08-03 13:38:17 +"""Run tests. + +Main file for running Erichek tests. +""" + +import erichek.eric_asterisks as eric_asterisks +import erichek.eric_body as eric_body +import erichek.eric_encoding as eric_encoding +import erichek.eric_head as eric_head +import logbook + +from clize import run +from erichek.eric_config import clize_log_level +from erichek.eric_config import v +from erichek.eric_config import version + +# Pyfancy — output color highighting +# Disabled green background, because bad color in AppVeyor +# https://github.com/appveyor/ci/issues/1138#issuecomment-355525721 +# Import class, not a module +# https://stackoverflow.com/a/4534443/5951529 +from pyfancy.pyfancy import pyfancy + +# ASCII-art printing +# [BUG] ASCII-ART output, when --help or --version +# https://github.com/epsy/clize/issues/38#issue-290426111 +# https://stackoverflow.com/a/9638532/5951529 +# import sys +# from colorama import init +# from pyfiglet import figlet_format +# from termcolor import cprint + +# strip colors if stdout is redirected +# init(strip=not sys.stdout.isatty()) + +LOG = logbook.Logger("summary logbook") + + +def red_foreground(redtext): + """Red foreground for error messages. + + Red foreground for error messages. + + Arguments: + redtext {str} -- text, which will be colored in red. + """ + LOG.error(pyfancy().red().bold(redtext)) + + +def green_foreground(greentext): + """Green foreground for notice messages. + + Green foreground for error messages. + + Arguments: + greentext {str} -- text, which will be colored in green. + """ + LOG.notice(pyfancy().green().bold(greentext)) + + +def main(): + """Run Erichek. + + Run all modules of Erichek. + If no errors — validation success, + Else — exit(1). + """ + run(clize_log_level, alt=[version, v], exit=False) + eric_encoding.eric_encoding_summary() + eric_body.eric_body_summary() + eric_asterisks.eric_asterisks_summary() + eric_head.eric_head_summary() + + # If all instead of multiple if and: + # https://stackoverflow.com/a/9504681/5951529 + if all([eric_body.BODY_EXIST, eric_encoding.ENCODING_UTF_8, eric_asterisks.ASTERISKS_EXISTS, + eric_head.HEAD_DATA]): + green_foreground( + "Congratulations! You haven't errors in your packages!") + # cprint(figlet_format('\nSuccess', font='starwars'), + # 'white', 'on_green', attrs=['bold']) + else: + red_foreground( + "You have errors in your packages. Please, fix them.") + # cprint(figlet_format('\nFailure', font='starwars'), + # 'yellow', 'on_red', attrs=['bold']) + exit(1) + + +if __name__ == '__main__': + main() diff --git a/erichek/eric_asterisks.py b/erichek/eric_asterisks.py index 53f7d93..38abc57 100644 --- a/erichek/eric_asterisks.py +++ b/erichek/eric_asterisks.py @@ -1,117 +1,117 @@ -# -*- coding: utf-8 -*- -# @Author: SashaChernykh -# @Date: 2018-01-22 19:58:48 -# @Last Modified time: 2018-02-02 08:37:57 -"""Asterisks Checker. - -Check, if asterisks contains in each line of package for Eric room. - -Do not check: - 1. lines before and line with , - 2. . -""" -import logbook - -import os - -# Do not use «from import *» -# http://bit.ly/2CuW5GS -from pyfancy.pyfancy import pyfancy - -from erichek.eric_config import ALL_TXT_IN_ERIC_ROOM_WIHTOUT_SUBFOLDERS - - -LOG = logbook.Logger("eric_asterisks logbook") - -ASTERISKS_EXISTS = True - - -def red_foreground(redtext): - """Red foreground for error messages. - - Red foreground for error messages. - - Arguments: - redtext {str} -- text, which will be colored in red. - """ - LOG.error(pyfancy().red().bold(redtext)) - - -def green_foreground(greentext): - """Green foreground for notice messages. - - Green foreground for error messages. - - Arguments: - greentext {str} -- text, which will be colored in green. - """ - LOG.notice(pyfancy().green().bold(greentext)) - - -def eric_asterisks_function(): - """Check, contains asterisks in each line of a file, or no.""" - for filename in ALL_TXT_IN_ERIC_ROOM_WIHTOUT_SUBFOLDERS: - - filename_without_path = os.path.basename(filename) - # Lines to list - # https://stackoverflow.com/a/3277515/5951529 - with open(filename, encoding='windows-1251') as filename_as_list: - submit_file_as_list = filename_as_list.readlines() - # New list after - # https://stackoverflow.com/a/35880897/5951529 - # Except: if not contains, Erichek output ValueError. - # Propose to add . - try: - get_lines_with_body = submit_file_as_list.index('\n') - list_without_lines_with_body = submit_file_as_list[ - get_lines_with_body + 1:] - except ValueError: - green_foreground("If you see this message and, possibly, long output after them, " - "your file " + filename_without_path + " not contains . " - "Please, add to " + filename_without_path + " to correct place " - "and rerun erichek.") - # Check, that asterisks contains in full file - list_without_lines_with_body = submit_file_as_list - - # Remove list item, contains «. +""" +import logbook + +import os + +# Do not use «from import *» +# http://bit.ly/2CuW5GS +from pyfancy.pyfancy import pyfancy + +from erichek.eric_config import ALL_TXT_IN_ERIC_ROOM_WIHTOUT_SUBFOLDERS + + +LOG = logbook.Logger("eric_asterisks logbook") + +ASTERISKS_EXISTS = True + + +def red_foreground(redtext): + """Red foreground for error messages. + + Red foreground for error messages. + + Arguments: + redtext {str} -- text, which will be colored in red. + """ + LOG.error(pyfancy().red().bold(redtext)) + + +def green_foreground(greentext): + """Green foreground for notice messages. + + Green foreground for error messages. + + Arguments: + greentext {str} -- text, which will be colored in green. + """ + LOG.notice(pyfancy().green().bold(greentext)) + + +def eric_asterisks_function(): + """Check, contains asterisks in each line of a file, or no.""" + for filename in ALL_TXT_IN_ERIC_ROOM_WIHTOUT_SUBFOLDERS: + + filename_without_path = os.path.basename(filename) + # Lines to list + # https://stackoverflow.com/a/3277515/5951529 + with open(filename, encoding='utf-8') as filename_as_list: + submit_file_as_list = filename_as_list.readlines() + # New list after + # https://stackoverflow.com/a/35880897/5951529 + # Except: if not contains, Erichek output ValueError. + # Propose to add . + try: + get_lines_with_body = submit_file_as_list.index('\n') + list_without_lines_with_body = submit_file_as_list[ + get_lines_with_body + 1:] + except ValueError: + green_foreground("If you see this message and, possibly, long output after them, " + "your file " + filename_without_path + " not contains . " + "Please, add to " + filename_without_path + " to correct place " + "and rerun erichek.") + # Check, that asterisks contains in full file + list_without_lines_with_body = submit_file_as_list + + # Remove list item, contains «