Exemplo n.º 1
0
    def execute(self, string, data=None):
        """
        Start executing the given string in this subprocess.

        INPUT:

            - ``string`` -- a string containing code to be executed.

            - ``data`` -- a string or None; if given, must specify an
              absolute path on the server host filesystem.   This may
              be ignored by some worksheet process implementations.
        """
        if self._expect is None:
            self.start()

        if self._expect is None:
            raise RuntimeError(
                "unable to start subprocess using command '%s'" %
                self.command())

        self._number += 1

        local, remote = self.get_tmpdir()

        if data is not None:
            # make a symbolic link from the data directory into local tmp directory
            self._data = os.path.split(data)[1]
            self._data_dir = data
            set_permissive_permissions(data)
            os.symlink(data, os.path.join(local, self._data))
        else:
            self._data = ''

        self._tempdir = local
        sage_input = '_sage_input_%s.py' % self._number
        self._filename = os.path.join(self._tempdir, sage_input)
        self._so_far = ''
        self._is_computing = True

        self._all_tempdirs.append(self._tempdir)
        open(self._filename,
             'w').write(format_for_pexpect(string, self._prompt, self._number))
        try:
            self._expect.sendline(
                '\nimport os;os.chdir("%s");\nexecfile("%s")' %
                (remote, sage_input))
        except OSError as msg:
            self._is_computing = False
            self._so_far = str(msg)
Exemplo n.º 2
0
    def execute(self, string, data=None):
        """
        Start executing the given string in this subprocess.

        INPUT:

            - ``string`` -- a string containing code to be executed.

            - ``data`` -- a string or None; if given, must specify an
              absolute path on the server host filesystem.   This may
              be ignored by some worksheet process implementations.
        """
        if self._expect is None:
            self.start()

        if self._expect is None:
            msg = "unable to start subprocess using command '%s'" % self.command()
            raise RuntimeError(msg)

        self._number += 1

        local, remote = self.get_tmpdir()

        if data is not None:
            # make a symbolic link from the data directory into local
            # tmp directory
            self._data = os.path.split(data)[1]
            self._data_dir = data
            set_permissive_permissions(data)
            os.symlink(data, os.path.join(local, self._data))
        else:
            self._data = ''

        self._tempdir = local
        sage_input = '_sage_input_%s.py' % self._number
        self._filename = os.path.join(self._tempdir, sage_input)
        self._so_far = ''
        self._is_computing = True

        self._all_tempdirs.append(self._tempdir)
        open(self._filename, 'w').write(format_for_pexpect(string, self._prompt,
                                                           self._number))
        try:
            txt = '\nimport os;os.chdir("%s");\nexecfile("%s")' % (remote,
                                                                   sage_input)
            self._expect.sendline(txt)
        except OSError as msg:
            self._is_computing = False
            self._so_far = str(msg)
Exemplo n.º 3
0
 def get_tmpdir(self):
     """
     Return two strings (local, remote), where local is the name
     of a pre-created temporary directory, and remote is the name
     of the same directory but on the machine on which the actual
     worksheet process is running.
     """
     # In this implementation the remote process is just running
     # as the same user on the local machine.
     local = tempfile.mkdtemp(dir=self._local_directory)
     remote = os.path.join(self._remote_directory, local[len(self._local_directory):].lstrip(os.path.sep))
     # Make it so local is world read/writable -- so that the remote worksheet
     # process can write to it.
     set_permissive_permissions(local)
     return (local, remote)
Exemplo n.º 4
0
    def execute(self, string, data=None):
        """
        Start executing the given string in this subprocess.

        INPUT:

            - ``string`` -- a string containing code to be executed.

            - ``data`` -- a string or None; if given, must specify an
              absolute path on the server host filesystem.   This may
              be ignored by some worksheet process implementations.
        """
        if self._expect is None:
            self.start()

        if self._expect is None:
            raise RuntimeError, "unable to start subprocess using command '%s'"%self.command()
        
        self._number += 1

        local, remote = self.get_tmpdir()

        if data is not None:
            # make a symbolic link from the data directory into local tmp directory
            self._data = os.path.split(data)[1]
            self._data_dir = data
            set_permissive_permissions(data)
            os.symlink(data, os.path.join(local, self._data))
        else:
            self._data = ''
            
        self._tempdir = local
        sage_input = '_sage_input_%s.py'%self._number
        self._filename = os.path.join(self._tempdir, sage_input)
        self._so_far = ''
        self._is_computing = True

        self._all_tempdirs.append(self._tempdir)
        # The magic comment at the very start of the file allows utf8 characters.
        open(self._filename,'w').write(
            '# -*- coding: utf_8 -*-\nimport sys;sys.ps1="%s";print "START%s"\n'%(
            self._prompt, self._number) + displayhook_hack(string))
        try:
            self._expect.sendline('\nimport os;os.chdir("%s");\nexecfile("%s")'%(
                              remote, sage_input))
        except OSError, msg:
            self._is_computing = False
            self._so_far = str(msg)
Exemplo n.º 5
0
 def get_tmpdir(self):
     """
     Return two strings (local, remote), where local is the name
     of a pre-created temporary directory, and remote is the name
     of the same directory but on the machine on which the actual
     worksheet process is running.
     """
     # In this implementation the remote process is just running
     # as the same user on the local machine.
     local = tempfile.mkdtemp(dir=self._local_directory)
     remote = os.path.join(self._remote_directory,
                           local[len(self._local_directory):].lstrip(os.path.sep))
     # Make it so local is world read/writable -- so that the
     # remote worksheet process can write to it.
     set_permissive_permissions(local)
     return (local, remote)