Utilities

Note

The documentation in this section is aimed at people wishing to contribute to versionah, and can be skipped if you are simply using the tool from the command line.

versionah.STR_TYPE = <type 'basestring'>

Type basestring cannot be instantiated; it is the base for str and unicode.

The following three functions are defined for purely cosmetic reasons, as they make the calling points easier to read.

versionah.success(text)[source]

Format a success message with colour, if possible.

Return type:str
versionah.fail(text)[source]

Format a failure message with colour, if possible.

Return type:str
versionah.warn(text)[source]

Format a warning message with colour, if possible.

Return type:str
versionah.split_version(version)[source]

Split version string to components.

Parameters:version (str) – Version string
Return type:tuple of int
Returns:Components of version string
Raises:exceptions.ValueError – Invalid version string

Examples

Output formatting

>>> success('well done!')  
u'\x1b[38;5;10mwell done!\x1b[m\x1b(B'
>>> fail('unlucky!')  
u'\x1b[38;5;9munlucky!\x1b[m\x1b(B'

Version string parsing

>>> split_version('4.3.0')
(4, 3, 0)
>>> split_version('4.3.0.1')
(4, 3, 0, 1)
>>> split_version('4.3.0.1.3')
Traceback (most recent call last):
    ...
ValueError: Invalid version string '4.3.0.1.3'