Exemple #1
0
	def import_files(self, paths):
		start_time = time.time()
		netxml_files = self.find_all_netxml_files(paths)
		if len(netxml_files) == 0:
			print "No netxml files found to import."
		else:
			print "%s file(s) found to import." % str(len(netxml_files))
			for netxml_file in netxml_files:
				file_name = os.path.basename(netxml_file)
				if self.ignore_already_imported_error == False and file_name in self.data_repository.imported_files:
					imported_file = self.data_repository.imported_files[file_name]
					print "Ignoring %s. It has already been imported on %s." % (netxml_file, str(imported_file.date_imported))
					continue
				print "Reading %s" % netxml_file
				try:
					tree = ElementTree.parse(netxml_file)
				except:
					print "Ignoring %s. Failed to parse the xml." % netxml_file
					continue
				root = tree.getroot()
				self.parse_wireless_network_elements(root.findall("wireless-network"), file_name)
				self.data_repository.imported_files[file_name] = ImportedFile(0, file_name, Utils.get_utc_date_time())
			self.data_repository.save_updated_items()
		end_time = time.time()
		processing_time = end_time - start_time
		print "Completed in %s secs." % str(round(processing_time,2))
	def import_files(self, paths):
		start_time = time.time()
		pcap_files = self.find_all_pcap_files(paths)
		if len(pcap_files) == 0:
			print "No pcap files found to import."
		else:
			print "%s file(s) found to import." % str(len(pcap_files))
			for pcap_file in pcap_files:
				file_name = os.path.basename(pcap_file)
				if self.ignore_already_imported_error == False and file_name in self.data_repository.imported_hostname_files:
					imported_file = self.data_repository.imported_hostname_files[file_name]
					print "Ignoring %s. It has already been imported on %s." % (pcap_file, str(imported_file.date_imported))
					continue
				print "Reading %s" % pcap_file
				self.parse_pcap_file(pcap_file)
				self.data_repository.imported_hostname_files[file_name] = ImportedHostnameFile(0, file_name, Utils.get_utc_date_time())
			self.data_repository.save_updated_items()
		end_time = time.time()
		processing_time = end_time - start_time
		print "Completed in %s secs." % str(round(processing_time,2))