Date: | 2015-09-05 |
---|---|
Author: | Roland Smith |
This is a collection of small utilities that are not big enough to warrant a separate repository.
The subdirectory tests
contains tests for this code. Running the tests
requires nose or pytest.
Running the tests from the misc
directory using tcsh
done as follows.
# in tcsh
env PYTHONPATH=. pytest-3.6 test/
# in a POSIX shell
PYTHONPATH=. pytest-3.6 test/
(Adjust the name for the pytest
program according to your environment.)
The cct
function converts 8-bit RGB color to a correlated color temperature.
The lux
function coverts 8-bit RGB to illuminance in Lux.
The fcdate
function returns the creation date of a file as a string.
In [2]: from filedate import fcdate
In [3]: fcdate('README.rst')
Out[3]: '2015-09-05 14:29:54 +0200'
Splits a line and returns the items in two tuples;
- numbers
- the remaining words
Formats a number with a numeric prefix and optionally a unit.
The subgroup
function split an iterat up into a list of sub-iterators.
Calculates Hertz contact stresses.
The function rgb2html
converts an RGB color into a HTML color reference.
The two functions comput the absolute mean deviation of data. See the advantages of the mean deviation.
The NamedDict
class is a subclass of a dict
that allows you to access
dict values as attributes by “dot-notation”;
In [4]: d = NamedDict()
In [5]: d.a = 1
In [6]: d.b = 2
In [7]: d
Out[7]: {'a': 1, 'b': 2}
In [8]: d['a']
Out[8]: 1
The pdfinfo
function extracts the Info Dictionary from a PDF file.
The postfix
function evaluates postfix expressions.
In [1]: from postfix import postfix
In [2]: postfix('3 2 ** 1 -')
Out[2]: 8.0
The rawbytes
function converts a string to bytes without encoding.
The services
function returns a dict describing the defined services,
indexed by port number.
In [2]: from services import services
In [3]: data = services()
In [4]: data[80]
Out[4]: 'http'
In [5]: data[22]
Out[5]: 'ssh'
The tempname
function creates a name for a temporary file.
The function xpand
uses the glob
module to provide filename expansions
for operating systems incapable of doing so.