Parcourir la source

Move setting of output directory up and store it in Utility

Determining the output directory before the creation of the attacks
and storing it globally makes that directory available to the
attacks so that they can save miscellaneous output files there.
dustin.born il y a 6 ans
Parent
commit
e304c64611
2 fichiers modifiés avec 6 ajouts et 3 suppressions
  1. 5 3
      code/Core/Controller.py
  2. 1 0
      code/ID2TLib/Utility.py

+ 5 - 3
code/Core/Controller.py

@@ -36,6 +36,10 @@ class Controller:
         self.statisticsDB = self.statistics.get_statistics_database()
         self.statisticsDB = self.statistics.get_statistics_database()
         self.attack_controller = atkCtrl.AttackController(self.pcap_file, self.statistics, self.label_manager)
         self.attack_controller = atkCtrl.AttackController(self.pcap_file, self.statistics, self.label_manager)
 
 
+        # Set output directory and create it (if necessary)
+        Util.OUT_DIR = os.path.join(os.path.dirname(pcap_file_path), "ID2T_results") + os.sep
+        os.makedirs(Util.OUT_DIR, exist_ok=True)
+
     def load_pcap_statistics(self, flag_write_file: bool, flag_recalculate_stats: bool, flag_print_statistics: bool):
     def load_pcap_statistics(self, flag_write_file: bool, flag_recalculate_stats: bool, flag_print_statistics: bool):
         """
         """
         Loads the PCAP statistics either from the database, if the statistics were calculated earlier, or calculates
         Loads the PCAP statistics either from the database, if the statistics were calculated earlier, or calculates
@@ -100,10 +104,8 @@ class Controller:
         self.pcap_dest_path = self.pcap_file.merge_attack(attacks_pcap_path)
         self.pcap_dest_path = self.pcap_file.merge_attack(attacks_pcap_path)
 
 
         tmp_path_tuple = self.pcap_dest_path.rpartition("/")
         tmp_path_tuple = self.pcap_dest_path.rpartition("/")
-        result_dir = tmp_path_tuple[0] + tmp_path_tuple[1] + "ID2T_results/"
-        result_path = result_dir + tmp_path_tuple[2]
+        result_path = Util.OUT_DIR + tmp_path_tuple[2]
 
 
-        os.makedirs(result_dir, exist_ok=True)
         os.rename(self.pcap_dest_path, result_path)
         os.rename(self.pcap_dest_path, result_path)
         self.pcap_dest_path = result_path
         self.pcap_dest_path = result_path
 
 

+ 1 - 0
code/ID2TLib/Utility.py

@@ -17,6 +17,7 @@ CODE_DIR = os.path.dirname(os.path.abspath(__file__)) + "/../"
 ROOT_DIR = CODE_DIR + "../"
 ROOT_DIR = CODE_DIR + "../"
 RESOURCE_DIR = ROOT_DIR + "resources/"
 RESOURCE_DIR = ROOT_DIR + "resources/"
 TEST_DIR = RESOURCE_DIR + "test/"
 TEST_DIR = RESOURCE_DIR + "test/"
+OUT_DIR = None
 
 
 platforms = {"win7", "win10", "winxp", "win8.1", "macos", "linux", "win8", "winvista", "winnt", "win2000"}
 platforms = {"win7", "win10", "winxp", "win8.1", "macos", "linux", "win8", "winvista", "winnt", "win2000"}
 platform_probability = {"win7": 48.43, "win10": 27.99, "winxp": 6.07, "win8.1": 6.07, "macos": 5.94, "linux": 3.38,
 platform_probability = {"win7": 48.43, "win10": 27.99, "winxp": 6.07, "win8.1": 6.07, "macos": 5.94, "linux": 3.38,