Skip to main content

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:

        1. get_header() - get all fields of header with formated lengths.
        2. get_transaction()- get all fields of transaction with formated lengths.
        3. get_footer() - get all fields of footer with formated lengths.
        4. get_field() - get any field of model.
        5. change_field() - change field of model.
        6. close_field() - close field for modification.
        7. open_field() - open field for modification.
        8. is_field_modifiable() - check is field modifiable.
        9. decimal_places() - check if provided amount in transaction has more than 3 decimal places.
        10. 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:

        1. init: Initializes the FixedFileHandler object.
        2. validate_file_structure(): Validates the structure of the input file.
        3. validate_records_structure(): Validates the structure of the records stored in the dictonary.
        4. read_records(): Reads records from the input file and stores them in the records dictionary.
        5. write_records(): Writes records stored in the object to an output file.
        6. add_new_transaction(): Adds a new transaction to the records dictionary.
        7. add_header(): Adds a header record to the records dictionary.
        8. 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:
      1. read: Read records from a file.
      2. write: Write records to a file.
      3. add-header: Add a header record.
      4. add-transaction: Add a transaction record.
      5. list-transactions: List current transactions.
      6. get-field: Get the value of a specific field from a record.
      7. change-field: Change the value of a specific field in a record.
      8. open-field: Open a field for modification.
      9. close-field: Close a field for modification.
      10. clear-all: Clear all current stored information (not from file).
      11. generate-sample_file: Generate a sample file with transactions.
      12. help: Show available 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

https://pypi.org/project/FixedSizeFileIOTools/

Author

Patryk Jaworki

17.04.2024

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

FixedSizeFileIOTools-1.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

FixedSizeFileIOTools-1.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

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

Hashes for FixedSizeFileIOTools-1.2.tar.gz
Algorithm Hash digest
SHA256 731d71dee1c46f1619648ff446a4451f6b7a50d7f908e1173903ff38da629248
MD5 55c23bf67f53874a765a7121838c0c9b
BLAKE2b-256 0b2fee0176453b95d4af0c811d6280bc6bacb95930e3dc21ba5a25ca73324ca4

See more details on using hashes here.

File details

Details for the file FixedSizeFileIOTools-1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for FixedSizeFileIOTools-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3fc80d42c14fbd178896920e367dfe5ff2915fc33af3ca811ad63458ca71e9c4
MD5 9e1f550c674da8e1abed8e954e98e4eb
BLAKE2b-256 17d706a3f38cc46aef71ee519f3fef68a0ef795b64a61dcbcea5b56e56faf2b8

See more details on using hashes here.

Supported by

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