londiste: moved config processing from dispatch to base handler
authormartinko <gamato@users.sf.net>
Thu, 17 Oct 2013 14:23:31 +0000 (16:23 +0200)
committermartinko <gamato@users.sf.net>
Thu, 17 Oct 2013 14:23:31 +0000 (16:23 +0200)
python/londiste/handler.py
python/londiste/handlers/dispatch.py

index 287ad546eda483da3b9b8ee4f3f28af384259010..8ce45cff3ad12158782d071a7e34baedf3fea7f1 100644 (file)
@@ -78,6 +78,7 @@ class BaseHandler:
         self.fq_dest_table = skytools.quote_fqident(self.dest_table)
         self.args = args
         self._check_args (args)
+        self.conf = self.get_config()
 
     def _parse_args_from_doc (self):
         doc = self.__doc__ or ""
@@ -111,6 +112,19 @@ class BaseHandler:
         if invalid:
             raise ValueError ("Invalid handler argument: %s" % list(invalid))
 
+    def get_arg (self, name, value_list, default = None):
+        """ Return arg value or default; also check if value allowed. """
+        default = default or value_list[0]
+        val = type(default)(self.args.get(name, default))
+        if val not in value_list:
+            raise Exception('Bad argument %s value %r' % (name, val))
+        return val
+
+    def get_config (self):
+        """ Process args dict (into handler config). """
+        conf = skytools.dbdict()
+        return conf
+
     def add(self, trigger_arg_list):
         """Called when table is added.
 
index 477fd119a13a4e9dc694f0c8c87f4fb371c79125..2e1c3143cfecee04185432fbc87faaee567bbf0f 100644 (file)
@@ -646,7 +646,6 @@ class Dispatcher (ShardHandler):
         self.dst_curs = None
         self.pkeys = None
         # config
-        self.conf = self.get_config()
         hdlr_cls = ROW_HANDLERS[self.conf.row_mode]
         self.row_handler = hdlr_cls(self.log)
 
@@ -675,7 +674,7 @@ class Dispatcher (ShardHandler):
 
     def get_config(self):
         """Processes args dict"""
-        conf = skytools.dbdict()
+        conf = ShardHandler.get_config(self)
         # set table mode
         conf.table_mode = self.get_arg('table_mode', TABLE_MODES)
         conf.analyze = self.get_arg('analyze', [0, 1])
@@ -723,13 +722,6 @@ class Dispatcher (ShardHandler):
                     conf.field_map[tmp[0]] = tmp[1]
         return conf
 
-    def get_arg(self, name, value_list, default = None):
-        default = default or value_list[0]
-        val = type(default)(self.args.get(name, default))
-        if val not in value_list:
-            raise Exception('Bad argument %s value %r' % (name, val))
-        return val
-
     def _validate_hash_key(self):
         pass # no need for hash key when not sharding