RefactoringRope/FileSystemCommands.py

Fri, 02 May 2014 21:06:07 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Fri, 02 May 2014 21:06:07 +0200
changeset 76
936b2a98fe4e
parent 62
1077db8d0589
parent 63
c02061242598
child 94
03d6a17c66ac
permissions
-rw-r--r--

Merge with Py2 comp.

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing file system commands for rope.
"""

from __future__ import unicode_literals

import os

import rope.base.fscommands

from E5Gui.E5Application import e5App


class E5FileSystemCommands(object):
    """
    Class implementing file system commands for rope.
    """
    def __init__(self, project):
        """
        Constructor
        
        @param project reference to the eric4 project object (Project.Project)
        """
        self.__project = project
        self.__normal_actions = rope.base.fscommands.FileSystemCommands()
    
    def create_file(self, path):
        """
        Public method called by rope to create a new file.
        
        @param path new filename (string)
        """
        self.__normal_actions.create_file(path)
        self.__project.appendFile(path)
        vcs = self.__project.getVcs()
        if vcs is not None:
            vcs.vcsAdd(path, noDialog=True)
    
    def create_folder(self, path):
        """
        Public method called by rope to create a new directory.
        
        @param path new directory (string)
        """
        self.__normal_actions.create_folder(path)
        vcs = self.__project.getVcs()
        if vcs is not None:
            vcs.vcsAdd(path, noDialog=True)
    
    def move(self, path, new_location):
        """
        Public method called by rope to rename a file or directory.
        
        @param path old file/directory name (string)
        @param new_location new file/directory name (string)
        """
        vcs = self.__project.getVcs()
        if vcs is None:
            if os.path.isdir(path):
                self.__project.moveDirectory(path, new_location)
            else:
                self.__project.renameFile(path, new_location)
        else:
            vcs.vcsMove(path, self.__project, new_location, noDialog=True)
    
    def remove(self, path):
        """
        Public method called by rope to remove a file or directory.
        
        @param path name of file/directory to remove (string)
        """
        vcs = self.__project.getVcs()
        if vcs is None:
            if os.path.isdir(path):
                self.__project.removeDirectory(path)
            else:
                e5App().getObject("ViewManager").closeWindow(path)
                self.__project.removeFile(path)
            self.__normal_actions.remove(path)
        else:
            vcs.vcsRemove(path, noDialog=True)
    
    def write(self, path, data):
        """
        Public method called by rope to write data to a file.
        
        @param path filename of file to write to (string)
        @param data dat to be written
        """
        self.__normal_actions.write(path, data)

eric ide

mercurial