What could Python do for me....

Andy Jewell andy at wild-flower.co.uk
Wed Feb 19 18:40:10 EST 2003


On Tuesday 18 Feb 2003 1:43 pm, Kevin Coleclough - Global Treasury Technology 
wrote:
> Hi,
>
> I'm a newbie and I just wanted to ask a straightforward question regarding
> Python.  I've been asked to develop a small browser based utility that
> regularly scans multiple Windows 2000 fileservers and picks up settings (eg
> disk space, services running, registry key values, etc) and dumps them into
> an HTML/XML/ASP file, and I've been told that Python could do this.  I've
> had a look at some examples of Python, but they really are basic;
> variables, functions, that kind of thing, so I don't really know how to get
> started on this.
>
> Could anyone tell me a) if this is possible in Python and b) where I could
> find good reference material for pulling such stuff out of a Windows box.
> I'm not new to programming, but my recent experience is in HTML, ASP and
> Javascript.
>
> Many thanks,
>
> Kevin

Kevin,

I've done some similar work using Python.  There are already library modules 
for doing most (if not all) of the stuff you speak of above.

What I've recently done for outputting html is to make a function for each tag 
I wish to use.  Because Python can allow arbitrary keyword argument lists, 
you can do stuff like:

    quote=chr(34)
    space=chr(32)

    def params(**args):
        ret=""
        for arg,val in args.items:
             ret = ret + arg + quote + str(val) + quote + space
        return ret


    def table(text="",**args):
         return "<table "+ params(args) + ">\n"+text+"</table>\n"

# and of course more tag defs....

# then use it...

    tbl= table(align="center", bgcolor="teal",
                       text=row(cell("Row 1, First cell")+
                                        cell("Row 1, second cell"))+
                                 row(cell("Row 2, First cell")+
                                         cell("Row 2, second cell")))

which outputs (complete with indentation):

	<table align="center" bgcolor="teal">
		<tr>
			<td>Row 1, First cell</td>
			<td>Row 1, Second cell</td>
		</td>
		<tr>
			<td>Row 2, First cell</td>
			<td>Row 2, Second cell</td>
		</td>
        </table>

I've now bundled these into a module I call 'metahtml'.

All you have to do then, is pull your data from the monitored machines, and 
then output it to your html file.  If you want to get flashy, you could use 
Scaleable Vector Graphics to plot graphs and the like!

Check out modules os and  _winreg, then consult M$.com for the relevant reg 
keys and you're away.  

hth,
-andyj








More information about the Python-list mailing list