Skip to main content

No project description provided

Project description

ArrowDrive (adrv)

ArrowDrive is a Python module that allows you to create and manage virtual disks. The module ensures that the virtual disk's size does not exceed a specified maximum limit.

Version

  • Current version: 1.4.2
  • Last supported version: 1.4.0

Installation

ArrowDrive is available on PyPI. You can install it using pip:

pip install adrv

Alternatively, you can clone the repository:

git clone https://github.com/arr-setup/arrowdrive.git

Usage

Initialization

Create a new instance of the Disk class:

import adrv

disk = adrv.Disk(name='myDisk', path='./disks', max_size=1000 ** 2)

adrv.Disk(name: str = 'vDisk', path: str = './', max_size: int = 1000 ** 2)

Initializes a Disk instance.

  • name: The name of the disk. Defaults to 'vDisk'.
  • path: The path where the disk will be stored. Defaults to './'.
  • max_size: The maximum size of the disk in bytes. Defaults to 1,000,000 bytes.

Methods

read(vPath: str) -> FileResponse

Reads a file from the disk.

  • vPath: The path of the file to be read.

write(vPath: str, content: str | bytes = b'', mode: str = 'a') -> int

Writes content to a file in the disk.

  • vPath: The path where the content will be written.
  • content: The content to be written. Defaults to an empty byte string.
  • mode: The writing mode ('a' for append, 'w' for write). Defaults to 'a'.

delete(vPath: str) -> int

Deletes a file from the disk.

  • vPath: The path of the file to be deleted.

format_disk(modelPath: str | None = None)

Formats the disk. Optionally, a model path can be provided to initialize the disk with predefined files.

  • modelPath: The path to a model zip file. None (default) means the Disk will be completely reset.

extract_all(target: str)

Extracts all files from the disk to a target directory.

  • target: The target directory.

f_list(include_ts: bool = False, sys: bool = False) -> list[str | dict]

Lists files in the disk.

  • include_ts: Whether to include timestamps (and additional info in future versions). Defaults to False.
  • sys (deprecated): Whether to include system files. Defaults to False.

diagnosis(snooze: bool = False) -> DiagnoseResponse

Evaluates the health of the disk.

  • snooze: Whether to suppress output. Defaults to False.

Example

import adrv

# Create a new disk
disk = adrv.Disk(name='myDisk', path='./storage', max_size=1000**2)

# Write a file
disk.write('hello.txt', 'Hello, world!', mode='w')

# Read a file
file = disk.read('hello.txt')
print(file.content.decode())

# List files
files = disk.f_list()
print(files)

# Delete a file
disk.delete('hello.txt')

Error Handling

The module raises specific exceptions for different error conditions:

  • FileIsDirectoryError: Raised when attempting to read a directory as a file.
  • FileNotFoundError: Raised when a file is not found.
  • FullDiskError: Raised when attempting to write content that exceeds the disk's maximum size.
  • BrokenDiskError: Raised when the disk is detected to be in a corrupted state.

Utils

utils.parser

parse(data: str, keys: list, mode: int = 1) -> list | dict | list[dict]

Parses the provided data string into different formats based on the mode.

  • data: The data string to parse.
  • keys: A list of keys to use in the parsing.
  • mode: Determines the parsing strategy.
    • 1: Splits data by new lines and zips with keys.
    • 2: Splits data by new lines and then by '=' for key-value pairs.
    • 3: Splits data by '::' and optionally zips with keys.
    • 4: Splits data by new lines.

Returns a list, dictionary, or list of dictionaries based on the mode.

unparse(data, mode: int = 1) -> str

Unparses data into a string based on the mode.

  • data: The data to unparse.
  • mode: Determines the unparse strategy.
    • 1: Joins values with new lines.
    • 2: Joins key-value pairs with '=' and new lines.
    • 3: Joins dictionary values with '::'.
    • 4: Joins list items with new lines.

Returns the unparsed string.

utils.units

Size

A class to handle size representation and conversion.

  • init(value: int | float)

    • value: The size value in bytes.
  • literal() -> str

    • Converts the raw size value to a human-readable format (e.g., 1kB, 1MB).

Units

  • units: 1 byte.
  • kilo: 1 kilobyte (1,000 bytes).
  • mega: 1 megabyte (1,000,000 bytes).
  • giga: 1 gigabyte (1,000,000,000 bytes).
  • tera: 1 terabyte (1,000,000,000,000 bytes).

convert(val: float, _from: str, _to: str) -> float

Converts a value from one unit to another.

  • val: The value to convert.
  • _from: The original unit (B, kB, MB, GB, TB).
  • _to: The target unit (B, kB, MB, GB, TB).

Returns the converted value.

bridge

PhysicalBridge

A class to handle physical file transfer to and from the virtual disk.

  • init(disk: Disk)

    • disk: The Disk instance to interact with.
  • bring(vPath: str, newPath: str)

    • Transfers a file from the virtual disk to a physical location.
    • vPath: The virtual path of the file.
    • newPath: The physical path where the file will be saved.
  • send(filePath: str, vPath: str)

    • Transfers a file from a physical location to the virtual disk.
    • filePath: The physical path of the file.
    • vPath: The virtual path where the file will be saved.

VirtualBridge

A class to handle file transfer between two virtual disks.

  • init(firstDisk: Disk, secondDisk: Disk)

    • firstDisk: The source Disk instance.
    • secondDisk: The destination Disk instance.
  • cross(targetPath: str, finalPath: str = '/shore', rtl: bool = False)

    • Transfers a file from one virtual disk to another.
    • targetPath: The path of the file on the source disk.
    • finalPath: The path where the file will be saved on the destination disk.
    • rtl: If True, transfers from the second disk to the first; otherwise, transfers from the first to the second.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the GPLv3 License.

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

adrv-2.0.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

adrv-2.0.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file adrv-2.0.0.tar.gz.

File metadata

  • Download URL: adrv-2.0.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for adrv-2.0.0.tar.gz
Algorithm Hash digest
SHA256 3af4173f3326cc5c40fec84a7f21ffe4bd1e7e69b181cdc6e8ff2da58f07eb35
MD5 1e403cb8ca1e871a6944f65debbeeab7
BLAKE2b-256 d3aa42a7a361c5368078fe9eb2a98ee513acd6f2e60183d0336668c3e4a028a6

See more details on using hashes here.

File details

Details for the file adrv-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: adrv-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for adrv-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e971e2b78890a925582cb8cd7119b232eeff2b96b03a0a557ecc9a46977cb97f
MD5 0fe56534beacbe1f3564151958e4ee52
BLAKE2b-256 0353ea1b1dda520d2c880fd33d45e847c9259e2b066a8bdc236a2746d6bf7aaa

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