rope.base.resources
Files and folders in a project are represented as resource objects.
Files and folders are access through Resource objects. Resource has two subclasses: File and Folder. What we care about is that refactorings and `rope.base.change.Change`s use resources.
There are two options to create a Resource for a path in a project. Note that in these examples path is the path to a file or folder relative to the project’s root. A project’s root folder is represented by an empty string.
Use the rope.base.Project.get_resource() method. E.g.:
myresource = myproject.get_resource(path)
Use the rope.base.libutils module. libutils has a function named path_to_resource(). It takes a project and a path:
from rope.base import libutils
myresource = libutils.path_to_resource(myproject, path)
Once we have a Resource, we can retrieve information from it, like getting the path relative to the project’s root (via path), reading from and writing to the resource, moving the resource, etc.
Classes
Represents files and folders in a project |
|
Represents a file |
|
Represents a folder |
Module Contents
- class rope.base.resources.Resource(project, path)
Bases:
os.PathLikeRepresents files and folders in a project
- project
- move(new_location)
Move resource to new_location
- remove()
Remove resource from the project
- is_dir()
Alias for is_folder()
- is_folder()
Return True if the resource is a Folder
- create()
Create this resource
- exists()
- property parent
- property path: str
Return the path of this resource relative to the project root
The path is the list of parent directories separated by ‘/’ followed by the resource name.
- property pathlib: pathlib.Path
Return the file as a pathlib path.
- class rope.base.resources.File(project, name)
Bases:
ResourceRepresents a file
- newlines = None
- read()
- read_bytes()
- write(contents)
- is_folder()
Return True if the resource is a Folder
- create()
Create this resource
- project
- move(new_location)
Move resource to new_location
- remove()
Remove resource from the project
- is_dir()
Alias for is_folder()
- exists()
- property parent
- property path: str
Return the path of this resource relative to the project root
The path is the list of parent directories separated by ‘/’ followed by the resource name.
- property pathlib: pathlib.Path
Return the file as a pathlib path.
- class rope.base.resources.Folder(project, path)
Bases:
ResourceRepresents a folder
- is_folder()
Return True if the resource is a Folder
- get_children()
Return the children of this folder
- create_file(file_name)
- create_folder(folder_name)
- get_child(name)
- has_child(name)
- get_files()
- get_folders()
- contains(resource)
- create()
Create this resource
- project
- move(new_location)
Move resource to new_location
- remove()
Remove resource from the project
- is_dir()
Alias for is_folder()
- exists()
- property parent
- property path: str
Return the path of this resource relative to the project root
The path is the list of parent directories separated by ‘/’ followed by the resource name.
- property pathlib: pathlib.Path
Return the file as a pathlib path.