RefactoringRope/FileSystemCommands.py

Sat, 31 Dec 2016 13:51:04 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2016 13:51:04 +0100
changeset 147
3f8a995f6e49
parent 144
bfc6a3b38330
child 162
55eaaed9d590
permissions
-rw-r--r--

Updated copyright for 2017.

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

# Copyright (c) 2010 - 2017 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