sysrsync


Namesysrsync JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/gchamon/sysrsync
SummarySimple and safe python wrapper for calling system rsync
upload_time2023-04-24 14:29:38
maintainer
docs_urlNone
authorGabriel Chamon
requires_python>=3.6,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sysrsync
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Simple and safe native rsync wrapper for Python 3

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gchamon_sysrsync&metric=alert_status)](https://sonarcloud.io/dashboard?id=gchamon_sysrsync)

## Requirements

* rsync
* python 3.6+

**development**:

* poetry (be sure to have both poetry and pip upgraded to the latest version)

## Installation

`pip install sysrsync`

## Basic rules

- Syncs source contents by default, so it adds a trailing slash to the end of source, unless `sync_source_contents=False` is specified
- Removes trailing slash from destination
- Extra arguments are put right after `rsync`
- Breaks if `source_ssh` and `destination_ssh` are both set

## Usage

* Basic file sync

```python
import sysrsync

sysrsync.run(source='/home/user/foo.txt',
             destination='/home/server/bar')
# runs 'rsync /home/users/foo.txt /home/server/files'
```

* sync whole folder

```python
import sysrsync

sysrsync.run(source='/home/user/files',
             destination='/home/server/',
             sync_source_contents=False)
# runs 'rsync /home/user/files /home/server'
```

* sync folder contents

```python
import sysrsync

sysrsync.run(source='/home/user/files',
             destination='/home/server/',
             sync_source_contents=True)
# runs 'rsync /home/user/files/ /home/server'
```

* ssh with options

```python
import sysrsync

sysrsync.run(source='/home/user/files',
             destination='/home/server/files',
             destination_ssh='myserver',
             options=['-a'])
# runs 'rsync -a /home/users/files/ myserver:/home/server/files'
```

* exclusions

```python
import sysrsync

sysrsync.run(source='/home/user/files',
             destination='/home/server/files',
             destination_ssh='myserver',
             options=['-a'],
             exclusions=['file_to_exclude', 'unwanted_file'])
# runs 'rsync -a /home/user/files/ myserver:/home/server/files --exclude file_to_exclude --exclude unwanted_file'
```
* Private key

```python
import sysrsync

sysrsync.run(source='/home/user/files',
             destination='/home/server/files',
             destination_ssh='myserver',
             private_key="totally_secure_key")
# runs 'rsync --rsh='ssh -i totally_secure_key' /home/user/files/ myserver:/home/server/files'
```

## API

`sysrsync.run`

| argument  | type | default | description |
| --------- | ---- | ------- | ----------- |
| cwd  | str  | `os.getcwd()` | working directory in which subprocess will run the rsync command |
| strict  | bool | `True` | raises `RsyncError` when rsync return code is different than 0  |
| verbose | bool | `False` | verbose mode: currently prints rsync command before executing |
| **kwargs | dict | Not Applicable | arguments that will be forwarded to call to `sysrsync.get_rsync_command` |

**returns**: `subprocess.CompletedProcess`

**raises**:
- `RsyncError` when `strict = True` and rsync return code is different than 0 ([Success](https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes))

`sysrsync.get_rsync_command`

| argument  | type | default | description |
| --------- | ---- | ------- | ----------- |
| source | str | - | Source folder or file |
| destination | str | - | Destination folder |
| source_ssh | Optional[str] | None | Remote ssh client where source is located |
| destination_ssh | Optional[str] | None | Remote ssh client where destination is located |
| exclusions | Optional[Iterable[str]] | None | List of excluded patterns as in rsync's `--exclude` |
| sync_source_contents | bool | True | Abstracts the elusive trailing slash behaviour that `source` normally has when using rsync directly, i.e. when a trailing slash is present in `source`, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination. |
| options | Optional[Iterable[str]] | None | List of options to be used right after rsync call, e.g. `['-a', '-v']` translates to `rsync -a -v` |
| private_key | Optional[str] | None | Configures an explicit key to be used with rsync --rsh command |
| rsh_port | Optional[int] | None | Specify port to be used for --rsh command |
| strict_host_key_checking | Optional[bool] | None | set StrictHostKeyChecking property for rsh #cf. https://superuser.com/questions/125324/how-can-i-avoid-sshs-host-verification-for-known-hosts |

**returns**: `List[str]` -> the compiled list of commands to be used directly in `subprocess.run`

**raises**:
- `RemotesError` when both `source_ssh` and `destination_ssh` are set. Normally linux rsync distribution disallows source and destination to be both remotes.
- `PrivateKeyError` when `private_key` doesn't exist

# Contributing

- Fork project
- Install dependencies with `poetry install`
- Make changes
- Lint with `poetry run pylint ./sysrsync`
- Test with `poetry run python -m unittest`
- Run end-to-end tests with `bash end-to-end-tests/run-tests.sh`
- Submit changes with a pull request

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/plazmakeks"><img src="https://avatars.githubusercontent.com/u/25690073?v=4?s=100" width="100px;" alt="plazmakeks"/><br /><sub><b>plazmakeks</b></sub></a><br /><a href="https://github.com/gchamon/sysrsync/commits?author=plazmakeks" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://stevehenderson.github.io/"><img src="https://avatars.githubusercontent.com/u/2936416?v=4?s=100" width="100px;" alt="Steve Henderson"/><br /><sub><b>Steve Henderson</b></sub></a><br /><a href="https://github.com/gchamon/sysrsync/commits?author=stevehenderson" title="Code">💻</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gchamon/sysrsync",
    "name": "sysrsync",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Gabriel Chamon",
    "author_email": "gchamon@live.com",
    "download_url": "https://files.pythonhosted.org/packages/24/a0/eaf4f0691639d603ba3da73c4ebbd3da22dfae09565ab7ba38bc28d17de2/sysrsync-1.1.1.tar.gz",
    "platform": null,
    "description": "# sysrsync\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\nSimple and safe native rsync wrapper for Python 3\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gchamon_sysrsync&metric=alert_status)](https://sonarcloud.io/dashboard?id=gchamon_sysrsync)\n\n## Requirements\n\n* rsync\n* python 3.6+\n\n**development**:\n\n* poetry (be sure to have both poetry and pip upgraded to the latest version)\n\n## Installation\n\n`pip install sysrsync`\n\n## Basic rules\n\n- Syncs source contents by default, so it adds a trailing slash to the end of source, unless `sync_source_contents=False` is specified\n- Removes trailing slash from destination\n- Extra arguments are put right after `rsync`\n- Breaks if `source_ssh` and `destination_ssh` are both set\n\n## Usage\n\n* Basic file sync\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/foo.txt',\n             destination='/home/server/bar')\n# runs 'rsync /home/users/foo.txt /home/server/files'\n```\n\n* sync whole folder\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/files',\n             destination='/home/server/',\n             sync_source_contents=False)\n# runs 'rsync /home/user/files /home/server'\n```\n\n* sync folder contents\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/files',\n             destination='/home/server/',\n             sync_source_contents=True)\n# runs 'rsync /home/user/files/ /home/server'\n```\n\n* ssh with options\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/files',\n             destination='/home/server/files',\n             destination_ssh='myserver',\n             options=['-a'])\n# runs 'rsync -a /home/users/files/ myserver:/home/server/files'\n```\n\n* exclusions\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/files',\n             destination='/home/server/files',\n             destination_ssh='myserver',\n             options=['-a'],\n             exclusions=['file_to_exclude', 'unwanted_file'])\n# runs 'rsync -a /home/user/files/ myserver:/home/server/files --exclude file_to_exclude --exclude unwanted_file'\n```\n* Private key\n\n```python\nimport sysrsync\n\nsysrsync.run(source='/home/user/files',\n             destination='/home/server/files',\n             destination_ssh='myserver',\n             private_key=\"totally_secure_key\")\n# runs 'rsync --rsh='ssh -i totally_secure_key' /home/user/files/ myserver:/home/server/files'\n```\n\n## API\n\n`sysrsync.run`\n\n| argument  | type | default | description |\n| --------- | ---- | ------- | ----------- |\n| cwd  | str  | `os.getcwd()` | working directory in which subprocess will run the rsync command |\n| strict  | bool | `True` | raises `RsyncError` when rsync return code is different than 0  |\n| verbose | bool | `False` | verbose mode: currently prints rsync command before executing |\n| **kwargs | dict | Not Applicable | arguments that will be forwarded to call to `sysrsync.get_rsync_command` |\n\n**returns**: `subprocess.CompletedProcess`\n\n**raises**:\n- `RsyncError` when `strict = True` and rsync return code is different than 0 ([Success](https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes))\n\n`sysrsync.get_rsync_command`\n\n| argument  | type | default | description |\n| --------- | ---- | ------- | ----------- |\n| source | str | - | Source folder or file |\n| destination | str | - | Destination folder |\n| source_ssh | Optional[str] | None | Remote ssh client where source is located |\n| destination_ssh | Optional[str] | None | Remote ssh client where destination is located |\n| exclusions | Optional[Iterable[str]] | None | List of excluded patterns as in rsync's `--exclude` |\n| sync_source_contents | bool | True | Abstracts the elusive trailing slash behaviour that `source` normally has when using rsync directly, i.e. when a trailing slash is present in `source`, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination. |\n| options | Optional[Iterable[str]] | None | List of options to be used right after rsync call, e.g. `['-a', '-v']` translates to `rsync -a -v` |\n| private_key | Optional[str] | None | Configures an explicit key to be used with rsync --rsh command |\n| rsh_port |\u00a0Optional[int] | None | Specify port to be used for --rsh command |\n| strict_host_key_checking | Optional[bool] | None | set StrictHostKeyChecking property for rsh #cf. https://superuser.com/questions/125324/how-can-i-avoid-sshs-host-verification-for-known-hosts |\n\n**returns**: `List[str]` -> the compiled list of commands to be used directly in `subprocess.run`\n\n**raises**:\n- `RemotesError` when both `source_ssh` and `destination_ssh` are set. Normally linux rsync distribution disallows source and destination to be both remotes.\n- `PrivateKeyError` when `private_key` doesn't exist\n\n# Contributing\n\n- Fork project\n- Install dependencies with `poetry install`\n- Make changes\n- Lint with `poetry run pylint ./sysrsync`\n- Test with `poetry run python -m unittest`\n- Run end-to-end tests with `bash end-to-end-tests/run-tests.sh`\n- Submit changes with a pull request\n\n## Contributors \u2728\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n  <tbody>\n    <tr>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/plazmakeks\"><img src=\"https://avatars.githubusercontent.com/u/25690073?v=4?s=100\" width=\"100px;\" alt=\"plazmakeks\"/><br /><sub><b>plazmakeks</b></sub></a><br /><a href=\"https://github.com/gchamon/sysrsync/commits?author=plazmakeks\" title=\"Code\">\ud83d\udcbb</a></td>\n      <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://stevehenderson.github.io/\"><img src=\"https://avatars.githubusercontent.com/u/2936416?v=4?s=100\" width=\"100px;\" alt=\"Steve Henderson\"/><br /><sub><b>Steve Henderson</b></sub></a><br /><a href=\"https://github.com/gchamon/sysrsync/commits?author=stevehenderson\" title=\"Code\">\ud83d\udcbb</a></td>\n    </tr>\n  </tbody>\n</table>\n\n<!-- markdownlint-restore -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple and safe python wrapper for calling system rsync",
    "version": "1.1.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ce825939e68632beebdb6f61a52246c0243e8490d9f75e0f1a214dda0113d5f2",
                "md5": "de3c6a3cae8a3cd39ea46ac60f42424d",
                "sha256": "9c8877f162dce9c480804445fca56cd19bf41b998d2172651468ccebfdc60850"
            },
            "downloads": -1,
            "filename": "sysrsync-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "de3c6a3cae8a3cd39ea46ac60f42424d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 7512,
            "upload_time": "2023-04-24T14:29:10",
            "upload_time_iso_8601": "2023-04-24T14:29:10.186732Z",
            "url": "https://files.pythonhosted.org/packages/ce/82/5939e68632beebdb6f61a52246c0243e8490d9f75e0f1a214dda0113d5f2/sysrsync-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "24a0eaf4f0691639d603ba3da73c4ebbd3da22dfae09565ab7ba38bc28d17de2",
                "md5": "0295cbaee846bcca7c62a6b8ad687571",
                "sha256": "435f9eb620e68ffb18ca5cbad32b113396a432361c7722038eab65c97dd83bd5"
            },
            "downloads": -1,
            "filename": "sysrsync-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0295cbaee846bcca7c62a6b8ad687571",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 6903,
            "upload_time": "2023-04-24T14:29:38",
            "upload_time_iso_8601": "2023-04-24T14:29:38.344372Z",
            "url": "https://files.pythonhosted.org/packages/24/a0/eaf4f0691639d603ba3da73c4ebbd3da22dfae09565ab7ba38bc28d17de2/sysrsync-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-24 14:29:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "gchamon",
    "github_project": "sysrsync",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "sysrsync"
}
        
Elapsed time: 0.07422s