add minimum string count
This commit is contained in:
		
							parent
							
								
									e1a28abc61
								
							
						
					
					
						commit
						5755e10212
					
				| 
						 | 
				
			
			@ -104,6 +104,8 @@ def send_command(connection: ConnectHandler, command: str) -> str:
 | 
			
		|||
        result = "NetmikoTimeoutException"
 | 
			
		||||
    except exceptions.ReadTimeout:
 | 
			
		||||
            result = "ReadTimeout"
 | 
			
		||||
    if len(result.split("\n")) < cfg.bcp.min_string_count:
 | 
			
		||||
        result = 'NotEnoughLines'
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -125,6 +127,9 @@ def save_mikrotik_bcp(host: str, name: str) -> None:
 | 
			
		|||
    elif result == "ReadTimeout":
 | 
			
		||||
        log.warning("Timeout read config from %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    elif result == "NotEnoughLines":
 | 
			
		||||
        log.warning("Small number of lines %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    result = "\n".join(result.split("\n")[1:])
 | 
			
		||||
    bcp_file_name, file_folder = get_bcp_file_path(name)
 | 
			
		||||
    with open(bcp_file_name, "w") as f:
 | 
			
		||||
| 
						 | 
				
			
			@ -150,6 +155,9 @@ def save_snr_bcp(host: str, name: str) -> None:
 | 
			
		|||
    elif result == "ReadTimeout":
 | 
			
		||||
        log.warning("Timeout read config from %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    elif result == "NotEnoughLines":
 | 
			
		||||
        log.warning("Small number of lines %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    bcp_file_name, file_folder = get_bcp_file_path(name)
 | 
			
		||||
    with open(bcp_file_name, "w") as f:
 | 
			
		||||
        f.write(result)
 | 
			
		||||
| 
						 | 
				
			
			@ -174,6 +182,9 @@ def save_cisco_sb_bcp(host: str, name: str) -> None:
 | 
			
		|||
    elif result == "ReadTimeout":
 | 
			
		||||
        log.warning("Timeout read config from %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    elif result == "NotEnoughLines":
 | 
			
		||||
        log.warning("Small number of lines %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    bcp_file_name, file_folder = get_bcp_file_path(name)
 | 
			
		||||
    with open(bcp_file_name, "w") as f:
 | 
			
		||||
        f.write(result)
 | 
			
		||||
| 
						 | 
				
			
			@ -198,6 +209,9 @@ def save_cisco_bcp(host: str, name: str) -> None:
 | 
			
		|||
    elif result == "ReadTimeout":
 | 
			
		||||
        log.warning("Timeout read config from %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    elif result == "NotEnoughLines":
 | 
			
		||||
        log.warning("Small number of lines %r", name)
 | 
			
		||||
        return
 | 
			
		||||
    bcp_file_name, file_folder = get_bcp_file_path(name)
 | 
			
		||||
    with open(bcp_file_name, "w") as f:
 | 
			
		||||
        f.write(result)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,6 +62,7 @@ class ConfigBcp:
 | 
			
		|||
    in_folder: bool = config["bcp"].getboolean("in_folder")
 | 
			
		||||
    if in_folder:
 | 
			
		||||
        folder_name_pattern: str = config["bcp"].get("folder_name_pattern")
 | 
			
		||||
    min_string_count: int = config["bcp"].getint("min_string_count")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@dataclass
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,7 +41,8 @@ start_at: 18:59
 | 
			
		|||
in_folder: True
 | 
			
		||||
# Регулярное выражение по которому будет парситься имя папки из названия девайса
 | 
			
		||||
folder_name_pattern: ^(.*?)-
 | 
			
		||||
 | 
			
		||||
# Если количество строк в конфиге меньше указанного значения - ошибка, изменения не записываются.
 | 
			
		||||
min_string_count: 50
 | 
			
		||||
 | 
			
		||||
[net_dev]
 | 
			
		||||
debug: False
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue