# ----------------------------------------------------------------------------
#       Copyright (C) 2013-2014 Huynh Vi Lam  <domovilam@gmail.com>
#
#       This file is part of pimucha.
#
#	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 threading


def checksrvs(s,listsrvs):
    msg = []
    for ctrl in listsrvs:
        tt = serverthreads(ctrl)
        if not tt:
            msg.append(s + '_' + ctrl)
    if len(msg) == 0: msg = None
    return msg


def infothreads():
    msg = []
    ths = threading.enumerate()
    for th in ths:
        try:
            thname = th.__name__ + ':' + repr(th)
        except:
            thname = th.name + ':' + repr(th)
        msg.append(thname)
    return msg


def serverthreads(srvtt):
    ths = threading.enumerate()
    for srv in ths:
        try:
            n = srv.__name__
        except:
            n = srv.name
        if srvtt in n:
            return srv
    return None
