1. Marcus von Appen
  2. python-utils

Source

python-utils / README.txt

About python-utils
==================
python-utils is a loose set of modules and packages, that can be easily
dropped into any Python project. They are usually small (code to read),
easy to use and limited in the functionality, they provide.

Installation
============
There is nothing to install. Just copy the files, you want to use, into
your own project.

License
=======
All code within this project is given to the public domain. There are no
licensing restrictions. Please see *COPYING.txt* for further details.

Packages
========    
The following packages are currently available.

test.util
---------
A simple test framework based on `unittest`. It supports improved test
behaviour, automated test loading, tagging, randomisation and
parallelised execution of tests.

How to use
^^^^^^^^^^
You can simply copy it into your main project. It is recommended to keep the
hierarchy as it is, so that you put your unittest files into test/ and keep
all the framework files in test/util. ::

    awesomeproject/
        setup.py
        README
        awesomepackage/
            __init__.py
            wow.py
            test/
                __init__.py
                wow_test.py
                util/
                    runtests.py
                    support.py
                    testrunner.py
                    testutils.py

You just need to stick to a single naming rule for files, which have to
end with ``_test.py``. This can be changed in the `gettestfiles()`
function in the *runtests.py* file.

The whole test suite can be executed with a simple module execution: ::

    python -m awesomepackage.test.util.runtests

Modules
=======
The following modules are currently available.

array
-----
n-dimensional buffer access classes and ctypes sequence conversion helpers.

compat
------
Several compatibility helpers to make writing Python code for Python 2.x and
Python 3.x easier without too many if/else gates.

dll
---
A simple ctypes wrapper class for loading shared libraries.

ebs
---
A simple component-based framework.

font
----
System font handling functions.


resources
---------
Resource management methods and classes. This allows you to easily handle
non-Python resource files in your application. The `Resources` class can be
used to scan folders or compressed archives and to access the files within them
without the need to fiddle around with absolute or relative paths.

If you for example intend to ship some content files with your application and
need to access them, just put them into some content-specific folder and access
them via the Resource class. If you want to package all those content files to
save the user some disk space, you can use the ZIP or TAR compression to bundle
them into one or more single files.

Let's assume your application features something like the following
layout: ::

    awesomeapplication/
        Application.exe
            resources/
            button.png
            info.dat
            textcontent.zip
                [textfile1.txt, textfile2.txt]

Within Application.exe (which previously might have been application.py,
compiled and packaged via py2exe or something similar), you can define
the resource bundle like ::

    apppath = os.path.dirname(os.path.abspath(__file__))
    appresources = Resources(os.path.join(apppath, "resources"))

and access your data files like ::

    button_image = appresources.get("button.png")
    info_file = appresources.get("info.dat")

    # Get textfile1.txt from textcontent.zip
    textfile1 = appresources.get("textfile1.txt")

Easy, isn't it?