Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1461)

Unified Diff: plaso/cli/tools.py

Issue 321000043: [plaso] Refactored log2timeline front-end to tool #160 (Closed)
Patch Set: Changes after review Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « plaso/cli/status_view_tool.py ('k') | plaso/engine/engine.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: plaso/cli/tools.py
diff --git a/plaso/cli/tools.py b/plaso/cli/tools.py
index ce9cb012a09f4a32ebefef035db0584e6b55041c..c4125bf22dd48709ca357f368ac906b37d572a07 100644
--- a/plaso/cli/tools.py
+++ b/plaso/cli/tools.py
@@ -458,6 +458,36 @@ class CLITool(object):
table_view.Write(self._output_writer)
+ def ParseNumericOption(self, options, name, base=10, default_value=None):
+ """Parses a numeric option.
+
+ If the option is not set the default value is returned.
+
+ Args:
+ options (argparse.Namespace): command line arguments.
+ name (str): name of the numeric option.
+ base (Optional[int]): base of the numeric value.
+ default_value (Optional[object]): default value.
+
+ Returns:
+ int: numeric value.
+
+ Raises:
+ BadConfigOption: if the options are invalid.
+ """
+ numeric_value = getattr(options, name, None)
+ if not numeric_value:
+ return default_value
+
+ try:
+ return int(numeric_value, base)
+
+ except (TypeError, ValueError):
+ name = name.replace(u'_', u' ')
+ raise errors.BadConfigOption(
+ u'Unsupported numeric value {0:s}: {1!s}.'.format(
+ name, numeric_value))
+
def ParseOptions(self, options):
"""Parses tool specific options.
@@ -489,7 +519,7 @@ class CLITool(object):
Raises:
BadConfigOption: if the command line argument value cannot be converted
- to a Unicode string.
+ to a Unicode string.
"""
argument_value = getattr(options, argument_name, None)
if not argument_value:
« no previous file with comments | « plaso/cli/status_view_tool.py ('k') | plaso/engine/engine.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b