Index: plaso/cli/status_view.py |
diff --git a/plaso/cli/status_view_tool.py b/plaso/cli/status_view.py |
similarity index 64% |
copy from plaso/cli/status_view_tool.py |
copy to plaso/cli/status_view.py |
index 8a864f0fb29b27c7fc0e0f71dfa9f27959441bd7..17136b1fb762bcae4f30eb9bedd4439ced6ebfdf 100644 |
--- a/plaso/cli/status_view_tool.py |
+++ b/plaso/cli/status_view.py |
@@ -1,5 +1,5 @@ |
# -*- coding: utf-8 -*- |
-"""The StatusView CLI tool.""" |
+"""The status view.""" |
import sys |
@@ -8,72 +8,48 @@ try: |
except ImportError: |
win32console = None |
+from dfvfs.lib import definitions as dfvfs_definitions |
+ |
import plaso |
from plaso.lib import definitions |
-from plaso.cli import storage_media_tool |
from plaso.cli import tools as cli_tools |
from plaso.cli import views as cli_views |
-class StatusViewTool(storage_media_tool.StorageMediaTool): |
- """A tool that reports processing status.""" |
- |
- def __init__(self, input_reader=None, output_writer=None): |
- """Initializes the status view tool object. |
- |
- Args: |
- input_reader (Optional[InputReader]): input reader, where None indicates |
- that the stdin input reader should be used. |
- output_writer (Optional[OutputWriter]): output writer, where None |
- indicates that the stdout output writer should be used. |
- """ |
- super(StatusViewTool, self).__init__( |
- input_reader=input_reader, output_writer=output_writer) |
- |
- self._stdout_output_writer = isinstance( |
- self._output_writer, cli_tools.StdoutOutputWriter) |
- |
- self._number_of_analysis_reports = 0 |
- self._source_path = None |
- self._source_type_string = u'UNKNOWN' |
- |
- def _PrintStatusHeader(self): |
- """Prints the processing status header.""" |
- self._output_writer.Write( |
- u'Source path\t: {0:s}\n'.format(self._source_path)) |
- self._output_writer.Write( |
- u'Source type\t: {0:s}\n'.format(self._source_type_string)) |
+class StatusView(object): |
+ """Processing status view.""" |
- if self._filter_file: |
- self._output_writer.Write(u'Filter file\t: {0:s}\n'.format( |
- self._filter_file)) |
+ MODE_LINEAR = u'linear' |
+ MODE_WINDOW = u'window' |
- self._output_writer.Write(u'\n') |
+ _SOURCE_TYPES = { |
+ dfvfs_definitions.SOURCE_TYPE_DIRECTORY: u'directory', |
+ dfvfs_definitions.SOURCE_TYPE_FILE: u'single file', |
+ dfvfs_definitions.SOURCE_TYPE_STORAGE_MEDIA_DEVICE: ( |
+ u'storage media device'), |
+ dfvfs_definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE: ( |
+ u'storage media image')} |
- def _FormatSizeInUnitsOf1024(self, size): |
- """Represents a number of bytes in units of 1024. |
+ def __init__(self, output_writer, tool_name): |
+ """Initializes a status view. |
Args: |
- size (int): size in bytes. |
- |
- Returns: |
- str: human readable string of the size. |
+ output_writer (OutputWriter): output writer. |
+ tool_name (str): namd of the tool. |
""" |
- magnitude_1024 = 0 |
- used_memory_1024 = float(size) |
- while used_memory_1024 >= 1024: |
- used_memory_1024 /= 1024 |
- magnitude_1024 += 1 |
- |
- if magnitude_1024 > 0 and magnitude_1024 <= 7: |
- return u'{0:.1f} {1:s}'.format( |
- used_memory_1024, self._UNITS_1024[magnitude_1024]) |
- |
- return u'{0:d} B'.format(size) |
+ super(StatusView, self).__init__() |
+ self._filter_file = None |
+ self._mode = self.MODE_WINDOW |
+ self._output_writer = output_writer |
+ self._source_path = None |
+ self._source_type = None |
+ self._stdout_output_writer = isinstance( |
+ output_writer, cli_tools.StdoutOutputWriter) |
+ self._tool_name = tool_name |
- def _FormatStatusTableRow(self, process_status): |
- """Formats a status table row. |
+ def _FormatExtractionStatusTableRow(self, process_status): |
+ """Formats an extraction status table row. |
Args: |
process_status (ProcessStatus): processing status. |
@@ -118,8 +94,45 @@ class StatusViewTool(storage_media_tool.StorageMediaTool): |
identifier, process_status.pid, status, used_memory, sources, events, |
process_status.display_name) |
- def _PrintStatusUpdate(self, processing_status): |
- """Prints the processing status. |
+ def _FormatSizeInUnitsOf1024(self, size): |
+ """Represents a number of bytes in units of 1024. |
+ |
+ Args: |
+ size (int): size in bytes. |
+ |
+ Returns: |
+ str: human readable string of the size. |
+ """ |
+ magnitude_1024 = 0 |
+ used_memory_1024 = float(size) |
+ while used_memory_1024 >= 1024: |
+ used_memory_1024 /= 1024 |
+ magnitude_1024 += 1 |
+ |
+ if magnitude_1024 > 0 and magnitude_1024 <= 7: |
+ return u'{0:.1f} {1:s}'.format( |
+ used_memory_1024, self._UNITS_1024[magnitude_1024]) |
+ |
+ return u'{0:d} B'.format(size) |
+ |
+ def _PrintExtractionStatusUpdateLinear(self, processing_status): |
+ """Prints an extraction status update in linear mode. |
+ |
+ Args: |
+ processing_status (ProcessingStatus): processing status. |
+ """ |
+ for worker_status in processing_status.workers_status: |
+ status_line = ( |
+ u'{0:s} (PID: {1:d}) - events produced: {2:d} - file: {3:s} ' |
+ u'- running: {4!s}\n').format( |
+ worker_status.identifier, worker_status.pid, |
+ worker_status.number_of_produced_events, |
+ worker_status.display_name, |
+ worker_status.status not in definitions.PROCESSING_ERROR_STATUS) |
+ self._output_writer.Write(status_line) |
+ |
+ def _PrintExtractionStatusUpdateWindow(self, processing_status): |
+ """Prints an extraction status update in window mode. |
Args: |
processing_status (ProcessingStatus): processing status. |
@@ -128,10 +141,10 @@ class StatusViewTool(storage_media_tool.StorageMediaTool): |
self._ClearScreen() |
output_text = u'plaso - {0:s} version {1:s}\n\n'.format( |
- self.NAME, plaso.__version__) |
+ self._tool_name, plaso.__version__) |
self._output_writer.Write(output_text) |
- self._PrintStatusHeader() |
+ self.PrintExtractionStatusHeader() |
# TODO: for win32console get current color and set intensity, |
# write the header separately then reset intensity. |
@@ -142,11 +155,12 @@ class StatusViewTool(storage_media_tool.StorageMediaTool): |
status_table = [status_header] |
- status_row = self._FormatStatusTableRow(processing_status.foreman_status) |
+ status_row = self._FormatExtractionStatusTableRow( |
+ processing_status.foreman_status) |
status_table.append(status_row) |
for worker_status in processing_status.workers_status: |
- status_row = self._FormatStatusTableRow(worker_status) |
+ status_row = self._FormatExtractionStatusTableRow(worker_status) |
status_table.append(status_row) |
status_table.append(u'') |
@@ -164,30 +178,26 @@ class StatusViewTool(storage_media_tool.StorageMediaTool): |
# We need to explicitly flush stdout to prevent partial status updates. |
sys.stdout.flush() |
- def _PrintStatusUpdateStream(self, processing_status): |
- """Prints the processing status as a stream of output. |
+ def GetExtractionStatusUpdateCallback(self): |
+ """Retrieves the extraction status update callback function. |
- Args: |
- processing_status (ProcessingStatus): processing status. |
+ Returns: |
+ function: status update callback function or None. |
""" |
- for worker_status in processing_status.workers_status: |
- status_line = ( |
- u'{0:s} (PID: {1:d}) - events produced: {2:d} - file: {3:s} ' |
- u'- running: {4!s}\n').format( |
- worker_status.identifier, worker_status.pid, |
- worker_status.number_of_produced_events, |
- worker_status.display_name, |
- worker_status.status not in definitions.PROCESSING_ERROR_STATUS) |
- self._output_writer.Write(status_line) |
+ if self._mode == self.MODE_LINEAR: |
+ return self._PrintExtractionStatusUpdateLinear |
+ elif self._mode == self.MODE_WINDOW: |
+ return self._PrintExtractionStatusUpdateWindow |
- def _PrintAnalysisReportsDetails(self, storage): |
+ def PrintAnalysisReportsDetails(self, storage, number_of_analysis_reports): |
"""Prints the details of the analysis reports. |
Args: |
storage (BaseStorage): storage writer. |
+ number_of_analysis_reports (int): number of analysis reports. |
""" |
for index, analysis_report in enumerate(storage.GetAnalysisReports()): |
- if index + 1 <= self._number_of_analysis_reports: |
+ if index + 1 <= number_of_analysis_reports: |
continue |
title = u'Analysis report: {0:d}'.format(index) |
@@ -197,3 +207,37 @@ class StatusViewTool(storage_media_tool.StorageMediaTool): |
table_view.AddRow([u'String', analysis_report.GetString()]) |
table_view.Write(self._output_writer) |
+ |
+ # TODO: refactor to protected method. |
+ def PrintExtractionStatusHeader(self): |
+ """Prints the extraction status header.""" |
+ self._output_writer.Write( |
+ u'Source path\t: {0:s}\n'.format(self._source_path)) |
+ self._output_writer.Write( |
+ u'Source type\t: {0:s}\n'.format(self._source_type)) |
+ |
+ if self._filter_file: |
+ self._output_writer.Write(u'Filter file\t: {0:s}\n'.format( |
+ self._filter_file)) |
+ |
+ self._output_writer.Write(u'\n') |
+ |
+ def SetMode(self, mode): |
+ """Sets the mode. |
+ |
+ Args: |
+ mode (str): status view mode. |
+ """ |
+ self._mode = mode |
+ |
+ def SetSourceInformation(self, source_path, source_type, filter_file=None): |
+ """Sets the source information. |
+ |
+ Args: |
+ source_path (str): path of the source. |
+ source_type (str): source type. |
+ filter_file (Optional[str]): filter file. |
+ """ |
+ self._filter_file = filter_file |
+ self._source_path = source_path |
+ self._source_type = self._SOURCE_TYPES.get(source_type, u'UNKNOWN') |