r39089 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39088‎ | r39089 | r39090 >
Date:20:50, 10 August 2008
Author:mark
Status:old
Tags:
Comment:
Move ConfigDict to module util
Modified paths:
  • /trunk/pybal/pybal/pybal.py (modified) (history)
  • /trunk/pybal/pybal/util.py (modified) (history)

Diff [purge]

Index: trunk/pybal/pybal/util.py
@@ -1,6 +1,6 @@
22 """
33 util.py - PyBal utility classes
4 -Copyright (C) 2006 by Mark Bergsma <mark@nedworks.org>
 4+Copyright (C) 2006-2008 by Mark Bergsma <mark@nedworks.org>
55
66 LVS Squid balancer/monitor for managing the Wikimedia Squid servers using LVS
77 """
@@ -37,3 +37,41 @@
3838 self.file.close()
3939 self.file = file(self.filename, 'a')
4040 self.lineEnded = True
 41+
 42+class ConfigDict(dict):
 43+
 44+ def getint(self, key, default=None):
 45+ try:
 46+ return int(self[key])
 47+ except KeyError:
 48+ if defaut is not None:
 49+ return default
 50+ else:
 51+ raise
 52+ # do not intercept ValueError
 53+
 54+ def getboolean(self, key, default=None):
 55+ try:
 56+ value = self[key].strip().lower()
 57+ except KeyError:
 58+ if default is not None:
 59+ return default
 60+ else:
 61+ raise
 62+ else:
 63+ if value in ('t', 'true', 'y', 'yes', 'on', '1'):
 64+ return True
 65+ elif value in ('f', 'false', 'n', 'no', 'off', '0'):
 66+ return False
 67+ else:
 68+ raise ValueError
 69+
 70+ def getfloat(self, key, default=None):
 71+ try:
 72+ return float(self[key])
 73+ except KeyError:
 74+ if default is not None:
 75+ return default
 76+ else:
 77+ raise
 78+ # do not intercept ValueError
\ No newline at end of file
Index: trunk/pybal/pybal/pybal.py
@@ -11,7 +11,7 @@
1212
1313 import os, sys, signal
1414
15 -import ipvs, monitor, bgp
 15+import ipvs, monitor, bgp, util
1616
1717 from twisted.internet import reactor
1818
@@ -388,44 +388,6 @@
389389 @classmethod
390390 def addPrefix(cls, prefix):
391391 cls.prefixes.add(bgp.IPv4IP(prefix)) # FIXME: IPv6
392 -
393 -class ConfigDict(dict):
394 -
395 - def getint(self, key, default=None):
396 - try:
397 - return int(self[key])
398 - except KeyError:
399 - if defaut is not None:
400 - return default
401 - else:
402 - raise
403 - # do not intercept ValueError
404 -
405 - def getboolean(self, key, default=None):
406 - try:
407 - value = self[key].strip().lower()
408 - except KeyError:
409 - if default is not None:
410 - return default
411 - else:
412 - raise
413 - else:
414 - if value in ('t', 'true', 'y', 'yes', 'on', '1'):
415 - return True
416 - elif value in ('f', 'false', 'n', 'no', 'off', '0'):
417 - return False
418 - else:
419 - raise ValueError
420 -
421 - def getfloat(self, key, default=None):
422 - try:
423 - return float(self[key])
424 - except KeyError:
425 - if default is not None:
426 - return default
427 - else:
428 - raise
429 - # do not intercept ValueError
430392
431393 def parseCommandLine(configuration):
432394 """
@@ -621,7 +583,7 @@
622584 config.get(section, 'scheduler'))
623585
624586 # Read the custom configuration options of the LVS section
625 - configdict = ConfigDict(config.items(section))
 587+ configdict = util.ConfigDict(config.items(section))
626588
627589 # Override with command line options
628590 configdict.update(cliconfig)

Status & tagging log