old_contents: # -*- coding: utf-8 -*-
  # Copyright 2015 Google Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #      http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  """Task for executing volatility."""
  
  from __future__ import unicode_literals
  
  import os
  
  from turbinia import config
  from turbinia.evidence import VolatilityReport
  from turbinia.workers import TurbiniaTask
  
  
  class VolatilityTask(TurbiniaTask):
    """Task to execute volatility."""
  
    def __init__(self, module='test'):
      super(VolatilityTask, self).__init__()
      self.module = module
  
    def run(self, evidence, result):
      """Run volatility against evidence.
  
      Args:
          evidence (Evidence object): The evidence we will process
          result (TurbiniaTaskResult): The object to place task results into.
  
      Returns:
          TurbiniaTaskResult object.
      """
  
      config.LoadConfig()
  
      # Create the new Evidence object that will be generated by this Task.
      output_evidence = VolatilityReport()
  
      # Create a path that we can write the new file to.
      output_file_path = os.path.join(
          self.output_dir, '{0:s}.txt'.format(self.id))
      output_evidence.local_path = output_file_path
      debug_log = os.path.join(self.output_dir, '{0:s}.log'.format(self.id))
  
      # TODO: Add in config options for Turbinia
      cmd = (
          'vol2 -f {0:s} --profile={1:s} {2:s} --output=text '
          '--output-file={3:s}').format(
              evidence.local_path, evidence.profile, self.module,
              output_file_path).split()
  
      result.log('Running vol as [{0:s}]'.format(' '.join(cmd)))
      res = self.execute(
          cmd, result, log_files=[debug_log], new_evidence=[output_evidence],
          close=True)
  
      if res == 0:
        # Write the report to the output file.
        with open(output_file_path, 'w') as fh:
          fh.write(output_evidence.text_data.encode('utf-8'))
  
        # Add the resulting evidence to the result object.
        result.add_evidence(output_evidence, evidence.config)
        result.report_data = output_evidence
        summary = 'Volatility module {0} successfully ran.'.format(self.module)
        result.close(self, success=True, status=summary)
      else:
        summary = 'Volatility module {0} failed to run.'.format(self.module)
        result.close(self, success=False, status=summary)
  
      return result
  
new_contents: # -*- coding: utf-8 -*-
  # Copyright 2015 Google Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #      http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  """Task for executing volatility."""
  
  from __future__ import unicode_literals
  
  import os
  
  from turbinia import config
  from turbinia.evidence import VolatilityReport
  from turbinia.workers import TurbiniaTask
  
  
  class VolatilityTask(TurbiniaTask):
    """Task to execute volatility."""
  
    def __init__(self, module='test'):
      super(VolatilityTask, self).__init__()
      self.module = module
  
    def run(self, evidence, result):
      """Run volatility against evidence.
  
      Args:
          evidence (Evidence object): The evidence we will process
          result (TurbiniaTaskResult): The object to place task results into.
  
      Returns:
          TurbiniaTaskResult object.
      """
  
      config.LoadConfig()
  
      # Create the new Evidence object that will be generated by this Task.
      output_evidence = VolatilityReport()
  
      # Create a path that we can write the new file to.
      output_file_path = os.path.join(
          self.output_dir, '{0:s}.txt'.format(self.id))
      output_evidence.local_path = output_file_path
      debug_log = os.path.join(self.output_dir, '{0:s}.log'.format(self.id))
  
      # TODO: Add in config options for Turbinia
      cmd = (
          'vol.py -f {0:s} --profile={1:s} {2:s} --output=text '
          '--output-file={3:s}').format(
              evidence.local_path, evidence.profile, self.module,
              output_file_path).split()
  
      result.log('Running vol as [{0:s}]'.format(' '.join(cmd)))
      res = self.execute(
          cmd, result, log_files=[debug_log], new_evidence=[output_evidence],
          close=True)
  
      if res == 0:
        # Write the report to the output file.
        with open(output_file_path, 'w') as fh:
          fh.write(output_evidence.text_data.encode('utf-8'))
  
        # Add the resulting evidence to the result object.
        result.add_evidence(output_evidence, evidence.config)
        result.report_data = output_evidence
        summary = 'Volatility module {0} successfully ran.'.format(self.module)
        result.close(self, success=True, status=summary)
      else:
        summary = 'Volatility module {0} failed to run.'.format(self.module)
        result.close(self, success=False, status=summary)
  
      return result
  
subject: Change Volatility binary name (#407)