commit 2cd99e7ad4fd097f773237554c1a9257df4edb3b
Author: Georgios Gousios <gousiosg@gmail.com>
Date:   Wed May 11 09:53:08 2011 +0300

    Style and pylint suggested fixes

diff --git a/aai/middleware.py b/aai/middleware.py
index ef6fd85..683a0e6 100644
--- a/aai/middleware.py
+++ b/aai/middleware.py
@@ -19,8 +19,8 @@ class SynnefoAuthMiddleware(object):
         # test user on first access
         # TODO: REMOVE THE FOLLOWING BEFORE DEPLOYMENT
         if request.GET.get('test') is not None:
-            u = SynnefoUser.objects.get(auth_token='46e427d657b20defe352804f0eb6f8a2')
-            return self._redirect_shib_auth_user(user = u)
+            usr = SynnefoUser.objects.get(auth_token='46e427d657b20defe352804f0eb6f8a2')
+            return self._redirect_shib_auth_user(user = usr)
 
         token = None
         #Try to find token in a cookie
diff --git a/aai/shibboleth.py b/aai/shibboleth.py
index da6c54d..9f7bd87 100644
--- a/aai/shibboleth.py
+++ b/aai/shibboleth.py
@@ -6,6 +6,7 @@
 
 from synnefo.logic import users
 
+
 class Tokens:
     SIB_NAME = "Shib-InetOrgPerson-givenName"
     SIB_SURNAME = "Shib-Person-surname"
@@ -17,20 +18,16 @@ class Tokens:
     SIB_GR_EDU_PERSON_UNDERGRADUATE_BRANCH = "grEduPersonUndergraduateBranch"
     SIB_SESSION_ID = "Shib-Session-ID"
 
-class NoUniqueToken(object):
+class NoUniqueToken(BaseException):
 
     def __init__(self, msg):
         self.msg = msg
-    
-    pass
 
-class NoRealName(object):
+class NoRealName(BaseException):
 
     def __init__(self, msg):
         self.msg = msg
 
-    pass
-
 def register_shibboleth_user(tokens):
     """Registers a sibbolleth user using the input hash as a source for data.
        The token requirements are described in:
@@ -61,8 +58,8 @@ def register_shibboleth_user(tokens):
         raise NoRealName("Authentication does not return the user's name")
 
     if is_student:
-        users.register_student(realname, '' ,unq)
+        users.register_student(realname, '' , unq)
     else:
-        users.register_professor(realname, '' ,unq)
+        users.register_professor(realname, '' , unq)
 
     return True
diff --git a/aai/tests.py b/aai/tests.py
index d3cb630..839d54d 100644
--- a/aai/tests.py
+++ b/aai/tests.py
@@ -5,7 +5,6 @@
 #
 # Copyright 2011 Greek Research and Technology Network
 #
-from Cookie import Cookie
 
 from django.test import TestCase
 from django.test.client import Client
@@ -15,7 +14,8 @@ from synnefo.db.models import SynnefoUser
 
 from datetime import datetime, timedelta
 
-from synnefo.aai.shibboleth import Tokens, NoUniqueToken
+from synnefo.aai.shibboleth import Tokens
+
 
 class AaiTestCase(TestCase):
     fixtures = ['api_test_data', 'auth_test_data']
@@ -45,7 +45,6 @@ class AaiTestCase(TestCase):
         self.assertEquals(response['X-Auth-Token'], user.auth_token)
         #self.assertNotEquals(response.cookies['X-Auth-Token'].find(user.auth_token), -1)
 
-
     def test_shibboleth_no_uniq_request(self):
         """test a request with no unique field
         """
@@ -55,13 +54,12 @@ class AaiTestCase(TestCase):
                                   'TEST-AAI': 'true'})
         self._test_redirect(response)
 
-
     def test_shibboleth_expired_token(self):
         """ test request from expired token
         """
         user = SynnefoUser.objects.get(uniq="test@synnefo.gr")
         self.assertNotEqual(user.auth_token_created, None)
-        self._update_user_ts(user)
+        _update_user_ts(user)
         response = self.client.get('/index.html', {},
                                **{'X-Auth-Token': user.auth_token,
                                   'TEST-AAI': 'true'})
@@ -89,7 +87,7 @@ class AaiTestCase(TestCase):
         self.assertTrue('Location' in response)
         self.assertTrue(response['Location'].endswith(settings.LOGIN_PATH))
 
-    def _update_user_ts(self, user):
-        user.auth_token_created = (datetime.now() -
-                                   timedelta(hours = settings.AUTH_TOKEN_DURATION))
-        user.save()
\ No newline at end of file
+def _update_user_ts(user):
+    user.auth_token_created = (datetime.now() -
+                               timedelta(hours = settings.AUTH_TOKEN_DURATION))
+    user.save()
\ No newline at end of file
diff --git a/ganeti/ganeti-eventd.py b/ganeti/ganeti-eventd.py
index 35c875a..c4d9b04 100755
--- a/ganeti/ganeti-eventd.py
+++ b/ganeti/ganeti-eventd.py
@@ -30,8 +30,6 @@ from signal import signal, SIGINT, SIGTERM
 
 from amqplib import client_0_8 as amqp
 
-from threading import Thread, Event, currentThread
-
 from ganeti import utils
 from ganeti import jqueue
 from ganeti import constants
@@ -54,7 +52,6 @@ class JobFileHandler(pyinotify.ProcessEvent):
                      virtual_host=settings.RABBIT_VHOST)
             except socket.error:
                 time.sleep(1)
-                pass
         
         handler_logger.info("Connection succesful, opening channel")
         return conn.channel()
@@ -135,7 +132,7 @@ def fatal_signal_handler(signum, frame):
     global handler_logger
 
     handler_logger.info("Caught fatal signal %d, will raise SystemExit",
-            signum)
+                        signum)
     raise SystemExit
 
 def parse_arguments(args):
@@ -143,17 +140,17 @@ def parse_arguments(args):
 
     parser = OptionParser()
     parser.add_option("-d", "--debug", action="store_true", dest="debug",
-            help="Enable debugging information")
+                      help="Enable debugging information")
     parser.add_option("-l", "--log", dest="log_file",
-            default=settings.GANETI_EVENTD_LOG_FILE,
-            metavar="FILE",
-            help="Write log to FILE instead of %s" %
-            settings.GANETI_EVENTD_LOG_FILE),
+                      default=settings.GANETI_EVENTD_LOG_FILE,
+                      metavar="FILE",
+                      help="Write log to FILE instead of %s" %
+                           settings.GANETI_EVENTD_LOG_FILE)
     parser.add_option('--pid-file', dest="pid_file",
-            default=settings.GANETI_EVENTD_PID_FILE,
-            metavar='PIDFILE',
-            help="Save PID to file (default: %s)" %
-            settings.GANETI_EVENTD_PID_FILE)
+                      default=settings.GANETI_EVENTD_PID_FILE,
+                      metavar='PIDFILE',
+                      help="Save PID to file (default: %s)" %
+                           settings.GANETI_EVENTD_PID_FILE)
 
     return parser.parse_args(args)
 
diff --git a/logic/dispatcher.py b/logic/dispatcher.py
index f83d4ce..98b0fd0 100755
--- a/logic/dispatcher.py
+++ b/logic/dispatcher.py
@@ -2,10 +2,11 @@
 #
 # Copyright (c) 2011 Greek Research and Technology Network
 #
-"""Connect to a queue 
-
-This daemon receives job notifications from a number of queues
+""" Message queue setup and dispatch
 
+This program sets up connections to the queues configured in settings.py
+and implements the message wait and dispatch loops. Actual messages are
+handled in the dispatched functions.
 
 """
 
@@ -20,7 +21,6 @@ import synnefo.settings as settings
 setup_environ(settings)
 
 from amqplib import client_0_8 as amqp
-
 from signal import signal, SIGINT, SIGTERM
 
 import logging
@@ -29,8 +29,6 @@ import socket
 
 from synnefo.logic import dispatcher_callbacks
 
-# List of worker ids
-global children
 
 class Dispatcher:
 
@@ -53,7 +51,6 @@ class Dispatcher:
             except socket.error:
                 self.logger.error("Server went away, reconnecting...")
                 self._init()
-                pass
 
         [self.chan.basic_cancel(clienttag) for clienttag in self.clienttags]
         self.chan.close()
@@ -73,7 +70,6 @@ class Dispatcher:
                                        virtual_host=settings.RABBIT_VHOST)
             except socket.error:
                 time.sleep(1)
-                pass
 
         self.logger.info("Connection succesful, opening channel")
         self.chan = conn.channel()
@@ -98,14 +94,14 @@ class Dispatcher:
         # Bind queues to handler methods
         for binding in bindings:
             try:
-                cb = getattr(dispatcher_callbacks, binding[3])
+                callback = getattr(dispatcher_callbacks, binding[3])
             except AttributeError:
                 self.logger.error("Cannot find callback %s" % binding[3])
                 continue
 
             self.chan.queue_bind(queue=binding[0], exchange=binding[1],
                                  routing_key=binding[2])
-            tag = self.chan.basic_consume(queue=binding[0], callback=cb)
+            tag = self.chan.basic_consume(queue=binding[0], callback=callback)
             self.logger.debug("Binding %s(%s) to queue %s with handler %s" %
                               (binding[1], binding[2], binding[0], binding[3]))
             self.clienttags.append(tag)
@@ -113,7 +109,7 @@ class Dispatcher:
 
 def _exit_handler(signum, frame):
     """"Catch exit signal in children processes."""
-    print "%d: Caught signal %d, will raise SystemExit" % (os.getpid(),signum)
+    print "%d: Caught signal %d, will raise SystemExit" % (os.getpid(), signum)
     raise SystemExit
 
 
@@ -129,10 +125,10 @@ def child(cmdline, logger):
 
     # Cmd line argument parsing
     (opts, args) = parse_arguments(cmdline)
-    d = Dispatcher(debug = opts.debug, logger = logger)
+    disp = Dispatcher(debug = opts.debug, logger = logger)
 
     # Start the event loop
-    d.wait()
+    disp.wait()
 
 
 def parse_arguments(args):
@@ -140,18 +136,16 @@ def parse_arguments(args):
 
     parser = OptionParser()
     parser.add_option("-d", "--debug", action="store_true", default=False,
-                      dest="debug",
-            help="Enable debug mode")
+                      dest="debug", help="Enable debug mode")
     parser.add_option("-l", "--log", dest="log_file",
-            default=settings.DISPATCHER_LOG_FILE,
-            metavar="FILE",
-            help="Write log to FILE instead of %s" %
-            settings.DISPATCHER_LOG_FILE)
+                      default=settings.DISPATCHER_LOG_FILE, metavar="FILE",
+                      help="Write log to FILE instead of %s" %
+                           settings.DISPATCHER_LOG_FILE)
     parser.add_option("-c", "--cleanup-queues", action="store_true",
                       default=False, dest="cleanup_queues",
-            help="Remove all queues declared in settings.py (DANGEROUS!)")
+                      help="Remove all queues declared in settings.py (DANGEROUS!)")
     parser.add_option("-w", "--workers", default=2, dest="workers",
-            help="Number of workers to spawn", type="int")
+                      help="Number of workers to spawn", type="int")
     
     return parser.parse_args(args)
 
@@ -197,8 +191,8 @@ def main():
     logger = logging.getLogger("synnefo.dispatcher")
     logger.setLevel(lvl)
     formatter = logging.Formatter(
-            "%(asctime)s %(module)s[%(process)d] %(levelname)s: %(message)s",
-            "%Y-%m-%d %H:%M:%S")
+        "%(asctime)s %(module)s[%(process)d] %(levelname)s: %(message)s",
+        "%Y-%m-%d %H:%M:%S")
     handler = logging.FileHandler(opts.log_file)
     handler.setFormatter(formatter)
     logger.addHandler(handler)
@@ -231,9 +225,9 @@ def main():
     signal(SIGTERM, _parent_handler)
 
     # Wait for all children process to die, one by one
-    for c in children:
+    for pid in children:
         try:
-            os.wait()
+            os.waitpid(pid)
         except Exception:
             pass
 
