OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The pinfo CLI tool.""" | 2 """The pinfo CLI tool.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import argparse | 6 import argparse |
7 import collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import uuid | 10 import uuid |
11 | 11 |
12 from plaso.cli import tool_options | 12 from plaso.cli import tool_options |
13 from plaso.cli import tools | 13 from plaso.cli import tools |
14 from plaso.cli import views | 14 from plaso.cli import views |
15 from plaso.cli.helpers import manager as helpers_manager | 15 from plaso.cli.helpers import manager as helpers_manager |
16 from plaso.engine import knowledge_base | 16 from plaso.engine import knowledge_base |
17 from plaso.lib import definitions | 17 from plaso.lib import definitions |
18 from plaso.lib import errors | 18 from plaso.lib import errors |
| 19 from plaso.lib import loggers |
19 from plaso.lib import timelib | 20 from plaso.lib import timelib |
20 from plaso.serializer import json_serializer | 21 from plaso.serializer import json_serializer |
21 from plaso.storage import factory as storage_factory | 22 from plaso.storage import factory as storage_factory |
22 | 23 |
23 | 24 |
24 class PinfoTool( | 25 class PinfoTool( |
25 tools.CLITool, | 26 tools.CLITool, |
26 tool_options.StorageFileOptions): | 27 tool_options.StorageFileOptions): |
27 """Pinfo CLI tool.""" | 28 """Pinfo CLI tool.""" |
28 | 29 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 self._output_writer.Write('Storage files are different.\n') | 532 self._output_writer.Write('Storage files are different.\n') |
532 | 533 |
533 return result | 534 return result |
534 | 535 |
535 def ParseArguments(self): | 536 def ParseArguments(self): |
536 """Parses the command line arguments. | 537 """Parses the command line arguments. |
537 | 538 |
538 Returns: | 539 Returns: |
539 bool: True if the arguments were successfully parsed. | 540 bool: True if the arguments were successfully parsed. |
540 """ | 541 """ |
541 self._ConfigureLogging() | 542 loggers.ConfigureLogging() |
542 | 543 |
543 argument_parser = argparse.ArgumentParser( | 544 argument_parser = argparse.ArgumentParser( |
544 description=self.DESCRIPTION, add_help=False, | 545 description=self.DESCRIPTION, add_help=False, |
545 formatter_class=argparse.RawDescriptionHelpFormatter) | 546 formatter_class=argparse.RawDescriptionHelpFormatter) |
546 | 547 |
547 self.AddBasicOptions(argument_parser) | 548 self.AddBasicOptions(argument_parser) |
548 | 549 |
549 helpers_manager.ArgumentHelperManager.AddCommandLineArguments( | 550 helpers_manager.ArgumentHelperManager.AddCommandLineArguments( |
550 argument_parser, names=['storage_file']) | 551 argument_parser, names=['storage_file']) |
551 | 552 |
(...skipping 25 matching lines...) Expand all Loading... |
577 return False | 578 return False |
578 | 579 |
579 try: | 580 try: |
580 self.ParseOptions(options) | 581 self.ParseOptions(options) |
581 except errors.BadConfigOption as exception: | 582 except errors.BadConfigOption as exception: |
582 self._output_writer.Write('ERROR: {0!s}\n'.format(exception)) | 583 self._output_writer.Write('ERROR: {0!s}\n'.format(exception)) |
583 self._output_writer.Write('\n') | 584 self._output_writer.Write('\n') |
584 self._output_writer.Write(argument_parser.format_usage()) | 585 self._output_writer.Write(argument_parser.format_usage()) |
585 return False | 586 return False |
586 | 587 |
| 588 loggers.ConfigureLogging( |
| 589 debug_output=self._debug_mode, filename=self._log_file, |
| 590 quiet_mode=self._quiet_mode) |
| 591 |
587 return True | 592 return True |
588 | 593 |
589 def ParseOptions(self, options): | 594 def ParseOptions(self, options): |
590 """Parses the options. | 595 """Parses the options. |
591 | 596 |
592 Args: | 597 Args: |
593 options (argparse.Namespace): command line arguments. | 598 options (argparse.Namespace): command line arguments. |
594 | 599 |
595 Raises: | 600 Raises: |
596 BadConfigOption: if the options are invalid. | 601 BadConfigOption: if the options are invalid. |
597 """ | 602 """ |
598 self._ParseInformationalOptions(options) | 603 self._ParseInformationalOptions(options) |
599 | 604 |
600 if self._debug_mode: | |
601 logging_level = logging.DEBUG | |
602 elif self._quiet_mode: | |
603 logging_level = logging.WARNING | |
604 else: | |
605 logging_level = logging.INFO | |
606 | |
607 self._ConfigureLogging(log_level=logging_level) | |
608 | |
609 self._verbose = getattr(options, 'verbose', False) | 605 self._verbose = getattr(options, 'verbose', False) |
610 | 606 |
611 self._output_filename = getattr(options, 'write', None) | 607 self._output_filename = getattr(options, 'write', None) |
612 | 608 |
613 helpers_manager.ArgumentHelperManager.ParseOptions( | 609 helpers_manager.ArgumentHelperManager.ParseOptions( |
614 options, self, names=['storage_file']) | 610 options, self, names=['storage_file']) |
615 | 611 |
616 # TODO: move check into _CheckStorageFile. | 612 # TODO: move check into _CheckStorageFile. |
617 if not self._storage_file_path: | 613 if not self._storage_file_path: |
618 raise errors.BadConfigOption('Missing storage file option.') | 614 raise errors.BadConfigOption('Missing storage file option.') |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 self._storage_file_path, exception)) | 654 self._storage_file_path, exception)) |
659 return | 655 return |
660 | 656 |
661 try: | 657 try: |
662 if self._output_format == 'json': | 658 if self._output_format == 'json': |
663 self._PrintStorageInformationAsJSON(storage_file) | 659 self._PrintStorageInformationAsJSON(storage_file) |
664 elif self._output_format == 'text': | 660 elif self._output_format == 'text': |
665 self._PrintStorageInformationAsText(storage_file) | 661 self._PrintStorageInformationAsText(storage_file) |
666 finally: | 662 finally: |
667 storage_file.Close() | 663 storage_file.Close() |
OLD | NEW |