Skip to main content

blockinfile is a tool for editing automatically a text block surrounded by marker lines

Project description

blockinfile

blockinfile is a tool for editing automatically a text block surrounded by marker lines. It's an automated port of ansible's blockinfile module.

Basically, it can overwrite a part of a file that's well delimited so it doesn't overwrite the whole file.

Usage

blockinfile --path FILE_TO_PATCH --block CONTENT_TO_INSERT [--marker MARKER_TEMPLATE] [--marker-begin START_STRING] [--marker-end END_STRING] [MORE_OPTIONS]

Options are the same as in Ansible documentation.

Sample

If myfile.conf initially contains:

sample line
other line

Then running:

blockinfile --path myfile.conf --marker "# {mark} MY BLOCK" --block 'this line will be entered
this one too'

Then myfile.conf will be updated:

sample line
other line
# BEGIN MY BLOCK
this line will be entered
this one too
# END MY BLOCK

Then running:

blockinfile --path myfile.conf --marker "# {mark} MY BLOCK" --block 'updating the section'

Would produce:

sample line
other line
# BEGIN MY BLOCK
updating the section
# END MY BLOCK

"Automated" port

This project includes the source of Ansible's blockinfile module, slightly modified so it can work without having to use or even install Ansible. The modifications have been automated so it should be possible to easily port newer Ansible versions.

See builder/build.sh.

Install

From PyPI:

pipx install blockinfile

License

Since blockinfile is a port of (part of) Ansible's source, it's licensed under GPLv3+ just like Ansible.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blockinfile-2.17.1.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

blockinfile-2.17.1-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file blockinfile-2.17.1.tar.gz.

File metadata

  • Download URL: blockinfile-2.17.1.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for blockinfile-2.17.1.tar.gz
Algorithm Hash digest
SHA256 534efea307c285e2cbde37dff8c133c805787013dff7c680f421a772744f7463
MD5 e70d2f87107ec0afa5928a7abeceafd8
BLAKE2b-256 e39ce593b86c466a5f1a656049e5bddf8235c19162f4aa78096cc6767e23f763

See more details on using hashes here.

File details

Details for the file blockinfile-2.17.1-py3-none-any.whl.

File metadata

File hashes

Hashes for blockinfile-2.17.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad52f6dc8bef58f476692ef9df5f16e6fedbfee604753049dcaad4ec6a08f535
MD5 941f05ac791a85572d2299ac27e84a25
BLAKE2b-256 8f5e57c61c211d662df0cc5352ed1dce565ef5678e7068607297444406c1421d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page