pyRclone
A typed rClone interface for python.
Written to more easily express awkward logic, that would be a pain or not (easily) possible on the command line.
A short example, to tidy up and half the number of backups is shown below. The logic can be trivially expanded to instead say, parse the time stamp of the backup out of the folder name, to allow different logic to be applied depending on the age of a backup (do nothing if 1 month old, half is 2 months old, remove every other after a year old etc).
import json
import logging
import os
import sys
from pyrclone import Rclone, RcloneError
def main():
# Setup rclone runner, and have it run in verbose and dry run mode.
rclone: Rclone = Rclone()
rclone.verbose_mode = True
rclone.dry_run_mode = True
# Attach a logger, for more immediate output, rather than just on command completion.
rclone.logger.setLevel(logging.DEBUG)
handler: logging.StreamHandler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter: logging.Formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
rclone.logger.addHandler(handler)
# List all folders in backup directory to iterate over them.
remote_path: str = "drive:PC/Backups"
output = rclone.lsd(remote_path)
# If we failed to run, stop.
if output.return_code is not RcloneError.SUCCESS:
print(output.error)
return
# lsd (and all other ls commands) will default to using lsjson.
# Lets decode the JSON, and get a list of all our folders.
backup_folders = []
for folder in json.loads("".join(files)):
backup_folders.append(f"{remote_path}/{folder['Path']}")
# With our list of folders, lets delete every other folder, excluding these
# useful ones.
#
# This could also be more indepth logic, such as using the modified timestamp
# or the timestamp in the folder name to do logic to different backups of
# varying age. This is allows the ease of scripting in Python to help, versus
# confusing/verbose command line options and shell scripts.
ignore_list = [
"drive:PC/Backups/2017-09-18_WindowsUpdate",
"drive:PC/Backups/2019-07-30_FlatMove",
"drive:PC/Backups/2019-08-12_HDD-Swap",
]
# Iterate over every other folder and delete if not in the ignore.
#
# Of course, right now we are in dry_run mode, so this won't do anything
# except list what it would have done.
for folder in backup_folders[1::2]:
if folder in ignore_list:
continue
rclone.delete(folder)
if __name__ == "__main__":
main()
Metadata
Release files for pyrclone 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyrclone-1.0.1.tar.gz | 17.5 kB | Without provenance | Details for pyrclone-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyRclone-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyRclone-1.0.1-py3-none-any.whl |
Total release size: 35.6 kB
Release files / pyrclone-1.0.1.tar.gz
| Download URL | pyrclone-1.0.1.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6baaea54d1104dba854c06b9680ce5e395068d78b937a8bb6bf4a07c028b37a
|
|
BLAKE2b-256 checksum How to use checksums |
80f9f50fd8e6b241705382c78a6a5159a900483a9f0b1fca5bbd95162a9f9c1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.3 CPython/3.7.3 Windows/10
|
Release files / pyRclone-1.0.1-py3-none-any.whl
| Download URL | pyRclone-1.0.1-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
edea1230efb424e7d4ded9bbb52d44b6f9611a50f221fbd386533666afa591f4
|
|
BLAKE2b-256 checksum How to use checksums |
09d17c66e2b2962005f5d0bb9ee235677797e58454e758a3b300e77564282127
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.3 CPython/3.7.3 Windows/10
|
Security for pyrclone 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.