Logo Search packages:      
Sourcecode: zope-externaleditor version File versions  Download package

def ExternalEditor::zopeedit::ExternalEditor::launch (   self )
Launch external editor

Definition at line 300 of file zopeedit.py.

        """Launch external editor"""
        use_locks = int(self.options.get('use_locks', 0))
        if use_locks and self.metadata.get('lock-token'):
            # A lock token came down with the data, so the object is
            # already locked, see if we can borrow the lock
            if (int(self.options.get('always_borrow_locks', 0))
                or self.metadata.get('borrow_lock')
                or askYesNo('This object is already locked by you in another'
                            ' session.\n Do you want to borrow this lock'
                            ' and continue?')):
                self.lock_token = 'opaquelocktoken:%s' \
                                  % self.metadata['lock-token']
        save_interval = float(self.options.get('save_interval'))
        last_mtime = os.path.getmtime(self.content_file)
        command = self.getEditorCommand()

        # Extract the executable name from the command
        if win32:
            if command.find('\\') != -1:
                bin = re.search(r'\\([^\.\\]+)\.exe', command.lower())
                if bin is not None:
                    bin = bin.group(1)
                bin = command.lower().strip()
            bin = command

        if bin is not None:
            # Try to load the plugin for this editor
                module = 'Plugins.%s' % bin
                Plugin = __import__(module, globals(), locals(), 
                editor = Plugin.EditorProcess(self.content_file)
            except (ImportError, AttributeError):
                bin = None

        if bin is None: 
            # Use the standard EditorProcess class for this editor
            if win32:
                file_insert = '%1'
                file_insert = '$1'
            if command.find(file_insert) > -1:
                command = command.replace(file_insert, self.content_file)
                command = '%s %s' % (command, self.content_file)

            editor = EditorProcess(command)
        launch_success = editor.isAlive()
        if use_locks:

        final_loop = 0
        while 1:
            if not final_loop:
                editor.wait(save_interval or 2)

            mtime = os.path.getmtime(self.content_file)

            if mtime != last_mtime:
                if save_interval or final_loop:
                    launch_success = 1 # handle very short editing sessions
                    self.saved = self.putChanges()
                    last_mtime = mtime

            if not editor.isAlive():
                if final_loop:
                    # Go through the loop one final time for good measure.
                    # Our editor's isAlive method may itself *block* during a
                    # save operation (seen in COM calls, which seem to
                    # respond asynchronously until they don't) and subsequently
                    # return false, but the editor may have actually saved the
                    # file to disk while the call blocked.  We want to catch
                    # any changes that happened during a blocking isAlive call.
                    final_loop = 1

        if not launch_success:
            fatalError('Editor did not launch properly.\n'
                       'External editor lost connection '
                       'to editor process.\n'
                       '(%s)' % command)
        if use_locks:
        if not self.saved \
           and askYesNo('File not saved to Zope.\nReopen local copy?'):

Generated by  Doxygen 1.6.0   Back to index