Misc. basic stuff needed by RSCs tools
Project description
The library includes various utility modules used in other projects.
ast_call: A simple call manager using asterisk: This can be used to originate a call and log all event associated to that call. So you can find out the status of the call and optionally the dialstatus.
ast_cdr: parser for CDR records in asterisk. We currently use text-files only, this might be later extended for database use.
Autosuper magic (originally from Guido van Rossums announcement of Python 2.2): For refactoring it’s a good idea that each class knows its parents (that the parent is not hardcoded in the upcall), achieved by adding a the __super attribute. Use as, e.g., self.__super.method for calling method in the parent.
bero: A configurator for the bero*fos failover switch. See my blogpost why I wrote that (short summary: to work around bugs in the firmware of the device which are not addressed by the configurator code that comes with the device).
Config_File for python-syntax configuration files used in several of my projects.
execute: module for executing commands and handling IO, this also has a Lock and a Log mixin. Now there is also a framework for executing processes in a pipeline, there can be fork-points in the pipeline where the output of one process feeds several pipelines. See test_exec.py and test2_exec.py.
ETree: wrapper around ElementTree for pretty-printing and xml export. This uses delegation (not inheritance) because we can’t seem to inherit from ElementTree.
Firstname: given a string-candidate of a first name, check with popular web-site if it is really considered a first name.
Freshmeat: Get project and release information via the freshmeat.net REST API. Also support submit of a new release. I’m now using this for announcing new releases for my projects.
grepmime: search for pattern in email attachments (even if these are encoded)
HTML_Parse for opening and parsing URLs
inductance: Inductance calculation of air-cored cylindrical flat-winded coil according to Robert Weaver http://electronbunker.sasktelwebsite.net
IP4_Address: IP v4 Addresses with subnet masking
iter_recipes: magic with iterators
lcr: model the status of Linux Call Router ISDN lines.
ldap_lib: some routines for common ldap tasks including an iterator for LDAP implementations that use paged search (notably active directory).
Math implements Euclids algorithm for greatest common divisor and as a by-product the least common multiple
nmap: A parser for output of nmap scans to (e.g. to generate tables in TeX)
ocf: small framework for writing OCF scripts for the heartbeat cluster resource manager (probably also usable for the newer version called pacemaker but for now only tested with the version in Debian stable aka lenny).
PDF_Parse for opening and parsing PDFs, needs pdftotext installed
PDF_Signature: experimental code for checking signatures on adobe PDF documents
PM_Value: Possibly missing value, encapsulate a number which may be missing and associated arithmetics.
Rational: Implementation of Rational numbers
stateparser: Simple state-machine parser class
timeout: A simple timeout mechanism using SIGALRM
Tex_CSV_Writer: Write CVS files in a syntax that can be parsed by TeX. Implements same interface as the csv module. Only implements writing.
trafficshape: Simple traffic shaping configuration: Currently generates Linux tc commands for a traffic shaping config using hfsc for shaping and sfq or red for the leaf qdiscs. We also provide a translator from iptables mangle rules (for traffic marking) to tc commands for filtering. This is needed if we want to do inbound shaping. The Linux kernel doesn’t support inbound shaping, so we need to redirect all traffic to an ifb device. On that device we do outbound shaping. Unfortunately when sending traffic to an ifb device with a tc filter + action mirred command this occurs before the PREROUTING chain. This means packets are not yet marked. So we provide a parser to translate mangle rules in the PREROUTING chain to appropriate tc commands. For implementing this we mark packets (using the tc action ipt for iptables marking) in the original device and then use the marked information in the ifb device to send the traffic to appropriate qdiscs. This supports a two-level approach: Rules in iptables that match on a packet mark (using –mark) are translated to tc commands in the ifb device (they depend on the mark already present). All other rules are translated to a tc action ipt (using -j MARK) and a tc action mirred redirect (for sending the traffic to the ifb device) for the original device (e.g. eth0 redirecting to ifb0). The PREROUTING commands by default are directly taken from the running kernel by default (using “iptables -t mangle -S -v”)
Resources
Download the source at https://sourceforge.net/projects/rsclib/ and install using the standard python setup, e.g.:
python setup.py install --prefix=/usr/local
Changes
Version 0.21: Minor feature enhancements
Fix autosuper: allow to inherit from non-autosuper classes, some small fixes to ast_call and lcr parser. Fix ETree pretty-printing. Update Freshmeat to new hostname. Add dotted netmaks parsing to IP4_Address.
Since python2.6 constructor of “object” do not allow parameters, so we need to strip these when doing the upcall from autosuper. This fails when e.g. inheriting from a non-autosuper enabled class, e.g., class (With_Autosuper, dict) in that case dict would get empty parameters. New implementation finds out if our upcall is to “object”, only in that case strip parameters.
ast_call now processes all queued unhandled events when a call is matched.
update regression test for ast_call.Call
lcr parser: fix regex, port can have an empty name.
Optimize call matching in ast_call: mark call as closed once we are sure about the uniqueid. Add matching of Account-Code.
Fix ETree pretty-printing: don’t print unicode strings when arguments are already converted
freshmeat.net now is freecode.com (and the API redirects there), update Freshmeat.py to new hostname (including .netrc credentials with compatibility for old name).
explicit mask paramter of IP4_Address can now be a dotted netmask.
Version 0.20: Not announced on freshmeat
Database value output for ast_cdr, added inductance calculation.
ast_cdr: Add methods for database values of CDR records – database values of CDRs are different, they don’t include start, end, answer time-stamps but instead only a calldate, in addition the amaflags are numerical in the database.
added inductance calculation
Version 0.19: Not announced on freshmeat
Extend ETree with a walk method and implement small ldap library
ETree: add walk method to walk the tree and call an optional pre- and post-hook function
ldap_lib: common ldap tasks for user and group search, and an iterator for paged search (used with active directory).
Version 0.18: Not announced on freshmeat
Bugfix of ast_call and update for asterisk 1.6, small extension to IP4_Address.
ast_call: match calls via (unique) account code
ast_call: State vs ChannelState parameter in Newstate event
ast_call: handle immediate error from asterisk (e.g. Permission Denied)
IP4_Address: add netblk (start and end address for address with netmask)
Version 0.17: Not announced on freshmeat
Factor ETree (extended ElementTree) from HTML_Parse. New Freshmeat module to get project information and submit new releases via the new freshmeat REST API. New simple hexdump module.
New ETree.py (extended ElementTree)
New Freshmeat.py
New hexdump.py
adapt lcr module to new version of Linux Call Router
Version 0.16: Not announced on freshmeat
Add an iptables to tc translator for translating mangle rules in the iptables PREROUTING chain to appropriate tc commands (using an ipt action and mirred redirect actions).
Add iptables to tc translator to trafficshape.py
Version 0.15: Not announced on freshmeat
Add a framework for traffic shaping with linux iproute (tc). Minor updates to iter_recipes.
Initial implementation of trafficshape.py
Add iter_recipes.combinations from python2.6 manpage of itertools for backward compatibility
Version 0.14: Not announced on freshmeat
Add a framework for process pipeline execution, processes can either be python methods or external programs (with parameter list). They can be connected in a pipe and there may be T-points in the pipe, where the pipe forks into two or more pipelines fed by the output of one process.
Add process pipeline framework
HTML_Parse now has an explicit translate hook for preprocessing the html page before parsing it. This defaults to the old behaviour of filtering out common characters in broken HTML.
Add nmap parser (e.g. to generate TeX tables from an nmap scan)
Fix Lock_Mixin in execute module to remove lockfile at exit, this used to rely on __del__ which breaks in certain cases.
add file upload to HTML_Parse
Version 0.13: Not announced on freshmeat
Bug-Fix Release: Fix signal handler in timeout.py
fix signal handler timeout.py
Version 0.12: Not announced on freshmeat
Add a simple timeout mechanism using SIGALRM.
add timeout.py
Version 0.11: Not announced on freshmeat
Add a parser for CDR records in asterisk. We currently use text-files only, this might be later extended for database use. Some fixes for ast_call, make call-handling more robust (some race conditions would identify events of other calls as belonging to our initiated call). Add an execute module for executing commands and handling IO, this also has a Lock and a Log mixin. Add ocf.py, a small framework for writing OCF scripts for the heartbeat cluster resource manager (probably also usable for the newer version called pacemaker but for now only tested with the version in Debian stable aka lenny). Add lcr.py to model the status of Linux Call Router ISDN lines.
add ast_cdr.py
fix ast_call.py
fix up-chaining in stateparser.py
add execute.py
add ocf.py
add lcr.py
Version 0.10: Not announced on freshmeat
add ast_call for asterisk auto-dialling, small fixes to IP4_Address, add bero*fos configurator, experimental code for checking PDF signature
add ast_call.py
Firstname: don’t look up names with len < 2
IP4_Address: some aliases for common functions
IP4_Address: add __cmp__
bero.py: bero*fos configurator
HTML_Parse updated for python 2.5
stateparser update: use self.matrix by default
PDF_Signature: experimental code for checking signatures on adobe PDF documents
iter_recipes: some magic with iterators
Version 0.9: Not announced on freshmeat
Add binom to the Math package, add Firstname, Bug-Fix Release Rational
binom (n, m) computes the binomial coefficient of n, m.
Firstname: check if candidate is a first name candidate according to popular web site.
Rational: On division we could get a negative denominator – fixed
make Config_File a descendent of autosuper
Version 0.8: Not announced on freshmeat
Added more documentation. State-machine parser stateparser implemented. Rational number arithmetic package added.
stateparser implemented (simple state-machine line-oriented configurable parser)
usage-example of IP4_Address prints debian /etc/network/interfaces entry.
Math added (Euclids algorithm, gcd, lcm)
Rational number arithmetics
cookie processing for HTML_Parse
basic HTML auth for HTML_Parse
HTML_Parse: move to urllib2
Version 0.7: Not announced on freshmeat
Small Python library with various things such as Configuration file parsing (in Python syntax), HTML and PDF parsing.
First Release version