🔊 Add variable messages in logs

relate to forga/process/fr/embarquement#6
This commit is contained in:
freezed 2021-04-18 23:30:17 +02:00
parent f00187f4ea
commit bd949c2075
1 changed files with 7 additions and 7 deletions

View File

@ -13,11 +13,12 @@ The goal is to build durable python script using standard library
This script compute the greater common divisor of 2 integrers This script compute the greater common divisor of 2 integrers
""" """
import logging import logging
import sys
# MESSAGES # MESSAGES
FUNCTION_CALL = "Function is called" FUNCTION_CALL = "Function `%s` is called"
SUBSTRACTION_MADE = "Substraction made" SUBSTRACTION_MADE = "Substraction made: %s - %s"
WRONG_INPUT_ORDER = "Inputs in ascending order" WRONG_INPUT_ORDER = "Revert input order (`%s < %s`)"
def pgcd(input_a, input_b): def pgcd(input_a, input_b):
@ -35,14 +36,14 @@ def pgcd(input_a, input_b):
>>> pgcd(910, 42) >>> pgcd(910, 42)
14 14
""" """
logging.info(FUNCTION_CALL) logging.info(FUNCTION_CALL, "pgcd")
rest = input_a - input_b rest = input_a - input_b
check = input_b - rest check = input_b - rest
while check != 0: while check != 0:
logging.debug(SUBSTRACTION_MADE)
input_a = max(input_b, rest) input_a = max(input_b, rest)
input_b = min(input_b, rest) input_b = min(input_b, rest)
logging.debug(SUBSTRACTION_MADE, input_a, input_b)
rest = input_a - input_b rest = input_a - input_b
check = max(input_b, rest) - min(input_b, rest) check = max(input_b, rest) - min(input_b, rest)
@ -58,7 +59,6 @@ if __name__ == "__main__":
# ARGUMENTS, PARAMETERS & OPTIONS # ARGUMENTS, PARAMETERS & OPTIONS
import argparse import argparse
import sys
PARSER = argparse.ArgumentParser( PARSER = argparse.ArgumentParser(
description=sys.modules[__name__].__doc__, description=sys.modules[__name__].__doc__,
@ -74,7 +74,7 @@ if __name__ == "__main__":
# CHECKS INPUTS # CHECKS INPUTS
if ARGS.INPUT_A <= ARGS.INPUT_B: if ARGS.INPUT_A <= ARGS.INPUT_B:
logging.critical(WRONG_INPUT_ORDER) logging.critical(WRONG_INPUT_ORDER, ARGS.INPUT_A, ARGS.INPUT_B)
sys.exit() sys.exit()
# DO THE JOB # DO THE JOB