Automatically assign an increasing sequence number to file names.
Project description
numfile
Automatically assign an increasing sequence number to file names.
Installation
$ python -m pip install numfile
Use Cases
Write data to numbered snapshot files in a given directory:
$ python -q
>>> from numfile import open_next
>>> for version in ("first", "second", "third"):
... with open_next("/tmp/snapshot.txt") as file:
... print(f"The {version} version.", file=file)
...
$ ls -d /tmp/* | grep snapshot
/tmp/snapshot-1.txt
/tmp/snapshot-2.txt
/tmp/snapshot-3.txt
Append messages to the latest log file:
$ ls -tr | grep app-error
app-error.log
app-error-2.log
app-error-3.log
$ python -q
>>> from numfile import open_latest
>>> with open_latest("app-error.log") as file:
... print("Oops... Something went wrong!", file=file)
... print(file.name)
...
app-error-3.log
$ tail -n1 app-error-3.log
Oops... Something went wrong!
Consolidate similar files in chronological order:
$ python -q
>>> from numfile import open_all
>>> for file in open_all("/tmp/snapshot.txt"):
... print(file.name, file.read(), end="")
...
/tmp/snapshot-1.txt The first version.
/tmp/snapshot-2.txt The second version.
/tmp/snapshot-3.txt The third version.
Development
$ git clone git@github.com:bzaczynski/numfile.git
$ cd numfile
$ pyenv local 3.9.0
$ python -m venv .venv --prompt=numfile
$ source .venv/bin/activate
$ pip install -U pip flit
$ flit install --deps=all --symlink
$ python -m pytest
Releasing
Test
Make sure there are no uncommitted or untracked files, and then bump the version:
$ bump2version minor
$ git status
$ git commit -am "Bumped version"
Build a new binary package:
$ rm -rf dist
$ flit build
Publish the binaries to the official PyPI server:
$ flit publish
To use the Test PyPI server, create a file ~/.pypirc
with your username:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = your-username
[testpypi]
repository = https://test.pypi.org/legacy/
username = your-username
Then, supply the test server using the --repository
flag:
$ flit publish --repository testpypi
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file numfile-0.1.0.tar.gz
.
File metadata
- Download URL: numfile-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dba81491e97c4163a2c8e721d99b24d61a3aaeda6b99f71115a53e3230839a88 |
|
MD5 | 6cbcd23ab0ea01e6e60504364e2ffd17 |
|
BLAKE2b-256 | c30c43ac3e0e05097c43536d211a95841ad16d18bed1a16001423b6f016c3eca |
File details
Details for the file numfile-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: numfile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 988bdb12041f5ca79eeaf198606681103f5fe6754be0d6b5aef206b4221f9251 |
|
MD5 | 935169b14f3180e545ff192555a99be4 |
|
BLAKE2b-256 | b78b20261955d77691e68a36455d6511b13b17fce338544526d21f259408e390 |