#!/usr/bin/env python
#
# Information about which process is in rsbac jail running.
# 
# Copyright (C) 2011-2014 Jens Kasten <jens@kasten-edv.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>
# 

import argparse
import time

from rsbactools import jail


def main():
    time_start = time.time()
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", "--time", default=False, action="store_true",
        help="show execution time")
    parser.add_argument("-p", "--program", default=False, metavar="prog-name",
        help="print only information about a single process")
    parser.add_argument("-j", "--jail-id", type=int, metavar="jail-id",
        help="print only process with same jail-id")
    
    args = parser.parse_args()
   
    ps = jail.PsJail()
    if args.program:
        ps.list_process(args.program)
    else:
        ps.list_processes()
    ps.get_processes_info(args.jail_id)

    ps.show()
    if args.time:
        time_end = time.time()
        time_all = time_end - time_start
        print("-" * 79)
        print("Time to execute: %0.4s seconds" % time_all)


if __name__ == "__main__":
    main()
