Skip to main content

A Python wrapper for the TK.MSTS.Tokens.dll library by Okrasa Ghia.

Project description

pyTKUtils

GitHub release (latest by date) Python 3.6+ License GNU GPL v3

This Python module wraps the TK.MSTS.Tokens.dll library by Okrasa Ghia. The module allows you to compress and decompress MSTS files such as shape and world files.

Note: Only compression works on Linux and macOS.
The DLL fails internally for decompression when using the Mono runtime.

The TK.MSTS.Tokens.dll file itself can be downloaded separately as part of the TK_Utils package.

Prerequisites

A Common Language Runtime (CLR) is required if you wish to compress and decompress files through this module. You can use the Mono runtime on Linux and macOS, or the .NET Framework on Windows.

The TK.MSTS.Tokens.dll library is not bundled with this Python module. It is available as part of the TK_Utils package from the-train.de.

See the Usage section for more details on how to compress and decompress shape and world files using the module.

Steps to install a CLR on your operating system:

Linux

sudo apt update
sudo apt install mono-complete

macOS

brew install mono

Windows

Download and install the .NET Framework 4.0 or later from Microsoft.

The .NET Framework is typically already installed on most Windows systems.

Installation

Install from PyPI

pip install --upgrade pytkutils

Install from wheel

If you have downloaded a .whl file from the Releases page, install it with:

pip install path/to/pytkutils-<version>‑py3‑none‑any.whl

Replace <version> with the actual version number in the filename. For example:

pip install path/to/pytkutils-0.1.0-py3-none-any.whl

Install from source

git clone https://github.com/pgroenbaek/pytkutils.git
pip install --upgrade ./pytkutils

Usage

Check if a file on disk is compressed

To check whether a file on disk is compressed, you can use the is_compressed function. This function returns True if the file is compressed and False if it is not. If the file is empty or its state cannot be determined, the function will return None.

import pytkutils

is_comp = pytkutils.is_compressed("./path/to/example.s")

if is_comp is True:
    print("Compressed")
elif is_comp is False:
    print("Uncompressed")
else:
    print("Could not determine (possibly empty file)")

Compress or decompress files

The compression and decompression functions in this module use the TK.MSTS.Tokens.dll library by Okrasa Ghia. This library is not included with the Python module. You will also need a CLR installed to load this file.

See the Prerequisites section for instructions on how to obtain the TK.MSTS.Tokens.dll library and set up a CLR on your machine.

Alternatively, you can manually compress and decompress using other tools, such as ffeditc_unicode.exe through the Shape File Manager or the FFEDIT_Sub v1.2 utility by Ged Saunders.

import pytkutils

dll_path = "./path/to/TK.MSTS.Tokens.dll"

# Compress and decompress in-place.
pytkutils.compress(dll_path, "./path/to/example.s")
pytkutils.decompress(dll_path, "./path/to/example.s")

# Compress and decompress to an output file.
pytkutils.compress(dll_path, "./path/to/example.s", "./path/to/output.s")
pytkutils.decompress(dll_path, "./path/to/example.s", "./path/to/output.s")

Running Tests

You can run tests manually or use tox to test across multiple Python versions.

Run Tests Manually

First, install the required dependencies:

pip install pytest pytest-dependency

Then, run tests with:

pytest

Run Tests with tox

tox allows you to test across multiple Python environments.

1. Install tox

pip install tox

2. Run Tests

tox

This will execute tests in all specified Python versions.

3. tox.ini Configuration

The tox.ini file should be in your project root:

[tox]
envlist = py36, py37, py38, py39, py310

[testenv]
deps = pytest
commands = pytest

Modify envlist to match the Python versions you want to support.

Known Issues

Only compression works on Linux and macOS. The DLL fails internally for decompression when using the Mono runtime.

License

This Python module was created by Peter Grønbæk Andersen and is licensed under GNU GPL v3.

Note: The TK.MSTS.Tokens.dll library itself comes with a different license by Okrasa Ghia. That license can be found in the TK_Utils package from the-train.de.

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

pytkutils-0.1.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

pytkutils-0.1.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file pytkutils-0.1.1.tar.gz.

File metadata

  • Download URL: pytkutils-0.1.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pytkutils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 abec5b24d5c964a944ccbd91e18da76eab11d437d99ecbf52dab1e82201b62f3
MD5 004108ee0d4d8ef72711e3ee8bfe1726
BLAKE2b-256 fc7b2966819d78897f4bad2e1eb919693792f80724826b381735436fee42a020

See more details on using hashes here.

File details

Details for the file pytkutils-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytkutils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pytkutils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0d5c993ab5ce515df4420a7258a72712440606d227f8de5daf4279bd027ec70
MD5 9a9c01f2f7954de6857c753d65d09b6f
BLAKE2b-256 02b7887c9840da6c8324530acb16401a3bd27332aa48c5275aa3f3674d2a6410

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