(snmp code) perl to python

lkcl luke.leighton at googlemail.com
Sun Apr 25 19:24:50 CEST 2010


On Apr 25, 9:41 am, Shabbir Ahmed <shabbir1... at gmail.com> wrote:
> hi hope all are doing good, i have code written in perl which quries
> too many devices and then stores the result in mysqldb, whiel shifting
> to python and googling i heared of and studied google asynch python
> code, now i wanted to use it n convert my perl code to it but i have
> some problem.
>
> 1. this class creates forks every snmp query and returns un ordered
> result without any information that which oid returned which result,
> where as in my code i query all only if a parent oid returns true, now
> i dont know how to read specific oid.
>
> algo of perl code,
>
> read all the ips and communities from mysql then fork function for
> every router so that all the equipment are queried at once, it creates
> that much saperate process of equipment ips,
>
> function that is forked:
> loop for all the interfaces: check if the inteface is up
> -> if so read the interface ips.
> -> save result in mysql tables.
>
> kindly help me convert this code to python or make this logic in
> python.

 if the code is particularly long (greater than 2,000 lines) then you
might wish to look at java2py.py and use it as the basis to write a
"dumb" assistant in doing much of the code-conversion:

http://pyjamas.svn.sourceforge.net/viewvc/pyjamas/trunk/contrib/java2py.py?revision=1572&content-type=text%2Fplain

 this program is _not_ parser-based (yacc, ply, oMeta2) it is line-
based and state-based.  specific assumptions are made about the code
layout (braces in K&R formatting style for example) and, thanks to the
high code-quality of the code it was used to translate (GWT) this was
not in the slightest bit a problem.

 so, _in combination with a code-cleaner_ such as "indent", which
regularises the formatting of whatever god-awful-looking perl you want
to translate, the approach indicated by java2py.py will save you a lot
of time and mistakes.

 think about it, even if the code you want to translate is 500 lines.
that's 500+ lines you need to rewrite, whereas something as simple as
267 lines of python could help automate that process of conversion.

 l.



More information about the Python-list mailing list