def Main(): """The main function.""" multiprocessing.freeze_support() input_reader = cli_tools.StdinInputReader() tool = PsortTool(input_reader=input_reader) if not tool.ParseArguments(): return False have_list_option = False if tool.list_analysis_plugins: tool.ListAnalysisPlugins() have_list_option = True if tool.list_output_modules: tool.ListOutputModules() have_list_option = True if tool.list_language_identifiers: tool.ListLanguageIdentifiers() have_list_option = True if tool.list_timezones: tool.ListTimeZones() have_list_option = True if have_list_option: return True tool.ProcessStorage() return True
def testReadUtf8(self): """Tests the Read function with UTF-8 encoding.""" original_stdin = sys.stdin sys.stdin = io.BytesIO(self._TEST_DATA) input_reader = tools.StdinInputReader() string = input_reader.Read() self.assertEqual(string, u'A first string\n') string = input_reader.Read() self.assertEqual(string, u'A 2nd string\n') # UTF-8 string with non-ASCII characters. string = input_reader.Read() self.assertEqual(string, u'þriðja string\n') # UTF-16 string with non-ASCII characters. string = input_reader.Read() expected_string = ( u'\ufffd\ufffdf\x00j\x00\ufffd\x00r\x00\ufffd\x00a\x00 ' u'\x00b\x00a\x00n\x00d\x00') self.assertEqual(string, expected_string) sys.stdin = original_stdin
def Main(): """The main function.""" input_reader = cli_tools.StdinInputReader() tool = psort_tool.PsortTool(input_reader=input_reader) if not tool.ParseArguments(sys.argv[1:]): return False if tool.show_troubleshooting: print('Using Python version {0!s}'.format(sys.version)) print() print('Path: {0:s}'.format(os.path.abspath(__file__))) print() print(tool.GetVersionInformation()) print() dependencies.CheckDependencies(verbose_output=True) print('Also see: https://plaso.readthedocs.io/en/latest/sources/user/' 'Troubleshooting.html') return True try: tool.CheckOutDated() except KeyboardInterrupt: return False have_list_option = False if tool.list_analysis_plugins: tool.ListAnalysisPlugins() have_list_option = True if tool.list_output_modules: tool.ListOutputModules() have_list_option = True if tool.list_language_identifiers: tool.ListLanguageIdentifiers() have_list_option = True if tool.list_timezones: tool.ListTimeZones() have_list_option = True if have_list_option: return True try: tool.ProcessStorage() except (KeyboardInterrupt, errors.UserAbort): logging.warning('Aborted by user.') return False except errors.BadConfigOption as exception: logging.warning(exception) return False return True
def Main(): """The main function.""" multiprocessing.freeze_support() input_reader = cli_tools.StdinInputReader() tool = psort_tool.PsortTool(input_reader=input_reader) if not tool.ParseArguments(): return False have_list_option = False if tool.list_analysis_plugins: tool.ListAnalysisPlugins() have_list_option = True if tool.list_output_modules: tool.ListOutputModules() have_list_option = True if tool.list_language_identifiers: tool.ListLanguageIdentifiers() have_list_option = True if tool.list_timezones: tool.ListTimeZones() have_list_option = True if have_list_option: return True try: tool.ProcessStorage() except (KeyboardInterrupt, errors.UserAbort): logging.warning('Aborted by user.') return False except errors.BadConfigOption as exception: logging.warning(exception) return False return True
def testPrintStatusUpdateStream(self): """Tests the PrintStatusUpdateStream function.""" input_reader = tools.StdinInputReader(encoding=u'ascii') output_writer = test_lib.TestOutputWriter() status_view_tool = TestStatusViewTool( input_reader=input_reader, output_writer=output_writer) status_view_tool._PrintStatusHeader() process_status = processing_status.ProcessingStatus() process_status.UpdateForemanStatus( u'f_identifier', u'f_status', 123, 0, u'f_test_file', 1, 29, 3, 456, 5, 6, 7, 8, 9, 10) status_view_tool._PrintStatusUpdateStream(process_status) string = output_writer.ReadOutput() expected_lines = [ b'Source path\t: /test/source/path', b'Source type\t: TESTSOURCE', b'', b''] self.assertEqual(string.split(b'\n'), expected_lines) process_status.UpdateWorkerStatus( u'w_identifier', u'w_status', 123, 0, u'w_test_file', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) status_view_tool._PrintStatusUpdateStream(process_status) string = output_writer.ReadOutput() expected_string = ( u'w_identifier (PID: 123) - events produced: 4 - ' u'file: w_test_file - running: True\n') self.assertEqual(string, expected_string)
def testInitialize(self): """Tests the __init__ function.""" input_reader = tools.StdinInputReader() self.assertIsNotNone(input_reader)
def testPrintStatusUpdate(self): """Tests the PrintStatusUpdate function.""" input_reader = tools.StdinInputReader(encoding=u'ascii') output_writer = test_lib.TestOutputWriter() status_view_tool = TestStatusViewTool( input_reader=input_reader, output_writer=output_writer) status_view_tool._PrintStatusHeader() process_status = processing_status.ProcessingStatus() process_status.UpdateForemanStatus( u'f_identifier', u'f_status', 123, 0, u'f_test_file', 1, 29, 3, 456, 5, 6, 7, 8, 9, 10) status_view_tool._PrintStatusUpdate(process_status) string = output_writer.ReadOutput() plaso_version = plaso.GetVersion() table_header = ( b'Identifier\tPID\tStatus\t\tMemory\t\tSources\t\tEvents\t\tFile') if not sys.platform.startswith(u'win'): table_header = b'\x1b[1m{0:s}\x1b[0m'.format(table_header) expected_lines = [ b'Source path\t: /test/source/path', b'Source type\t: TESTSOURCE', b'', b'plaso - version {0:s}'.format(plaso_version), b'', b'Source path\t: /test/source/path', b'Source type\t: TESTSOURCE', b'', table_header, (b'f_identifier\t123\tf_status\t0 B\t\t29 (29)\t\t456 (456)\t' b'f_test_file'), b'', b''] self.assertEqual(string.split(b'\n'), expected_lines) process_status.UpdateWorkerStatus( u'w_identifier', u'w_status', 123, 0, u'w_test_file', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) status_view_tool._PrintStatusUpdate(process_status) string = output_writer.ReadOutput() expected_lines = [ b'plaso - version {0:s}'.format(plaso_version), b'', b'Source path\t: /test/source/path', b'Source type\t: TESTSOURCE', b'', table_header, (b'f_identifier\t123\tf_status\t0 B\t\t29 (29)\t\t456 (456)\t' b'f_test_file'), b'w_identifier\t123\tw_status\t0 B\t\t2 (2)\t\t4 (4)\t\tw_test_file', b'', b''] self.assertEqual(string.split(b'\n'), expected_lines)