<s> import argparse <EOL> import logging <EOL> from preferences_editor import PreferencesEditor <EOL> import sys <EOL> DEBUG = "<STR_LIT>" <EOL> DETECTION_RATE = "<STR_LIT>" <EOL> LASER_INTENSITY = "<STR_LIT>" <EOL> MARKER_RADIUS = "<STR_LIT>" <EOL> IGNORE_LASER_COLOR = "<STR_LIT>" <EOL> USE_VIRTUAL_MAGAZINE = "<STR_LIT>" <EOL> VIRTUAL_MAGAZINE = "<STR_LIT>" <EOL> USE_MALFUNCTIONS = "<STR_LIT>" <EOL> MALFUNCTION_PROBABILITY = "<STR_LIT>" <EOL> VIDCAM = "<STR_LIT>" <EOL> class Configurator ( ) : <EOL> def _check_rate ( self , rate ) : <EOL> value = int ( rate ) <EOL> if value < <NUM_LIT:1> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def _check_intensity ( self , intensity ) : <EOL> value = int ( intensity ) <EOL> if value < <NUM_LIT:1> or value > <NUM_LIT:255> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def _check_radius ( self , radius ) : <EOL> value = int ( radius ) <EOL> if value < <NUM_LIT:1> or value > <NUM_LIT:20> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def _check_vidcam ( self , vidcam ) : <EOL> value = int ( vidcam ) <EOL> if value < <NUM_LIT:0> or value > <NUM_LIT:2> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def _check_ignore_laser_color ( self , ignore_laser_color ) : <EOL> ignore_laser_color = ignore_laser_color . lower ( ) <EOL> if ignore_laser_color != "<STR_LIT>" and ignore_laser_color != "<STR_LIT>" : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return ignore_laser_color <EOL> def _check_virtual_magazine ( self , virtual_magazine ) : <EOL> value = int ( virtual_magazine ) <EOL> if value < <NUM_LIT:1> or value > <NUM_LIT> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def _check_malfunctions ( self , malfunctions ) : <EOL> value = float ( malfunctions ) <EOL> if value < <NUM_LIT> or value > <NUM_LIT> : <EOL> raise argparse . ArgumentTypeError ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return value <EOL> def __init__ ( self ) : <EOL> self . _logger = None <EOL> config , preferences = PreferencesEditor . map_configuration ( ) <EOL> parser = argparse . ArgumentParser ( prog = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = self . _check_rate , <EOL> help = "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = self . _check_intensity , <EOL> help = "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = self . _check_radius , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = self . _check_vidcam , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> type = self . _check_ignore_laser_color , <EOL> help = "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> type = self . _check_virtual_magazine , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> type = self . _check_malfunctions , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> preferences [ DEBUG ] = args . debug <EOL> if args . detection_rate : <EOL> preferences [ DETECTION_RATE ] = int ( args . detection_rate ) <EOL> if args . laser_intensity : <EOL> preferences [ LASER_INTENSITY ] = int ( args . laser_intensity ) <EOL> if args . marker_radius : <EOL> preferences [ MARKER_RADIUS ] = int ( args . marker_radius ) <EOL> if args . vidcam >= <NUM_LIT:0> : <EOL> preferences [ VIDCAM ] = int ( args . vidcam ) <EOL> if args . ignore_laser_color : <EOL> preferences [ IGNORE_LASER_COLOR ] = args . ignore_laser_color <EOL> if args . use_virtual_magazine : <EOL> preferences [ USE_VIRTUAL_MAGAZINE ] = True <EOL> preferences [ VIRTUAL_MAGAZINE ] = int ( args . use_virtual_magazine ) <EOL> if args . use_malfunctions : <EOL> preferences [ USE_MALFUNCTIONS ] = True <EOL> preferences [ MALFUNCTION_PROBABILITY ] = float ( args . use_malfunctions ) <EOL> self . _preferences = preferences <EOL> self . _config_parser = config <EOL> def get_preferences ( self ) : <EOL> return self . _preferences <EOL> def get_config_parser ( self ) : <EOL> return self . _config_parser <EOL> def get_logger ( self ) : <EOL> if self . _logger is None : <EOL> self . _logger = self . _make_logger ( ) <EOL> return self . _logger <EOL> def _make_logger ( self ) : <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> stdhandler = logging . StreamHandler ( sys . stdout ) <EOL> if self . _preferences [ DEBUG ] : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> else : <EOL> logger . setLevel ( logging . INFO ) <EOL> formatter = logging . Formatter ( <EOL> '<STR_LIT>' ) <EOL> stdhandler . setFormatter ( formatter ) <EOL> logger . addHandler ( stdhandler ) <EOL> return logger </s>
