|
@@ -9,6 +9,9 @@ LIST_BAD_ADAPTER = ['Wireless', 'Bluetooth', 'Wireless', 'WiFi',
|
|
'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
|
|
'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
|
|
'1394', 'Mobile']
|
|
'1394', 'Mobile']
|
|
|
|
|
|
|
|
+# Количетсво интерфейсов по умолчанию
|
|
|
|
+COUNT_INTERFACE = 1
|
|
|
|
+
|
|
|
|
|
|
def check_correct_controller(name):
|
|
def check_correct_controller(name):
|
|
return any(ext not in name for ext in LIST_BAD_ADAPTER)
|
|
return any(ext not in name for ext in LIST_BAD_ADAPTER)
|
|
@@ -34,8 +37,8 @@ def convert_mb_to_gb(val):
|
|
|
|
|
|
def get_ser_motherboard(row):
|
|
def get_ser_motherboard(row):
|
|
if len(row) > 0:
|
|
if len(row) > 0:
|
|
- if row[0][6] != 'To be filled by O.E.M.':
|
|
|
|
- return row[0][6]
|
|
|
|
|
|
+ if row[6] not in ['To be filled by O.E.M.', 'Default string']:
|
|
|
|
+ return row[6]
|
|
else:
|
|
else:
|
|
return None
|
|
return None
|
|
else:
|
|
else:
|
|
@@ -43,42 +46,48 @@ def get_ser_motherboard(row):
|
|
|
|
|
|
|
|
|
|
def get_data_from_file(path, obj):
|
|
def get_data_from_file(path, obj):
|
|
|
|
+ global COUNT_INTERFACE
|
|
with open(path, 'r', encoding='utf-16') as file:
|
|
with open(path, 'r', encoding='utf-16') as file:
|
|
cs = csv.reader(file, delimiter=',')
|
|
cs = csv.reader(file, delimiter=',')
|
|
|
|
+
|
|
next(cs)
|
|
next(cs)
|
|
line_info_computers = next(cs)
|
|
line_info_computers = next(cs)
|
|
obj.os = line_info_computers[7]
|
|
obj.os = line_info_computers[7]
|
|
- obj.motherboard = get_ser_motherboard(
|
|
|
|
- [x for x in cs if x[0] == '6200'])
|
|
|
|
obj.cpu = line_info_computers[13]
|
|
obj.cpu = line_info_computers[13]
|
|
obj.ram = convert_mb_to_gb(line_info_computers[14])
|
|
obj.ram = convert_mb_to_gb(line_info_computers[14])
|
|
|
|
|
|
- network_params = [x for x in cs if len(
|
|
|
|
- x) > 2 and x[0] == '2600' and check_correct_controller(x[3])]
|
|
|
|
|
|
+ obj.ip1 = None
|
|
|
|
+ obj.mac1 = None
|
|
|
|
|
|
- if len(network_params) != 0:
|
|
|
|
- i = 1
|
|
|
|
- for network in network_params:
|
|
|
|
- setattr(obj, F'ip{i}', network[6].split(' ')[0])
|
|
|
|
- setattr(obj, F'mac{i}', network[-3])
|
|
|
|
- i += 1
|
|
|
|
- else:
|
|
|
|
- obj.ip1 = None
|
|
|
|
- obj.mac1 = None
|
|
|
|
|
|
+ count_interface = 0
|
|
|
|
+ for x in cs:
|
|
|
|
+ if x[0] == '6200':
|
|
|
|
+ obj.motherboard = get_ser_motherboard(x)
|
|
|
|
+
|
|
|
|
+ if x[0] == '2600' and check_correct_controller(x[3]) and len(x) > 2:
|
|
|
|
+ setattr(obj, F'ip{count_interface}', x[6].split(' ')[0])
|
|
|
|
+ setattr(obj, F'mac{count_interface}', x[-3])
|
|
|
|
+ count_interface += 1
|
|
|
|
+
|
|
|
|
+ # Увеличиваем значение если количестов интерфейсов больше в этой строке
|
|
|
|
+ obj.count_interface = count_interface
|
|
|
|
+ if count_interface > COUNT_INTERFACE:
|
|
|
|
+ COUNT_INTERFACE = count_interface
|
|
|
|
|
|
file.close()
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
def get_ready_information():
|
|
def get_ready_information():
|
|
- err_file = open(F"Error_file-{datetime.datetime.today().strftime('%Y-%m-%d-%H.%M.%S')}", "w")
|
|
|
|
|
|
+ err_file = open(
|
|
|
|
+ F"Error_file-{datetime.datetime.today().strftime('%Y-%m-%d-%H.%M.%S')}", "w")
|
|
list_objects = []
|
|
list_objects = []
|
|
for path in get_paths():
|
|
for path in get_paths():
|
|
-
|
|
|
|
|
|
+
|
|
obj = ObjectReady()
|
|
obj = ObjectReady()
|
|
obj.frame = path.split('/')[-2]
|
|
obj.frame = path.split('/')[-2]
|
|
obj.cabinet = re.findall(
|
|
obj.cabinet = re.findall(
|
|
r"\/([\w+?\ ?[а-яА-Я]+\ ?|\w+?\ ?[a-zA-Z]+\ ?|\d+])[\.|\,]", path)[-1]
|
|
r"\/([\w+?\ ?[а-яА-Я]+\ ?|\w+?\ ?[a-zA-Z]+\ ?|\d+])[\.|\,]", path)[-1]
|
|
-
|
|
|
|
|
|
+
|
|
try:
|
|
try:
|
|
get_data_from_file(path, obj)
|
|
get_data_from_file(path, obj)
|
|
except UnicodeDecodeError as ude:
|
|
except UnicodeDecodeError as ude:
|
|
@@ -91,16 +100,19 @@ def get_ready_information():
|
|
|
|
|
|
|
|
|
|
def create_csv(list_obj):
|
|
def create_csv(list_obj):
|
|
- max_index = max([(v.get_len_dict(), i) for i, v in enumerate(list_obj)])[1]
|
|
|
|
namefile = F"result-{datetime.datetime.today().strftime('%Y-%m-%d-%H.%M.%S')}"
|
|
namefile = F"result-{datetime.datetime.today().strftime('%Y-%m-%d-%H.%M.%S')}"
|
|
|
|
|
|
with open(F"{namefile}.csv", 'w', newline='') as f:
|
|
with open(F"{namefile}.csv", 'w', newline='') as f:
|
|
- name_fields = [v for v in list_obj[max_index].__dict__]
|
|
|
|
- writer = csv.DictWriter(f, fieldnames=name_fields,
|
|
|
|
- delimiter=';', quoting=csv.QUOTE_NONNUMERIC)
|
|
|
|
- writer.writeheader()
|
|
|
|
- [writer.writerow(elem.__dict__) for elem in list_obj]
|
|
|
|
- f.close()
|
|
|
|
|
|
+ header_csv = F"frame;cabinet;os;motherboard;cpu;ram{''.join([F';ip{i+1};mac{i+1}' for i in range(COUNT_INTERFACE)])}\n"
|
|
|
|
+ f.write(header_csv)
|
|
|
|
+
|
|
|
|
+ for obj in list_obj:
|
|
|
|
+ dic = obj.__dict__
|
|
|
|
+ try:
|
|
|
|
+ row_interface = ';'.join([F'{dic[F"ip{i}"]};{dic[F"mac{i}"]}' for i in range(obj.count_interface)])
|
|
|
|
+ f.write(F'"{dic["frame"]}";"{dic["cabinet"]}";"{dic["os"]}";"{dic["motherboard"]}";"{dic["cpu"]}";"{dic["ram"]}";{row_interface}\n')
|
|
|
|
+ except AttributeError:
|
|
|
|
+ f.write(F'"{obj.frame}";"{obj.cabinet}"\n')
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|