[Zope] Sum up a property from several objects

Gitte Wange gitte@mmmanager.org
Mon, 9 Jul 2001 16:58:16 +0200


On Sunday 08 July 2001 18:45, ender wrote:
> On Sunday 08 July 2001 14:13, Gitte Wange wrote:
> >>Hello,
> >>
> >>I have a folder contaning some objects.
> >>These objects all have a property named CPU (it's an int).
> >>
> >>Now I want to iterate through the folder's objects and sum up the value
> >> of this CPU property.
> >>
> >>I have tried with this - IMHO - really bad code:
> >>
> >><dtml-with my_computers>
> >> <dtml-in "objectValues()">
> >>  <dtml-if sequence-start>
> >>   <dtml-call "REQUEST.set('new_cpu',CPU)">
> >>  <dtml-else>
> >>   <dtml-let cpu="new_cpu + CPU">
> >>    <dtml-call "REQUEST.set('new_cpu',cpu)">
> >>   </dtml-let>
> >>  </dtml-if>
> >> </dtml-in>
> >></dtml-with>
> >>
> >>But I get this error:
> >>Error Type: KeyError
> >>Error Value: cpu
> >>
> >>Any other way to do this ?
>
> this sort of thing is ripe for a python script
>
> mycomps = container.my_computers
> sum = 0
> for obj in mycomps.objectValues():
>      sum = obj.cpu + sum
> return sum
>
> it can be done via dtml as well but its just ugly... IMO
>
> kapil

Thanx !!
Now I have the nicests stats of my computers at my website :-)))

I have been wondering if it is possible in python to make system calls (I did 
it with PHP). But it was only for the machine that the script ran on.

It found the machines uptime and printed it out.

Could I - just philosophy - in python, write a script that calls different 
machines (perhaps via SNMP) and gets their uptime, hard ware numbers (such as 
RAM, CPU, Harddisk etc) ???

Regards,


-- 
Gitte Wange Jensen

Sys Admin, Developer and a lot more
MMmanager.org Aps, Denmark

Phone: +45 29 72 79 72
Email: gitte@mmmanager.org
Web: www.mmmanager.org

Quote of the day:
It's entirely untested, but it looks good and compiles. Ship it!

	- Linus Torvalds