# Path: bts_tools/core.py
# def run(cmd, capture_io=False, verbose=True, log_on_fail=True,
#         run_dir=None, forward_signals=False, pidfile=None, shell=False):
#     r = _run(cmd, capture_io=capture_io, verbose=verbose,
#              run_dir=run_dir, forward_signals=forward_signals, pidfile=pidfile, shell=shell)
#     if r.status != 0:
#         if log_on_fail:
#             log.warning('Failed running: %s' % cmd)
#             if capture_io:
#                 log.warning('\nSTDOUT:\n{}\nSTDERR:\n:{}'.format(r.stdout, r.stderr))
#         raise RuntimeError('Failed running: %s' % cmd)
#     return r
# 
# def get_bin_name(client=None, build_env=None):
#     return os.path.basename(get_full_bin_name(client, build_env))


from .core import run, get_bin_name
import psutil
import logging
#
# bts_tools - Tools to easily manage the bitshares client
# Copyright (c) 2014 Nicolas Wack <wackou@gmail.com>
#
# 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/>.
#


log = logging.getLogger(__name__)

# TODO: should move all these functions inside of GrapheneClient


# use a cache for the mapping {port: process}, as iterating over all processes with psutil is quite costly
_process_cache = {}

statuses = {psutil.STATUS_RUNNING: 'STATUS_RUNNING',
            psutil.STATUS_SLEEPING: 'STATUS_SLEEPING',
            psutil.STATUS_DISK_SLEEP: 'STATUS_DISK_SLEEP',

# Path: bts_tools/core.py
# def run(cmd, capture_io=False, verbose=True, log_on_fail=True,
#         run_dir=None, forward_signals=False, pidfile=None, shell=False):
#     r = _run(cmd, capture_io=capture_io, verbose=verbose,
#              run_dir=run_dir, forward_signals=forward_signals, pidfile=pidfile, shell=shell)
#     if r.status != 0:
#         if log_on_fail:
#             log.warning('Failed running: %s' % cmd)
#             if capture_io:
#                 log.warning('\nSTDOUT:\n{}\nSTDERR:\n:{}'.format(r.stdout, r.stderr))
#         raise RuntimeError('Failed running: %s' % cmd)
#     return r
# 
# def get_bin_name(client=None, build_env=None):
#     return os.path.basename(get_full_bin_name(client, build_env))


# Path: bts_tools/process.py
from .core import run, get_bin_name
import psutil
import logging

#
# bts_tools - Tools to easily manage the bitshares client
# Copyright (c) 2014 Nicolas Wack <wackou@gmail.com>
#
# 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/>.
#


log = logging.getLogger(__name__)

# TODO: should move all these functions inside of GrapheneClient


# use a cache for the mapping {port: process}, as iterating over all processes with psutil is quite costly
_process_cache = {}

statuses = {psutil.STATUS_RUNNING: 'STATUS_RUNNING',
            psutil.STATUS_SLEEPING: 'STATUS_SLEEPING',
            psutil.STATUS_DISK_SLEEP: 'STATUS_DISK_SLEEP',

            psutil.STATUS_STOPPED: 'STATUS_STOPPED',