file
shutil-based sync implementation
clean(root, ignore, dry_run)
Recursively remove all files and symlinks from the root path while respecting the provided ignore pattern
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
Path
|
The root directory. And this should absolutely be a directory. |
required |
ignore |
Callable
|
The ignore pattern created by |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
Source code in enderchest/sync/file.py
copy(source_path, destination_folder, exclude, delete, dry_run)
Copy the specified source file or folder to the provided destination, overwriting any existing files and deleting any that weren't in the source
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_path |
ParseResult
|
The file or folder to copy |
required |
destination_folder |
Path
|
The destination to put the source file(s) |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync (and sync) |
required |
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
Notes
If the source file does not exist, the destination file will simply be deleted (if it exists)
Source code in enderchest/sync/file.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
get_contents(path)
Recursively list the contents of a local directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
The path to scan |
required |
Returns:
Type | Description |
---|---|
list of filenames and attributes
|
The attributes of all files, folders and symlinks found under the specified path |
Notes
- This list will be sorted from shortest path to longest (so that parent directories come before their children)
- The paths returned are all relative to the provided path
Source code in enderchest/sync/file.py
ignore_patterns(*patterns)
shutil.ignore_patterns doesn't support checking absolute paths, so we gotta roll our own.
This implementation is adapted from https://github.com/python/cpython/blob/3.11/Lib/shutil.py#L440-L450 and https://stackoverflow.com/a/7842224
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*patterns |
str
|
The patterns to match |
()
|
Returns:
Type | Description |
---|---|
Callable
|
An "ignore" filter suitable for use in |
Source code in enderchest/sync/file.py
pull(remote_uri, local_path, exclude, dry_run, delete=True, **unsupported_kwargs)
Copy an upstream file or folder into the specified location, where the remote is another folder on this machine. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_uri |
ParseResult
|
The URI for the remote resource to copy from. See notes. |
required |
local_path |
Path
|
The destination folder |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
**unsupported_kwargs |
Any other provided options will be ignored |
{}
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination folder does not exist |
Notes
- This method is only meant to be used for local files specified using the file:// protocol, but it does not perform any validation on the URI to ensure that the schema is correct or that the hostname corresponds to this machine. This method does not support user authentication (running the copy as a different user).
- If the destination folder does not already exist, this method will not create it or its parent directories.
Source code in enderchest/sync/file.py
push(local_path, remote_uri, exclude, dry_run, delete=True, **unsupported_kwargs)
Copy a local file or folder into the specified location, where the remote is another folder on this machine. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path |
Path
|
The file or folder to copy |
required |
remote_uri |
ParseResult
|
The URI for the remote location to copy into. See notes. |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
**unsupported_kwargs |
Any other provided options will be ignored |
{}
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination folder does not exist |
Notes
- This method is only meant to be used for local files specified using the file:// protocol, but it does not perform any validation on the URI to ensure that the schema is correct or that the hostname corresponds to this machine. This method does not support user authentication (running the copy as a different user).
- If the destination folder does not already exist, this method will not create it or its parent directories.