'Run script in current or dedicated client'

def run_script(self, filename, wdir, args, debug, post_mortem, current_client, clear_variables):

    norm = (lambda text: remove_backslashes(to_text_string(text)))
    if current_client:
        client = self.get_current_client()
    else:
        client = self.get_client_for_file(filename)
        if (client is None):
            self.create_client_for_file(filename)
            client = self.get_current_client()
    if (client is not None):
        if (client.get_kernel() is not None):
            line = ("%s('%s'" % (('debugfile' if debug else 'runfile'), norm(filename)))
            if args:
                line += (",    args='%s'" % norm(args))
            if wdir:
                line += (",    wdir='%s'" % norm(wdir))
            if post_mortem:
                line += ',    post_mortem=True'
            line += ')'
        else:
            line = '%run    '
            if debug:
                line += '-d    '
            line += ('"%s"' % to_text_string(filename))
            if args:
                line += ('    %s' % norm(args))
        self.execute_code(line, current_client, clear_variables)
        self.visibility_changed(True)
        self.raise_()
    else:
        QMessageBox.warning(self, _('Warning'), (_('No    IPython    console    is    currently    available    to    run    <b>%s</b>.<br><br>Please    open    a    new    one    and    try    again.') % osp.basename(filename)), QMessageBox.Ok)
