fabsync


Namefabsync JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryFile syncing via Fabric.
upload_time2024-04-01 22:27:56
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords fabric
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- vim: set tw=80 lbr: -->
# fabsync

- Homepage: https://sr.ht/~psagers/fabsync/
- Source code: https://hg.sr.ht/~psagers/fabsync
- Documentation: https://fabsync.ignorare.net/

## Overview

This is a file-syncing tool for [Fabric][]. It's almost as straightforward to
use as rsync, but with some of the features that will be familiar from
deployment automation tools like Ansible.

Key points:

- Source files are kept in a simple directory tree, as if you were going to
  rsync them.
- Metadata—such as ownership and permissions—is configured in TOML files
  throughout the tree.
- Rendering functions can be configured to transform file contents. You can hook
  these up to template engines or anything else.
- Paths and tags can be used to sync a subset of the file tree.

The most important thing to note is that this is a library, not a framework. It
does one simple thing, which you're welcome to integrate into your own
deployment scheme any way you like. For illustration purposes, here's a fragment
of a hypothetical `fabfile.py` that you might write:

```python
import io
from pathlib import Path
from typing import Any, Mapping

from fabric import Connection, task
import fabsync
import pystache
import tomli


def _mustache_renderer(conn: Connection) -> fabsync.Renderer:
    try:
        result = conn.get('/usr/local/etc/fabsync.toml', io.BytesIO())
    except FileNotFoundError:
        host = {}
    else:
        host = tomli.loads(result.local.getvalue().decode())

    renderer = pystache.Renderer(escape=lambda s: s)

    def render(path: Path, vars: Mapping[str, Any]) -> str:
        with path.open('rt') as f:
            return renderer.render(f.read(), host | vars)

    return render


@task(iterable=['tag'], incrementable=['verbose'])
def sync(conn, subpath=None, tag=None, verbose=0):
    root = fabsync.load('files', '/')
    selector = fabsync.ItemSelector.new(subpath=subpath, tags=tag)
    renderers = {'mustache': _mustache_renderer(conn)}

    dry_run = conn['run']['dry']

    for result in fabsync.isync(conn, root, selector, renderers, dry_run=dry_run):
        print(f"{result.path}{' [modified]' if result.modified else ''}")
        if verbose > 0 and result.diff:
            print(result.diff.decode())
```

Of course you may also wish to save the results and use them to decide what
other actions to perform (e.g. restarting services).

Because we're just dealing with files, fabsync can offer a few other convenience
functions, including one that renders the source tree into human-readable rows.
If you rendered this with PrettyTable, it might look like this:

```
+-----------------------------------+------+-------+------------+----------+-------+--------+
| Path                              | User | Group | Mode       | Renderer | Diff? | Tags   |
+-----------------------------------+------+-------+------------+----------+-------+--------+
| /usr/                             |      |       |            |          |       |        |
| /usr/local/                       |      |       |            |          |       |        |
| /usr/local/etc/                   |      |       |            |          |       |        |
| /usr/local/etc/mail/              |      |       |            |          |       | mail   |
| /usr/local/etc/mail/smtpd.conf    |      |       |            |          |       | mail   |
| /usr/local/etc/rc.d/              | root | wheel |            |          |       |        |
| /usr/local/etc/rc.d/restic-server | root | wheel | -rwxr-xr-x |          |       | restic |
| /usr/local/etc/smb4.conf          |      |       |            |          |       |        |
| /usr/local/etc/wireguard/         |      |       | drwx------ |          |       | wg     |
| /usr/local/etc/wireguard/wg0.conf |      |       | -rw------- | mustache |       | wg     |
| /usr/local/utils/                 |      |       |            |          |       |        |
+-----------------------------------+------+-------+------------+----------+-------+--------+
```

Refer to the [documentation][] for more details and a step-by-step guide.

## Contributing

I wrote this for my own purposes and published it primarily to enforce the
discipline of comprehensive documentation and tests. It's deliberately narrow in
scope. New features are not out of the question, but mostly only those that
would be considerably more effort to implement externally.

Feel free to reach out with bug reports or suggestions. And note the Unlicense,
which means you can also just take the code and do what you like with it.

## License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>


[Fabric]: https://www.fabfile.org/
[documentation]: https://fabsync.ignorare.net/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fabsync",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "fabric",
    "author": null,
    "author_email": "Peter Sagerson <psagers@ignorare.net>",
    "download_url": "https://files.pythonhosted.org/packages/9a/e5/9e0aca5ff922e48c805cafc88f1dc71a599ae9bb040c5509b2b715bd0f4b/fabsync-1.2.0.tar.gz",
    "platform": null,
    "description": "<!-- vim: set tw=80 lbr: -->\n# fabsync\n\n- Homepage: https://sr.ht/~psagers/fabsync/\n- Source code: https://hg.sr.ht/~psagers/fabsync\n- Documentation: https://fabsync.ignorare.net/\n\n## Overview\n\nThis is a file-syncing tool for [Fabric][]. It's almost as straightforward to\nuse as rsync, but with some of the features that will be familiar from\ndeployment automation tools like Ansible.\n\nKey points:\n\n- Source files are kept in a simple directory tree, as if you were going to\n  rsync them.\n- Metadata\u2014such as ownership and permissions\u2014is configured in TOML files\n  throughout the tree.\n- Rendering functions can be configured to transform file contents. You can hook\n  these up to template engines or anything else.\n- Paths and tags can be used to sync a subset of the file tree.\n\nThe most important thing to note is that this is a library, not a framework. It\ndoes one simple thing, which you're welcome to integrate into your own\ndeployment scheme any way you like. For illustration purposes, here's a fragment\nof a hypothetical `fabfile.py` that you might write:\n\n```python\nimport io\nfrom pathlib import Path\nfrom typing import Any, Mapping\n\nfrom fabric import Connection, task\nimport fabsync\nimport pystache\nimport tomli\n\n\ndef _mustache_renderer(conn: Connection) -> fabsync.Renderer:\n    try:\n        result = conn.get('/usr/local/etc/fabsync.toml', io.BytesIO())\n    except FileNotFoundError:\n        host = {}\n    else:\n        host = tomli.loads(result.local.getvalue().decode())\n\n    renderer = pystache.Renderer(escape=lambda s: s)\n\n    def render(path: Path, vars: Mapping[str, Any]) -> str:\n        with path.open('rt') as f:\n            return renderer.render(f.read(), host | vars)\n\n    return render\n\n\n@task(iterable=['tag'], incrementable=['verbose'])\ndef sync(conn, subpath=None, tag=None, verbose=0):\n    root = fabsync.load('files', '/')\n    selector = fabsync.ItemSelector.new(subpath=subpath, tags=tag)\n    renderers = {'mustache': _mustache_renderer(conn)}\n\n    dry_run = conn['run']['dry']\n\n    for result in fabsync.isync(conn, root, selector, renderers, dry_run=dry_run):\n        print(f\"{result.path}{' [modified]' if result.modified else ''}\")\n        if verbose > 0 and result.diff:\n            print(result.diff.decode())\n```\n\nOf course you may also wish to save the results and use them to decide what\nother actions to perform (e.g. restarting services).\n\nBecause we're just dealing with files, fabsync can offer a few other convenience\nfunctions, including one that renders the source tree into human-readable rows.\nIf you rendered this with PrettyTable, it might look like this:\n\n```\n+-----------------------------------+------+-------+------------+----------+-------+--------+\n| Path                              | User | Group | Mode       | Renderer | Diff? | Tags   |\n+-----------------------------------+------+-------+------------+----------+-------+--------+\n| /usr/                             |      |       |            |          |       |        |\n| /usr/local/                       |      |       |            |          |       |        |\n| /usr/local/etc/                   |      |       |            |          |       |        |\n| /usr/local/etc/mail/              |      |       |            |          |       | mail   |\n| /usr/local/etc/mail/smtpd.conf    |      |       |            |          |       | mail   |\n| /usr/local/etc/rc.d/              | root | wheel |            |          |       |        |\n| /usr/local/etc/rc.d/restic-server | root | wheel | -rwxr-xr-x |          |       | restic |\n| /usr/local/etc/smb4.conf          |      |       |            |          |       |        |\n| /usr/local/etc/wireguard/         |      |       | drwx------ |          |       | wg     |\n| /usr/local/etc/wireguard/wg0.conf |      |       | -rw------- | mustache |       | wg     |\n| /usr/local/utils/                 |      |       |            |          |       |        |\n+-----------------------------------+------+-------+------------+----------+-------+--------+\n```\n\nRefer to the [documentation][] for more details and a step-by-step guide.\n\n## Contributing\n\nI wrote this for my own purposes and published it primarily to enforce the\ndiscipline of comprehensive documentation and tests. It's deliberately narrow in\nscope. New features are not out of the question, but mostly only those that\nwould be considerably more effort to implement externally.\n\nFeel free to reach out with bug reports or suggestions. And note the Unlicense,\nwhich means you can also just take the code and do what you like with it.\n\n## License\n\nThis is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, compile, sell, or\ndistribute this software, either in source code form or as a compiled\nbinary, for any purpose, commercial or non-commercial, and by any\nmeans.\n\nIn jurisdictions that recognize copyright laws, the author or authors\nof this software dedicate any and all copyright interest in the\nsoftware to the public domain. We make this dedication for the benefit\nof the public at large and to the detriment of our heirs and\nsuccessors. We intend this dedication to be an overt act of\nrelinquishment in perpetuity of all present and future rights to this\nsoftware under copyright law.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\nOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\nFor more information, please refer to <http://unlicense.org/>\n\n\n[Fabric]: https://www.fabfile.org/\n[documentation]: https://fabsync.ignorare.net/\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "File syncing via Fabric.",
    "version": "1.2.0",
    "project_urls": {
        "Documentation": "https://fabsync.ignorare.net/",
        "Homepage": "https://sr.ht/~psagers/fabsync/",
        "Source code": "https://hg.sr.ht/~psagers/fabsync"
    },
    "split_keywords": [
        "fabric"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9c8ed5b186aaeeba404c4e78bc408fcd8da3ef654b26671b538b08b70d1c1b51",
                "md5": "d032511f1967ef8ce6e62f86a08c662f",
                "sha256": "4fd050b12a1b3a20c3b0d674792fd3cf29b94b84667df0279f45fb75fe2170d8"
            },
            "downloads": -1,
            "filename": "fabsync-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d032511f1967ef8ce6e62f86a08c662f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18380,
            "upload_time": "2024-04-01T22:27:57",
            "upload_time_iso_8601": "2024-04-01T22:27:57.232249Z",
            "url": "https://files.pythonhosted.org/packages/9c/8e/d5b186aaeeba404c4e78bc408fcd8da3ef654b26671b538b08b70d1c1b51/fabsync-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9ae59e0aca5ff922e48c805cafc88f1dc71a599ae9bb040c5509b2b715bd0f4b",
                "md5": "e08ef942955bac1358becb9a030f2fc6",
                "sha256": "fdedca6010bccdec9548a84428ec9fb1624d18e5fbc652519d62f366d8a648a9"
            },
            "downloads": -1,
            "filename": "fabsync-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e08ef942955bac1358becb9a030f2fc6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 31212,
            "upload_time": "2024-04-01T22:27:56",
            "upload_time_iso_8601": "2024-04-01T22:27:56.102310Z",
            "url": "https://files.pythonhosted.org/packages/9a/e5/9e0aca5ff922e48c805cafc88f1dc71a599ae9bb040c5509b2b715bd0f4b/fabsync-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-01 22:27:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fabsync"
}
        
Elapsed time: 0.32002s