# DFF -- An Open Source Digital Forensics Framework
# Copyright (C) 2009-2013 ArxSys
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LICENSE file
# at the top of the source tree.
#  
# See http://www.digital-forensic.org for more information about this
# project. Please do not directly contact any of the maintainers of
# DFF for assistance; the project provides a web site, mailing lists
# and IRC channels for your use.
# 
# Author(s):
#  Solal Jacob <sja@digital-forensic.org>
# 

__dff_module_jobs_version__ = "1.0.0"

from dff.api.module.module import Module 
from dff.api.taskmanager.processus import ProcessusManager
from dff.api.module.script import Script
from dff.api.types.libtypes import Variant

class JOBS(Script):
  def __init__(self):
    Script.__init__(self, "jobs")
    self.processusManager = ProcessusManager()

  def start(self, args):
    buff = "pid\tname\tstate\tinfo\n"
    for proc in self.processusManager:
      if proc.name != "jobs":
        buff += "[" + str(proc.pid) + "]\t" + proc.name + "\t" + proc.state + "\t" + str(proc.stateinfo) + "\n"
    if not buff:
	buff += "No processus launched yet !"        
    self.res["result"] = Variant(buff)


class jobs(Module):
  """Display launched processus"""
  def __init__(self):
   Module.__init__(self, "jobs", JOBS)
   self.tags = "builtins"
   self.flags = ["console"]
