Python library for handling fixed sized files, with interactive CLI
Project description
FixedSizeFileIOTools
Python library for handling fixed sized files (120 characters), with interactive CLI.
Contents
Library on this Repo consist of 3 main files.
-
models.py - consist of pydantict models for object structures.
-
Functionalites:
-
Three seperate models:
- Header - Represents a header with specific fields. (name, surname, patronymic, address)
- Transaction - Represents a transaction with a specific fields. (counter, amount, currency, reserved)
- Footer - Represents a footer with specific fields. (total counter, control sum, reserved)
-
Methods:
- get_header() - get all fields of header with formated lengths.
- get_transaction()- get all fields of transaction with formated lengths.
- get_footer() - get all fields of footer with formated lengths.
- get_field() - get any field of model.
- change_field() - change field of model.
- close_field() - close field for modification.
- open_field() - open field for modification.
- is_field_modifiable() - check is field modifiable.
- decimal_places() - check if provided amount in transaction has more than 3 decimal places.
- currency_must_be_from_list() - check if provided currency is from predifined list.
-
-
-
file_handler.py - Handles fixed-format files containing headers, transactions, and footers.
-
Functionalites:
-
Methods:
- init: Initializes the FixedFileHandler object.
- validate_file_structure(): Validates the structure of the input file.
- validate_records_structure(): Validates the structure of the records stored in the dictonary.
- read_records(): Reads records from the input file and stores them in the records dictionary.
- write_records(): Writes records stored in the object to an output file.
- add_new_transaction(): Adds a new transaction to the records dictionary.
- add_header(): Adds a header record to the records dictionary.
- list_transactions(): Lists all transactions stored in the records dictionary.
-
-
-
cli.py - Interactive Command-line interface for handling files with fixed length (120 characters in line) records.
This CLI provides commands for reading, writing, modifying records and generating sample files.
Usage: Use the function run() to start the interactive CLI.
- Commands:
- read: Read records from a file.
- write: Write records to a file.
- add-header: Add a header record.
- add-transaction: Add a transaction record.
- list-transactions: List current transactions.
- get-field: Get the value of a specific field from a record.
- change-field: Change the value of a specific field in a record.
- open-field: Open a field for modification.
- close-field: Close a field for modification.
- clear-all: Clear all current stored information (not from file).
- generate-sample_file: Generate a sample file with transactions.
- help: Show available commands.
- Commands:
Tests
This library was throughly tested using pytest in edge scenarios / cases.
To run tests just write pytest -vv in terminal at root directory of this project.
Distribution
You can install and use this library free at
Author
Patryk Jaworki
17.04.2024
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file FixedSizeFileIOTools-1.2.tar.gz.
File metadata
- Download URL: FixedSizeFileIOTools-1.2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
731d71dee1c46f1619648ff446a4451f6b7a50d7f908e1173903ff38da629248
|
|
| MD5 |
55c23bf67f53874a765a7121838c0c9b
|
|
| BLAKE2b-256 |
0b2fee0176453b95d4af0c811d6280bc6bacb95930e3dc21ba5a25ca73324ca4
|
File details
Details for the file FixedSizeFileIOTools-1.2-py3-none-any.whl.
File metadata
- Download URL: FixedSizeFileIOTools-1.2-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fc80d42c14fbd178896920e367dfe5ff2915fc33af3ca811ad63458ca71e9c4
|
|
| MD5 |
9e1f550c674da8e1abed8e954e98e4eb
|
|
| BLAKE2b-256 |
17d706a3f38cc46aef71ee519f3fef68a0ef795b64a61dcbcea5b56e56faf2b8
|