Converted some print statements to logging statments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
|
import logging
|
||||||
|
|
||||||
class OptionsResults(object):
|
class OptionsResults(object):
|
||||||
pass
|
pass
|
||||||
@@ -22,10 +23,12 @@ class ConfigOptionParser(object):
|
|||||||
self.requiredArgs = []
|
self.requiredArgs = []
|
||||||
|
|
||||||
def display_config(self):
|
def display_config(self):
|
||||||
|
logging.info("Using the following settings:")
|
||||||
for x in self.configVars:
|
for x in self.configVars:
|
||||||
n = x['dest']
|
n = x['dest']
|
||||||
print "%s: %r" % (n, self.configResults.__dict__[n])
|
print "%s: %r" % (n, self.configResults.__dict__[n])
|
||||||
|
|
||||||
|
|
||||||
def add_option(self, *args, **kwargs):
|
def add_option(self, *args, **kwargs):
|
||||||
|
|
||||||
if kwargs.get("configFileOnly", False) and kwargs.get("commandLineOnly", False):
|
if kwargs.get("configFileOnly", False) and kwargs.get("commandLineOnly", False):
|
||||||
@@ -71,14 +74,14 @@ class ConfigOptionParser(object):
|
|||||||
except NameError, ex:
|
except NameError, ex:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print "\nError parsing %s. Please check the trackback above" % self.configFile
|
logging.error("Error parsing %s. Please check the trackback above" % self.configFile)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except SyntaxError, ex:
|
except SyntaxError, ex:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
tb = sys.exc_info()[2]
|
tb = sys.exc_info()[2]
|
||||||
#print tb.tb_frame.f_code.co_filename
|
#print tb.tb_frame.f_code.co_filename
|
||||||
print "\nError parsing %s. Please check the trackback above" % self.configFile
|
logging.error("Error parsing %s. Please check the trackback above" % self.configFile)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
#print l.keys()
|
#print l.keys()
|
||||||
@@ -89,7 +92,7 @@ class ConfigOptionParser(object):
|
|||||||
n = a['dest']
|
n = a['dest']
|
||||||
if a.get('commandLineOnly', False):
|
if a.get('commandLineOnly', False):
|
||||||
if n in l.keys():
|
if n in l.keys():
|
||||||
print "Error: %s can only be specified on the command line. It is not valid in the config file" % n
|
logging.error("Error: %s can only be specified on the command line. It is not valid in the config file" % n)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
configResults.__dict__[n] = l.get(n)
|
configResults.__dict__[n] = l.get(n)
|
||||||
@@ -113,7 +116,8 @@ class ConfigOptionParser(object):
|
|||||||
for a in self.configVars:
|
for a in self.configVars:
|
||||||
n = a['dest']
|
n = a['dest']
|
||||||
if configResults.__dict__[n] == None and a.get('required',False):
|
if configResults.__dict__[n] == None and a.get('required',False):
|
||||||
raise Exception("%s is required" % n)
|
logging.error("%s is required" % n)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# sixth, check types
|
# sixth, check types
|
||||||
for a in self.configVars:
|
for a in self.configVars:
|
||||||
@@ -128,7 +132,7 @@ class ConfigOptionParser(object):
|
|||||||
try:
|
try:
|
||||||
configResults.__dict__[n] = self.checkType(configResults.__dict__[n], a)
|
configResults.__dict__[n] = self.checkType(configResults.__dict__[n], a)
|
||||||
except ValueError, ex:
|
except ValueError, ex:
|
||||||
print "There was a problem converting the value '%s' to type %s for config parameter '%s'" % (configResults.__dict__[n], a['type'], n)
|
logging.error("There was a problem converting the value '%s' to type %s for config parameter '%s'" % (configResults.__dict__[n], a['type'], n))
|
||||||
import traceback
|
import traceback
|
||||||
#traceback.print_exc()
|
#traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -153,7 +157,7 @@ class ConfigOptionParser(object):
|
|||||||
return long(value)
|
return long(value)
|
||||||
elif a['type'] == "choice":
|
elif a['type'] == "choice":
|
||||||
if value not in a['choices']:
|
if value not in a['choices']:
|
||||||
print "The value '%s' is not valid for config parameter '%s'" % (value, a['dest'])
|
logging.error("The value '%s' is not valid for config parameter '%s'" % (value, a['dest']))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return value
|
return value
|
||||||
elif a['type'] == "float":
|
elif a['type'] == "float":
|
||||||
@@ -164,5 +168,5 @@ class ConfigOptionParser(object):
|
|||||||
if not callable(value):
|
if not callable(value):
|
||||||
raise ValueError("Not callable")
|
raise ValueError("Not callable")
|
||||||
else:
|
else:
|
||||||
print "Unknown type!"
|
logging.error("Unknown type!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def main():
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
print "You need to give me your world number or directory"
|
logging.error("You need to give me your world number or directory")
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
list_worlds()
|
list_worlds()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -113,7 +113,7 @@ def main():
|
|||||||
# if there are no worlds found at all, exit now
|
# if there are no worlds found at all, exit now
|
||||||
if not worlds:
|
if not worlds:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
print "\nInvalid world path"
|
logging.error("Invalid world path")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -126,12 +126,12 @@ def main():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
# it's not a number, name, or path
|
# it's not a number, name, or path
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
print "Invalid world name or path"
|
logging.error("Invalid world name or path")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# it was an invalid number
|
# it was an invalid number
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
print "Invalid world number"
|
logging.error("Invalid world number")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user