Alex Sidorov 1 anno fa
parent
commit
946127f174
2 ha cambiato i file con 15 aggiunte e 13 eliminazioni
  1. 2 3
      logger.py
  2. 13 10
      main.py

+ 2 - 3
logger.py

@@ -1,11 +1,10 @@
-import os
+import os, sys
 from datetime import datetime
 from datetime import datetime
 import logging
 import logging
 
 
 def create_logger():
 def create_logger():
     now = datetime.now()
     now = datetime.now()
-    file_log = os.path.join(os.path.dirname(__file__), F'logs_{now.year}{now.month}{now.day}.log')
-    print(file_log)
+    file_log = os.path.join(os.path.dirname(sys.argv[0]), F'logs_{now.year}{now.month}{now.day}.log')
     logging.basicConfig(filename=file_log,
     logging.basicConfig(filename=file_log,
                         encoding='utf-8',
                         encoding='utf-8',
                         level=logging.DEBUG,
                         level=logging.DEBUG,

+ 13 - 10
main.py

@@ -1,25 +1,20 @@
-import csv
-import os
-import re
-import datetime
-import argparse
+import csv, os, re, sys, argparse
 from logger import *
 from logger import *
 from datetime import datetime
 from datetime import datetime
 
 
 
 
-
+   
 parse = argparse.ArgumentParser(
 parse = argparse.ArgumentParser(
     description="Программа для сбора информации из csv файлов")
     description="Программа для сбора информации из csv файлов")
 parse.add_argument('-p', '--path', help='Указать в какой директории искать',
 parse.add_argument('-p', '--path', help='Указать в какой директории искать',
-                   default=os.path.dirname(__file__))
+                   default=os.path.dirname(sys.argv[0]))
 parse.add_argument('-e', '--encoding',
 parse.add_argument('-e', '--encoding',
-                   help='Указать в какой кодировке сохранять', default='utf-8')
+                   help='Указать в какой кодировке сохранять', default='windows-1251')
 parse.add_argument('-s', '--open_encoding',
 parse.add_argument('-s', '--open_encoding',
                    help='Указать в какой кодировке открывать', default='utf-16')
                    help='Указать в какой кодировке открывать', default='utf-16')
 args = parse.parse_args()
 args = parse.parse_args()
 
 
 print(args)
 print(args)
-# DIR_WORK = "./sbor"
 LIST_BAD_ADAPTER = ['Wireless', 'Bluetooth', 'Wireless', 'WiFi',
 LIST_BAD_ADAPTER = ['Wireless', 'Bluetooth', 'Wireless', 'WiFi',
                     'Kaspersky', 'VirtualBox', 'TAP-Windows',
                     'Kaspersky', 'VirtualBox', 'TAP-Windows',
                     'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
                     'Wintun', '802.11', 'VMware', 'VPN', 'Wi-Fi',
@@ -42,6 +37,7 @@ class ObjectReady:
             return ';'.join((self.frame, self.cabinet))
             return ';'.join((self.frame, self.cabinet))
 
 
         dic = self.__dict__
         dic = self.__dict__
+        # print(dic)
         try:
         try:
             row_interface = ';'.join(
             row_interface = ';'.join(
                 [';'.join((dic.get(F"ip{i}"), dic.get(F"mac{i}"))) for i in range(self.count_interface)
                 [';'.join((dic.get(F"ip{i}"), dic.get(F"mac{i}"))) for i in range(self.count_interface)
@@ -113,7 +109,7 @@ def get_ready_information() -> list[ObjectReady]:
     for path in get_paths():
     for path in get_paths():
 
 
         obj = ObjectReady()
         obj = ObjectReady()
-        obj.frame = path.split('/')[-2]
+        obj.frame = os.path.basename(os.path.dirname(path))
         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]
 
 
@@ -138,9 +134,16 @@ def create_csv(list_obj: list[ObjectReady]) -> None:
         f.write(header_csv)
         f.write(header_csv)
 
 
         for obj in list_obj:
         for obj in list_obj:
+            row = obj.get_csv_row()
+            logger.info(row)
             f.write(obj.get_csv_row())
             f.write(obj.get_csv_row())
             
             
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     create_logger()
     create_logger()
+    
+    logger.info("Start programm")
+    logger.info(F"Base dir: {args.path}")
+    
     create_csv(get_ready_information())
     create_csv(get_ready_information())
+    logger.info("Stop programm")