|
@@ -5,12 +5,12 @@ import argparse
|
|
|
from logger import *
|
|
|
from datetime import datetime
|
|
|
import pandas as pd
|
|
|
-
|
|
|
+from tqdm import tqdm
|
|
|
ARGS = None
|
|
|
|
|
|
parse = argparse.ArgumentParser(
|
|
|
- description="Программа для сбора информации из csv файлов")
|
|
|
-
|
|
|
+ description="Программа для сбора информации из csv файлов")
|
|
|
+
|
|
|
parse.add_argument('-p', '--path', help='Указать в какой директории искать',
|
|
|
default=os.path.dirname(sys.argv[0]))
|
|
|
parse.add_argument('-e', '--open_encoding',
|
|
@@ -18,7 +18,6 @@ parse.add_argument('-e', '--open_encoding',
|
|
|
parse.add_argument('-d', '--delimiter', help='разделитель csv', default=',')
|
|
|
|
|
|
|
|
|
-
|
|
|
LIST_BAD_ADAPTER = ['Wireless', 'Bluetooth', 'Wireless', 'WiFi',
|
|
|
'Kaspersky', 'VirtualBox', 'TAP-Windows',
|
|
|
'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
|
|
@@ -33,14 +32,15 @@ def check_correct_controller(name) -> bool:
|
|
|
|
|
|
|
|
|
class ObjectReady:
|
|
|
- frame: str = None
|
|
|
- cabinet: str = None
|
|
|
- os: str = None
|
|
|
- cpu: str = None
|
|
|
- ram: str = None
|
|
|
- motherboard: str = None
|
|
|
- count_interface: int = 0
|
|
|
- path: str = None
|
|
|
+
|
|
|
+ def __init__(self) -> None:
|
|
|
+ self.frame: str = None
|
|
|
+ self.cabinet: str = None
|
|
|
+ self.os: str = None
|
|
|
+ self.cpu: str = None
|
|
|
+ self.ram: str = None
|
|
|
+ self.motherboard: str = None
|
|
|
+ self.count_interface: int = 0
|
|
|
|
|
|
def get_len_dict(self) -> int:
|
|
|
return len(self.__dict__)
|
|
@@ -71,45 +71,43 @@ def get_ser_motherboard(row: list) -> str:
|
|
|
|
|
|
def get_data_from_file(path: str, obj: ObjectReady) -> None:
|
|
|
global COUNT_INTERFACE
|
|
|
-
|
|
|
- with open(path, 'r', encoding=args.open_encoding) as file:
|
|
|
-
|
|
|
- cs = csv.reader(file, delimiter=',')
|
|
|
|
|
|
- next(cs)
|
|
|
- line_info_computers = next(cs)
|
|
|
- obj.os = line_info_computers[7]
|
|
|
- obj.cpu = line_info_computers[13]
|
|
|
- obj.ram = convert_mb_to_gb(line_info_computers[14])
|
|
|
- obj.motherboard = None
|
|
|
- obj.count_interface = 0
|
|
|
+ with open(path, 'r', encoding=ARGS.open_encoding) as file:
|
|
|
+ cs = csv.reader(file, delimiter=',')
|
|
|
count_interface = 0
|
|
|
-
|
|
|
+
|
|
|
for line in cs:
|
|
|
data = list(pd.Series(line))
|
|
|
- if data[0] == '6200':
|
|
|
- obj.motherboard = get_ser_motherboard(data[6])
|
|
|
-
|
|
|
- if data[0] == '2600' and len(data) > 2 and check_correct_controller(data[3]):
|
|
|
- setattr(obj, F'ip{count_interface+1}', data[6].split(' ')[0])
|
|
|
- setattr(obj, F'mac{count_interface+1}', data[-3])
|
|
|
- count_interface += 1
|
|
|
+ match data[0]:
|
|
|
+ case '300':
|
|
|
+ obj.os = data[7]
|
|
|
+ obj.cpu = data[13]
|
|
|
+ obj.ram = convert_mb_to_gb(data[14])
|
|
|
+ case '6200':
|
|
|
+ obj.motherboard = get_ser_motherboard(data[6])
|
|
|
+ case '2600':
|
|
|
+ if len(data) > 2 and check_correct_controller(data[3]):
|
|
|
+ setattr(obj, F'ip{count_interface+1}',
|
|
|
+ data[6].split(' ')[0])
|
|
|
+ setattr(obj, F'mac{count_interface+1}', data[-3])
|
|
|
+ count_interface += 1
|
|
|
+ case _: continue
|
|
|
|
|
|
# Увеличиваем значение если количестов интерфейсов больше в этой строке
|
|
|
obj.count_interface = count_interface
|
|
|
if count_interface > COUNT_INTERFACE:
|
|
|
COUNT_INTERFACE = count_interface
|
|
|
|
|
|
- file.close()
|
|
|
-
|
|
|
|
|
|
def get_ready_information() -> list[ObjectReady]:
|
|
|
list_objects = []
|
|
|
- for path in get_paths():
|
|
|
-
|
|
|
+ paths = get_paths()
|
|
|
+
|
|
|
+ progressbar = tqdm(range(0, len(paths)), desc='Progress')
|
|
|
+ for path in paths:
|
|
|
+
|
|
|
obj = ObjectReady()
|
|
|
obj.frame = os.path.basename(os.path.dirname(path))
|
|
|
- obj.path = path
|
|
|
|
|
|
try:
|
|
|
obj.cabinet = str(os.path.basename(path)).split('.')[0]
|
|
@@ -128,6 +126,7 @@ def get_ready_information() -> list[ObjectReady]:
|
|
|
logger.error(F"{path} --> Пустой файл или тмпо того")
|
|
|
|
|
|
list_objects.append(obj)
|
|
|
+ progressbar.update(1)
|
|
|
return list_objects
|
|
|
|
|
|
|
|
@@ -142,17 +141,20 @@ def create_csv(list_obj: list[ObjectReady]) -> None:
|
|
|
namefile = F"result-{datetime.today().strftime('%Y-%m-%d-%H.%M.%S')}.xlsx"
|
|
|
data = [row.get_row() for row in list_obj]
|
|
|
df = pd.DataFrame(data=data)
|
|
|
- df.to_excel(namefile, index= False)
|
|
|
-
|
|
|
+ df.to_excel(namefile, index=False)
|
|
|
+
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
- logger.info("Start programm")
|
|
|
-
|
|
|
try:
|
|
|
- ARGS = parse.parse_args(sys.argv[1:])
|
|
|
- except argparse.ArgumentError:
|
|
|
- parse.print_help()
|
|
|
- create_logger()
|
|
|
- logger.info(F"Base dir: {ARGS.path}")
|
|
|
- create_csv(get_ready_information())
|
|
|
-
|
|
|
- logger.info("Stop programm")
|
|
|
+ logger.info("Start programm")
|
|
|
+
|
|
|
+ try:
|
|
|
+ ARGS = parse.parse_args(sys.argv[1:])
|
|
|
+ except argparse.ArgumentError:
|
|
|
+ parse.print_help()
|
|
|
+ create_logger()
|
|
|
+ logger.info(F"Base dir: {ARGS.path}")
|
|
|
+ create_csv(get_ready_information())
|
|
|
+ logger.info("Stop programm")
|
|
|
+ except KeyboardInterrupt:
|
|
|
+ logger.info("Отмена операции")
|