Hi Folks,
I've been playing around a bit and I'm loving what you guys have done with crankd. I'm implementing a network configuring python class which will do various things in response to network changes and I'm looking for some general python advice: any help would be much appreciated.
Currently, I'm monitoring State:/Network/Global/IPv4, which means I get a notification every time any IPv4 changes. I then work out the primary interface and find out the primary IP address of it (all with the SystemConfiguration framework).
The thing is, because I get notifications whenever any IPv4 interface changes, I need to have some way of knowing if the primary interface has changed, or some other one (which I don't care about). At the moment, the code to do this looks like so:
def manage_transition(self, previous = [], **kwargs):
primary_ip = self._get_primary_ip()
try:
previous[0]
except IndexError:
print "No previous address"
previous.append(None)
if previous[0] == primary_ip:
print "No change on primary interface. IP is %s" % (primary_ip)
else:
""do stuff where primary IP changed""
previous.pop()
previous.append(primary_ip)
So, I'm using a 1-item list to keep track of what the last IP address was. This works fine but seems rather contrived. I'm new to python, so I'm just wondering if the more seasoned folks could point out a better method...?
Many TIA,
-geoff
--
You received this message because you are subscribed to the Google Groups "PyMacAdmin" group.
To post to this group, send email to
pymac...@googlegroups.com.
To unsubscribe from this group, send email to
pymacadmin+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/pymacadmin?hl=en.