def wrap_target_function(target, log_queue, result_queue, *args, **kwargs):
    try:
        setup_logger(handler=QueueHandler(log_queue))
        result = target(*args, **kwargs)
        result_queue.put(result)
    except:
        result = Exception(''.join(traceback.format_exception(*sys.exc_info())))
        result_queue.put(result)
        raise
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt

from ags_service_publisher.logging_io import setup_logger
from ags_service_publisher.config_io import get_config
from ags_service_publisher.helpers import empty_tuple

from datasetusagesreportdialog_ui import Ui_DatasetUsagesReportDialog

from helpers.pathhelpers import get_config_dir

log = setup_logger(__name__)


class DatasetUsagesReportDialog(QtGui.QDialog, Ui_DatasetUsagesReportDialog):

    runReport = QtCore.pyqtSignal(tuple, tuple, tuple, str)

    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)

        self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint)
        self._acceptButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok)
        self._acceptButton.setText('Run report')

        self.instancesTree.header().setResizeMode(0, QtGui.QHeaderView.Stretch)

        user_config = get_config('userconfig', config_dir=get_config_dir())
        for env_name, env in user_config['environments'].iteritems():
            env_item = QtGui.QTreeWidgetItem(self.instancesTree)