<s> import argparse <EOL> import sys <EOL> from paasta_tools import mesos_tools <EOL> from paasta_tools . utils import get_docker_client <EOL> from paasta_tools . utils import get_running_mesos_docker_containers <EOL> def parse_args ( ) : <EOL> parser = argparse . ArgumentParser ( <EOL> description = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> return args <EOL> def main ( ) : <EOL> args = parse_args ( ) <EOL> docker_client = get_docker_client ( ) <EOL> running_mesos_task_ids = [ task [ "<STR_LIT:id>" ] for task in mesos_tools . filter_running_tasks ( <EOL> mesos_tools . get_running_tasks_from_active_frameworks ( '<STR_LIT>' ) ) ] <EOL> running_mesos_docker_containers = get_running_mesos_docker_containers ( ) <EOL> orphaned_containers = [ ] <EOL> for container in running_mesos_docker_containers : <EOL> mesos_task_id = mesos_tools . get_mesos_id_from_container ( <EOL> container = container , client = docker_client ) <EOL> if mesos_task_id not in running_mesos_task_ids : <EOL> orphaned_containers . append ( ( container [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , mesos_task_id ) ) <EOL> if orphaned_containers : <EOL> print "<STR_LIT>" % ( "<STR_LIT:U+002CU+0020>" . join ( <EOL> "<STR_LIT>" % ( container_name , mesos_task_id ) <EOL> for container_name , mesos_task_id in orphaned_containers <EOL> ) , "<STR_LIT>" if args . force else "<STR_LIT>" ) <EOL> if args . force : <EOL> for container_name , mesos_task_id in orphaned_containers : <EOL> docker_client . kill ( container_name ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
