Permalink
Browse files

changed pybit.load_settings to return a tuple of the settings object …

…and the path it opened.
  • Loading branch information...
Nicholas Davidson
Nicholas Davidson committed Nov 13, 2012
1 parent 43f6f8d commit 597634825e7b96ad9452e0ff2ffdbe69979415ae
Showing with 45 additions and 24 deletions.
  1. +1 −1 application.wsgi
  2. +3 −3 buildd-test.py
  3. +1 −1 pybit-client
  4. +30 −10 pybit-watcher
  5. +8 −7 pybit/__init__.py
  6. +1 −1 pybit_web.py
  7. +1 −1 test/pybitclient-test.py
View
@@ -17,7 +17,7 @@ import pybitweb
from pybitweb.db import Database
from pybitweb.controller import Controller
-settings = pybit.load_settings("web.conf")
+(settings, opened_path) = pybit.load_settings("web.conf")
myDb = Database(settings['db']) # singleton instance
buildController = Controller(settings['controller'], myDb) # singleton instance
application = pybitweb.get_app(settings,myDb,buildController)
View
@@ -36,9 +36,9 @@ def main():
logging.basicConfig( format=FORMAT )
conffile = "%s/configs/client/client.conf" % (os.getcwd());
if os.path.isfile (conffile):
- settings = pybit.load_settings(conffile)
+ (settings, opened_path) = pybit.load_settings(conffile)
else :
- settings = pybit.load_settings("/etc/pybit/client/client.conf")
+ (settings, opened_path) = pybit.load_settings("/etc/pybit/client/client.conf")
build_client = PyBITClient(settings["host_arch"], settings["distribution"], settings["pkg_format"], settings["suite"], None, settings)
testconf = "%s/buildd-test.conf" % (os.getcwd());
@@ -47,7 +47,7 @@ def main():
print "I: Copy /usr/share/pybitclient/buildd-test.conf and modify it for your available packages."
return 1
else :
- test_options = pybit.load_settings(testconf)
+ (test_options, opened_path) = pybit.load_settings(testconf)
count = 0
max_count = test_options["count"]
View
@@ -146,7 +146,7 @@ if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.debug ("I: Not daemonised")
- settings = pybit.load_settings(options.conf_file)
+ (settings, opened_path) = pybit.load_settings(options.conf_file)
settings = pybit.merge_options(settings, groupConfigFile, options)
if settings == {}:
View
@@ -32,10 +32,18 @@ import os
import sys
import logging
+from pybitclient.daemonlogger import LoggingDaemonContext, FileLikeLogger
+
settings= {}
META="PYBIT_WATCHER_"
+def getDaemonLogger (filePath, format = None) :
+ FORMAT = format or '%(asctime)s %(msg)s'
+ logging.basicConfig(filename=filePath, format=FORMAT, level=logging.DEBUG)
+ logging.debug ("I: Daemonised")
+ return logging.getLogger()
+
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
if os.path.isfile(event.pathname) and event.pathname.endswith(".changes"):
@@ -74,13 +82,29 @@ if __name__ == '__main__':
(options, args) = parser.parse_args()
- settings = pybit.load_settings(options.conf_file)
+ (settings, opened_path) = pybit.load_settings(options.conf_file)
+
+ if options.daemonise :
+ testLogger = getDaemonLogger('/var/log/pybitclient.log')
+ stdoutLogger = getDaemonLogger('/dev/null')
+ stderrLogger = getDaemonLogger('/dev/null')
+ context = LoggingDaemonContext()
+ context.loggers_preserve=[testLogger]
+ context.stdout_logger = stdoutLogger
+ context.stderr_logger = stderrLogger
+ logging.debug ("I: Daemonised")
+ else :
+# FORMAT = format or '%(asctime)s %(msg)s'
+ logging.basicConfig(level=logging.DEBUG)
+ logging.debug ("I: Not daemonised")
+
+
if settings == {}:
- logging.debug("Couldn't load configuration from %s" % options.conf_file)
+ logging.debug("Couldn't load configuration from %s" % opened_path)
sys.exit(-1)
if 'configured' in settings and settings['configured'] == False:
- logging.debug ("Please configure your client.")
+ logging.debug ("Please configure your client. Edit %s" % opened_path)
sys.exit(os.EX_OK)
settings = pybit.merge_options(settings, groupConfigFile, options)
@@ -93,16 +117,12 @@ if __name__ == '__main__':
wdd = wm.add_watch(settings['path'], mask, rec=True)
- if options.daemonise:
+
+ if options.daemonise == True:
with daemon.DaemonContext():
pid = str(os.getpid())
file(PIDFILE, 'w').write(pid)
- FORMAT = '%(asctime)s %(filename)s:%(lineno)d %(msg)s'
- logging.basicConfig(filename='/tmp/pybitclient.log', level=logging.DEBUG)
- logging.basicConfig( format=FORMAT )
- log = logging.getLogger( "pybit-client" )
- log.debug ("I: Daemonised")
- log.debug ("I: Running build client.")
notifier.loop()
else:
+ logging.debug ("I: Running watcher")
notifier.loop()
View
@@ -64,27 +64,28 @@ def get_build_route_name(dist, arch, suite, package):
def load_settings(path):
opened_file = None
+ opened_path = path
#try the unmodified path incase we're being passed an absolute path.
try:
opened_file = open(path)
except IOError:
- new_path = "./configs/%s" % path
+ opened_path = "./configs/%s" % path
try:
- opened_file = open(new_path, 'r')
+ opened_file = open(opened_path, 'r')
except IOError:
- new_path = "/etc/pybit/%s" % path
+ opened_path = "/etc/pybit/%s" % path
try:
- opened_file = open(new_path)
+ opened_file = open(opened_path)
except IOError:
pass
if opened_file:
encoded_string = opened_file.read()
try:
- return jsonpickle.decode(encoded_string )
+ return (jsonpickle.decode(encoded_string ), opened_path)
except ValueError :
- return {}
+ return ({}, opened_path)
else:
- return {}
+ return ({}, opened_path)
exchange_name="pybit"
status_route="pybit.control.status"
View
@@ -49,7 +49,7 @@
parser.add_option("-v", dest="verbose", action="store_true", default=False,
help="Turn on verbose messages.", metavar=META+"VERBOSE")
(options, args) = parser.parse_args()
- settings = pybit.load_settings(options.config)
+ (settings, opened_file) = pybit.load_settings(options.config)
settings = pybit.merge_options(settings, groupConfigFile, options)
myDb = Database(settings['db']) # singleton instance
View
@@ -43,7 +43,7 @@ def test_01_client_config (self) :
conffile = "%s/configs/client/client.conf" % (os.getcwd());
self.assertTrue (os.path.isfile(conffile), "could not find %s" % conffile)
log.debug("I: reading %s" % (os.path.relpath(conffile, os.getcwd())))
- self.options = pybit.load_settings(conffile)
+ (self.options, opened_path) = pybit.load_settings(conffile)
if not "dry_run" in self.options :
msg = "I: asserting dry_run for test cases"
log.debug (msg)

0 comments on commit 5976348

Please sign in to comment.