Skip to content

Commit 3b19ac9

Browse files
committed
Fixes formatting
1 parent 9d26a72 commit 3b19ac9

File tree

6 files changed

+79
-77
lines changed

6 files changed

+79
-77
lines changed

deltascan/cli/cmd.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def do_diff(self, v):
191191
_uuids.append(self.last_index_to_uuid_mapping[_key])
192192
if len(_uuids) < 2:
193193
print("Provide 2 valid indexes from the view list."
194-
" Re-run view to view the last results.")
194+
" Re-run view to view the last results.")
195195
return
196196
r = self._app.diffs(uuids=_uuids)
197197
else:
@@ -280,6 +280,7 @@ def signal_handler(signal, frame):
280280
print("Exiting without cleanup :-(")
281281
os._exit(1)
282282

283+
283284
def run():
284285
"""
285286
Entry point for the command line interface.

deltascan/core/deltascan.py

+72-72
Original file line numberDiff line numberDiff line change
@@ -374,80 +374,80 @@ def __split_scans_in_hosts(scans):
374374
_split_scans_in_hosts[_s["host"]] = []
375375
_split_scans_in_hosts[_s["host"]].append(_s)
376376
return _split_scans_in_hosts
377-
377+
378378
def files_diff(self, _diff_files=None):
379-
"""
380-
Compare the scan results from different files and print the differences.
381-
382-
Args:
383-
_diff_files (str): Comma-separated list of file paths to compare. If not provided or empty,
384-
the file paths will be fetched from the configuration.
385-
386-
Returns:
387-
None
388-
"""
389-
if _diff_files is not None and _diff_files != "":
390-
_files = _diff_files.split(",")
379+
"""
380+
Compare the scan results from different files and print the differences.
381+
382+
Args:
383+
_diff_files (str): Comma-separated list of file paths to compare. If not provided or empty,
384+
the file paths will be fetched from the configuration.
385+
386+
Returns:
387+
None
388+
"""
389+
if _diff_files is not None and _diff_files != "":
390+
_files = _diff_files.split(",")
391+
else:
392+
_files = self._config.diff_files.split(",")
393+
_imported_scans = []
394+
_importer = None
395+
if _files is None or len(_files) < 2:
396+
raise DScanInputValidationException("At least two files must be provided to compare")
397+
for _f in _files:
398+
if _importer is None:
399+
_importer = Importer(_f, logger=self.logger)
400+
_r = _importer.load_results_from_file()
391401
else:
392-
_files = self._config.diff_files.split(",")
393-
_imported_scans = []
394-
_importer = None
395-
if _files is None or len(_files) < 2:
396-
raise DScanInputValidationException("At least two files must be provided to compare")
397-
for _f in _files:
398-
if _importer is None:
399-
_importer = Importer(_f, logger=self.logger)
400-
_r = _importer.load_results_from_file()
401-
else:
402-
_importer.filename = _f
403-
_r = _importer.load_results_from_file()
404-
405-
_host = _r._nmaprun["args"].split(" ")[-1]
406-
_parsed = Parser.extract_port_scan_dict_results(_r)
407-
if "/" in _host:
408-
raise DScanInputValidationException("Subnet is not supported for this operation")
409-
if len(_parsed) > 1:
410-
raise DScanInputValidationException("Only one host per file is supported for this operation")
411-
412-
_imported_scans.append(
413-
{
414-
"created_at": datetime.fromtimestamp(int(
415-
_r._runstats["finished"]["time"])).strftime(
416-
APP_DATE_FORMAT) if "finished" in _r._runstats else None,
417-
"results": _parsed[0],
418-
"arguments": _r._nmaprun["args"]
419-
}
420-
)
402+
_importer.filename = _f
403+
_r = _importer.load_results_from_file()
404+
405+
_host = _r._nmaprun["args"].split(" ")[-1]
406+
_parsed = Parser.extract_port_scan_dict_results(_r)
407+
if "/" in _host:
408+
raise DScanInputValidationException("Subnet is not supported for this operation")
409+
if len(_parsed) > 1:
410+
raise DScanInputValidationException("Only one host per file is supported for this operation")
411+
412+
_imported_scans.append(
413+
{
414+
"created_at": datetime.fromtimestamp(int(
415+
_r._runstats["finished"]["time"])).strftime(
416+
APP_DATE_FORMAT) if "finished" in _r._runstats else None,
417+
"results": _parsed[0],
418+
"arguments": _r._nmaprun["args"]
419+
}
420+
)
421421

422-
_final_diffs = []
423-
for i, _ in enumerate(_imported_scans, 1):
424-
if i == len(_imported_scans):
425-
break
426-
__diffs = self._diffs_between_dicts(
427-
self._results_to_port_dict(_imported_scans[i-1]["results"]),
428-
self._results_to_port_dict(_imported_scans[i]["results"]))
429-
_final_diffs.append({
430-
"ids": [0,0],
431-
"uuids": ["",""],
432-
"generic": [
433-
{
434-
"host": _imported_scans[i-1]["results"]["host"],
435-
"arguments": _imported_scans[i-1]["arguments"],
436-
"profile_name": ""
437-
},
438-
{
439-
"host": _imported_scans[i]["results"]["host"],
440-
"arguments": _imported_scans[i]["arguments"],
441-
"profile_name": ""
442-
}
443-
],
444-
"dates": [
445-
_imported_scans[i-1]["created_at"],
446-
_imported_scans[i]["created_at"]],
447-
"diffs": __diffs,
448-
"result_hashes": ["",""]
449-
})
450-
return _final_diffs
422+
_final_diffs = []
423+
for i, _ in enumerate(_imported_scans, 1):
424+
if i == len(_imported_scans):
425+
break
426+
__diffs = self._diffs_between_dicts(
427+
self._results_to_port_dict(_imported_scans[i-1]["results"]),
428+
self._results_to_port_dict(_imported_scans[i]["results"]))
429+
_final_diffs.append({
430+
"ids": [0, 0],
431+
"uuids": ["", ""],
432+
"generic": [
433+
{
434+
"host": _imported_scans[i-1]["results"]["host"],
435+
"arguments": _imported_scans[i-1]["arguments"],
436+
"profile_name": ""
437+
},
438+
{
439+
"host": _imported_scans[i]["results"]["host"],
440+
"arguments": _imported_scans[i]["arguments"],
441+
"profile_name": ""
442+
}
443+
],
444+
"dates": [
445+
_imported_scans[i-1]["created_at"],
446+
_imported_scans[i]["created_at"]],
447+
"diffs": __diffs,
448+
"result_hashes": ["", ""]
449+
})
450+
return _final_diffs
451451

452452
def _list_scans_with_diffs(self, scans):
453453
"""
@@ -844,7 +844,7 @@ def import_file(self):
844844
@import_file.setter
845845
def import_file(self, value):
846846
self._config.import_file = value
847-
847+
848848
@property
849849
def diff_files(self):
850850
return self._config.diff_files

deltascan/core/exceptions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ class DScanRDBMSErrorCreatingEntry(DScanRDBMSException):
8686
class DScanMethodNotImplemented(DScanException):
8787
pass
8888

89+
8990
class DScanResultsParsingError(DScanException):
90-
pass
91+
pass

deltascan/core/importer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _import_xml(self):
9797
"""
9898
try:
9999
_r = self.load_results_from_file(self._full_name)
100-
_parsed = Parser.extract_port_scan_dict_results(_r )
100+
_parsed = Parser.extract_port_scan_dict_results(_r)
101101
_host = _r ._nmaprun["args"].split(" ")[-1]
102102

103103
_profile_name, _ = \

deltascan/core/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from deltascan.core.exceptions import (DScanResultsSchemaException)
99
from marshmallow import ValidationError
1010

11+
1112
class Parser:
1213
@classmethod
1314
def diffs_to_output_format(cls, diffs):
@@ -142,4 +143,3 @@ def extract_port_scan_dict_results(cls, results):
142143
return scan_results
143144
except Exception as e:
144145
raise DScanResultsParsingError(f"An error occurred with the scan parser: {str(e)}")
145-

deltascan/core/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def validate_port_state_type(port_status_type):
105105
return False
106106
return True
107107

108+
108109
def format_string(string: str) -> str:
109110
"""
110111
Formats a string by making the first letter uppercase and replacing underscores with white spaces.
@@ -140,4 +141,3 @@ def nmap_arguments_to_list(arguments):
140141
_arguments = [_arg for _arg in _arguments.split(" ") if _arg != "" and _arg != " "]
141142

142143
return _arguments
143-

0 commit comments

Comments
 (0)