rope_py3k / rope / base / fscommands.py

"""Project file system commands.

This modules implements file system operations used by rope.
Different version control systems can supported by implementing the
interface provided by `FileSystemCommands` class.

"""

import os
import shutil

try:
    import pysvn
except ImportError:
    pass


def create_fscommands(root):
    if 'pysvn' in globals() and '.svn' in os.listdir(root):
        return SubversionCommands()
    return FileSystemCommands()


class FileSystemCommands(object):
    
    def create_file(self, path):
        open(path, 'w').close()
    
    def create_folder(self, path):
        os.mkdir(path)
    
    def move(self, path, new_location):
        shutil.move(path, new_location)
    
    def remove(self, path):
        if os.path.isfile(path):
            os.remove(path)
        else:
            shutil.rmtree(path)


class SubversionCommands(object):
    
    def __init__(self):
        self.normal_actions = FileSystemCommands()
        self.client = pysvn.Client()
    
    def create_file(self, path):
        self.normal_actions.create_file(path)
        self.client.add(path, force=True)
    
    def create_folder(self, path):
        self.normal_actions.create_folder(path)
        self.client.add(path, force=True)
    
    def move(self, path, new_location):
        self.client.move(path, new_location, force=True)
    
    def remove(self, path):
        self.client.remove(path, force=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.