Exemplo n.º 1
0
def run_python_script_in_terminal(fname, wdir, args, interact,
                                  debug, python_args):
    """Run Python script in an external system terminal"""
    
    # If fname has spaces on it it can't be ran on Windows, so we have to
    # enclose it in quotes
    if os.name == 'nt':
        fname = '"' + fname + '"'
    
    p_args = ['python']
    p_args += get_python_args(fname, python_args, interact, debug, args)
    
    if os.name == 'nt':
        # Command line and cwd have to be converted to the filesystem
        # encoding before passing them to subprocess
        # See http://bugs.python.org/issue1759845#msg74142
        cmd = encoding.to_fs_from_unicode(
                'start cmd.exe /c "cd %s && ' % wdir + ' '.join(p_args) + '"')
        subprocess.Popen(cmd, shell=True,
                         cwd=encoding.to_fs_from_unicode(wdir))
    elif os.name == 'posix':
        cmd = 'gnome-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'konsole'
        if is_program_installed(cmd):
            run_program(cmd, ['--workdir', wdir, '-e'] + p_args,
                        cwd=wdir)
            return
        # TODO: Add a fallback to xterm for Linux and the necessary code for
        #       OSX
    else:
        raise NotImplementedError
Exemplo n.º 2
0
def run_python_script_in_terminal(fname, wdir, args, interact, debug,
                                  python_args):
    """Run Python script in an external system terminal"""

    # If fname has spaces on it it can't be ran on Windows, so we have to
    # enclose it in quotes
    if os.name == 'nt':
        fname = '"' + fname + '"'

    p_args = ['python']
    p_args += get_python_args(fname, python_args, interact, debug, args)

    if os.name == 'nt':
        # Command line and cwd have to be converted to the filesystem
        # encoding before passing them to subprocess
        # See http://bugs.python.org/issue1759845#msg74142
        cmd = encoding.to_fs_from_unicode('start cmd.exe /c "cd %s && ' %
                                          wdir + ' '.join(p_args) + '"')
        subprocess.Popen(cmd,
                         shell=True,
                         cwd=encoding.to_fs_from_unicode(wdir))
    elif os.name == 'posix':
        cmd = 'gnome-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'konsole'
        if is_program_installed(cmd):
            run_program(cmd, ['--workdir', wdir, '-e'] + p_args, cwd=wdir)
            return
        # TODO: Add a fallback to xterm for Linux and the necessary code for
        #       OSX
    else:
        raise NotImplementedError
Exemplo n.º 3
0
def run_python_script_in_terminal(fname, wdir, args, interact,
                                  debug, python_args):
    """Run Python script in an external system terminal"""
    
    # If fname has spaces on it it can't be ran on Windows, so we have to
    # enclose it in quotes. Also wdir can come with / as os.sep, so we
    # need to take care of it
    if os.name == 'nt':
        fname = '"' + fname + '"'
        wdir = wdir.replace('/', '\\')
    
    p_args = ['python']
    p_args += get_python_args(fname, python_args, interact, debug, args)
    
    if os.name == 'nt':
        cmd = 'start cmd.exe /c "cd %s && ' % wdir + ' '.join(p_args) + '"'
        # Command line and cwd have to be converted to the filesystem
        # encoding before passing them to subprocess, but only for
        # Python 2.
        # See http://bugs.python.org/issue1759845#msg74142 and Issue 1856
        if PY2:
            cmd = encoding.to_fs_from_unicode(cmd)
            wdir = encoding.to_fs_from_unicode(wdir)
        try:
            run_shell_command(cmd, cwd=wdir)
        except WindowsError:
            from qtpy.QtWidgets import QMessageBox

            from spyderlib.config.base import _

            QMessageBox.critical(None, _('Run'),
                                 _("It was not possible to run this file in "
                                   "an external terminal"),
                                 QMessageBox.Ok)
    elif os.name == 'posix':
        cmd = 'gnome-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'konsole'
        if is_program_installed(cmd):
            run_program(cmd, ['--workdir', wdir, '-e'] + p_args,
                        cwd=wdir)
            return
        cmd = 'xfce4-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'xterm'
        if is_program_installed(cmd):
            run_program(cmd, ['-e'] + p_args + [wdir])
            return		
        # TODO: Add a fallback to OSX
    else:
        raise NotImplementedError
Exemplo n.º 4
0
def run_python_script_in_terminal(fname, wdir, args, interact, debug,
                                  python_args):
    """Run Python script in an external system terminal"""

    # If fname has spaces on it it can't be ran on Windows, so we have to
    # enclose it in quotes. Also wdir can come with / as os.sep, so we
    # need to take care of it
    if os.name == 'nt':
        fname = '"' + fname + '"'
        wdir = wdir.replace('/', '\\')

    p_args = ['python']
    p_args += get_python_args(fname, python_args, interact, debug, args)

    if os.name == 'nt':
        cmd = 'start cmd.exe /c "cd %s && ' % wdir + ' '.join(p_args) + '"'
        # Command line and cwd have to be converted to the filesystem
        # encoding before passing them to subprocess, but only for
        # Python 2.
        # See http://bugs.python.org/issue1759845#msg74142 and Issue 1856
        if PY2:
            cmd = encoding.to_fs_from_unicode(cmd)
            wdir = encoding.to_fs_from_unicode(wdir)
        try:
            run_shell_command(cmd, cwd=wdir)
        except WindowsError:
            from qtpy.QtWidgets import QMessageBox

            from spyderlib.config.base import _

            QMessageBox.critical(
                None, _('Run'),
                _("It was not possible to run this file in "
                  "an external terminal"), QMessageBox.Ok)
    elif os.name == 'posix':
        cmd = 'gnome-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'konsole'
        if is_program_installed(cmd):
            run_program(cmd, ['--workdir', wdir, '-e'] + p_args, cwd=wdir)
            return
        cmd = 'xfce4-terminal'
        if is_program_installed(cmd):
            run_program(cmd, ['--working-directory', wdir, '-x'] + p_args,
                        cwd=wdir)
            return
        cmd = 'xterm'
        if is_program_installed(cmd):
            run_program(cmd, ['-e'] + p_args + [wdir])
            return
        # TODO: Add a fallback to OSX
    else:
        raise NotImplementedError
Exemplo n.º 5
0
def run_python_script_in_terminal(fname, wdir, args, interact, debug, python_args):
    """Run Python script in an external system terminal"""

    # If fname has spaces on it it can't be ran on Windows, so we have to
    # enclose it in quotes. Also wdir can come with / as os.sep, so we
    # need to take care of it
    if os.name == "nt":
        fname = '"' + fname + '"'
        wdir = wdir.replace("/", "\\")

    p_args = ["python"]
    p_args += get_python_args(fname, python_args, interact, debug, args)

    if os.name == "nt":
        cmd = 'start cmd.exe /c "cd %s && ' % wdir + " ".join(p_args) + '"'
        # Command line and cwd have to be converted to the filesystem
        # encoding before passing them to subprocess, but only for
        # Python 2.
        # See http://bugs.python.org/issue1759845#msg74142 and Issue 1856
        if PY2:
            cmd = encoding.to_fs_from_unicode(cmd)
            wdir = encoding.to_fs_from_unicode(wdir)
        try:
            subprocess.Popen(cmd, shell=True, cwd=wdir)
        except WindowsError:
            from spyderlib.qt.QtGui import QMessageBox
            from spyderlib.config.base import _

            QMessageBox.critical(
                None, _("Run"), _("It was not possible to run this file in " "an external terminal"), QMessageBox.Ok
            )
    elif os.name == "posix":
        cmd = "gnome-terminal"
        if is_program_installed(cmd):
            run_program(cmd, ["--working-directory", wdir, "-x"] + p_args, cwd=wdir)
            return
        cmd = "konsole"
        if is_program_installed(cmd):
            run_program(cmd, ["--workdir", wdir, "-e"] + p_args, cwd=wdir)
            return
        cmd = "xfce4-terminal"
        if is_program_installed(cmd):
            run_program(cmd, ["--working-directory", wdir, "-x"] + p_args, cwd=wdir)
            return
        cmd = "xterm"
        if is_program_installed(cmd):
            run_program(cmd, ["-e"] + p_args + [wdir])
            return
        # TODO: Add a fallback to OSX
    else:
        raise NotImplementedError
Exemplo n.º 6
0
 def create_rope_project(self, root_path):
     """Create a Rope project on a desired path"""
     if PY2:
         root_path = encoding.to_fs_from_unicode(root_path)
     else:
         #TODO: test if this is working without any further change in
         # Python 3 with a user account containing unicode characters
         pass
     try:
         import rope.base.project
         self.project = rope.base.project.Project(root_path, **ROPE_PREFS)
     except ImportError:
         print >> STDERR, 'project error'
         self.project = None
         if DEBUG_EDITOR:
             log_last_error(LOG_FILENAME,
                            "create_rope_project: %r" % root_path)
     except TypeError:
         # Compatibility with new Mercurial API (>= 1.3).
         # New versions of rope (> 0.9.2) already handle this issue
         self.project = None
         if DEBUG_EDITOR:
             log_last_error(LOG_FILENAME,
                            "create_rope_project: %r" % root_path)
     self.validate()
Exemplo n.º 7
0
 def create_rope_project(self, root_path):
     """Create a Rope project on a desired path"""
     if PY2:
         root_path = encoding.to_fs_from_unicode(root_path)
     else:
         #TODO: test if this is working without any further change in
         # Python 3 with a user account containing unicode characters
         pass
     try:
         import rope.base.project
         self.project = rope.base.project.Project(root_path, **ROPE_PREFS)
     except ImportError:
         print >>STDERR, 'project error'
         self.project = None
         if DEBUG_EDITOR:
             log_last_error(LOG_FILENAME,
                            "create_rope_project: %r" % root_path)
     except TypeError:
         # Compatibility with new Mercurial API (>= 1.3).
         # New versions of rope (> 0.9.2) already handle this issue
         self.project = None
         if DEBUG_EDITOR:
             log_last_error(LOG_FILENAME,
                            "create_rope_project: %r" % root_path)
     self.validate()