Skip to content

Commit

Permalink
Code review: 215550043: Added means to set the preferred LCID for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Mar 24, 2015
1 parent 4d93a2a commit abd910e
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/dpkg/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ python-plaso (1.2.1-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline <log2timeline-dev@googlegroups.com> Sat, 21 Mar 2015 09:45:39 +0100
-- Log2Timeline <log2timeline-dev@googlegroups.com> Tue, 24 Mar 2015 05:09:34 +0100
2 changes: 1 addition & 1 deletion plaso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__version__ = '1.2.1'

VERSION_DEV = True
VERSION_DATE = '20150321'
VERSION_DATE = '20150324'


def GetVersion():
Expand Down
32 changes: 29 additions & 3 deletions plaso/formatters/mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import os

from plaso.formatters import winevt_rc
from plaso.winnt import language_ids


class FormatterMediator(object):
"""Class that implements the formatter mediator."""

# LCID defaults to us-EN.
DEFAULT_LCID = 0x00000409
DEFAULT_LANGUAGE_IDENTIFIER = u'en-US'
# TODO: add smarter language ID to LCID resolving e.g.
# 'en-US' falls back to 'en'.
# LCID 0x0409 is en-US.
DEFAULT_LCID = 0x0409

_WINEVT_RC_DATABASE = u'winevt-rc.db'

Expand All @@ -23,7 +27,7 @@ def __init__(self, data_location=None):
"""
super(FormatterMediator, self).__init__()
self._data_location = data_location
# TODO: add means to set the preferred LCID.
self._language_identifier = self.DEFAULT_LANGUAGE_IDENTIFIER
self._lcid = self.DEFAULT_LCID
self._winevt_database_reader = None

Expand Down Expand Up @@ -73,3 +77,25 @@ def GetWindowsEventMessage(self, log_source, message_identifier):

return database_reader.GetMessage(
log_source, self.DEFAULT_LCID, message_identifier)

def SetPreferredLanguageIdentifier(self, language_identifier):
"""Sets the preferred language identifier.
Args:
language_identifier: the language identifier string e.g. en-US for
US English or is-IS for Icelandic.
Raises:
KeyError: if the language identifier is not defined.
TypeError: if the language identifier is not a string type.
"""
if not isinstance(language_identifier, basestring):
raise ValueError(u'Language identifier is not a string.')

values = language_ids.LANGUAGE_IDENTIFIERS.get(
language_identifier.lower(), None)
if not values:
raise KeyError(u'Language identifier: {0:s} is not defined.'.format(
language_identifier))
self._language_identifier = language_identifier
self._lcid = values[0]
18 changes: 18 additions & 0 deletions plaso/frontend/psort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from plaso.output import manager as output_manager
from plaso.proto import plaso_storage_pb2
from plaso.serializer import protobuf_serializer
from plaso.winnt import language_ids

import pytz

Expand All @@ -47,6 +48,7 @@ def __init__(self):
self._filter_object = None
self._output_filename = None
self._output_format = None
self._preferred_language = u'en-US'
self._slice_size = 5

def _AppendEvent(self, event_object, output_buffer, event_queues):
Expand Down Expand Up @@ -160,6 +162,14 @@ def ListAnalysisPlugins(self):
self.PrintColumnValue(name, description, format_length)
self.PrintSeparatorLine()

def ListLanguageIdentifiers(self):
"""Lists the language identifiers."""
self.PrintHeader(u'Language identifiers')
self.PrintColumnValue(u'Identifier', u'Language')
for language_id, value_list in sorted(
language_ids.LANGUAGE_IDENTIFIERS.items()):
self.PrintColumnValue(language_id, value_list[1])

def ListOutputModules(self):
"""Lists the output modules."""
self.PrintHeader(u'Output Modules')
Expand Down Expand Up @@ -222,6 +232,8 @@ def ParseOptions(self, options):
self._slice_size = getattr(options, u'slice_size', 5)
self._filter_buffer = bufferlib.CircularBuffer(self._slice_size)

self._preferred_language = getattr(options, u'preferred_language', u'en-US')

def ProcessStorage(self, options):
"""Open a storage file and processes the events within.
Expand Down Expand Up @@ -276,6 +288,12 @@ def ProcessStorage(self, options):

formatter_mediator = self.GetFormatMediator()

try:
formatter_mediator.SetPreferredLanguageIdentifier(
self._preferred_language)
except (KeyError, TypeError) as exception:
raise RuntimeError(exception)

try:
# TODO: move this into a factory function?
output_module_class = output_manager.OutputManager.GetOutputClass(
Expand Down
Loading

0 comments on commit abd910e

Please sign in to comment.