summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartinko2012-12-04 16:25:56 +0000
committermartinko2012-12-04 16:25:56 +0000
commit2a99411a9cfe2c93a41dcb70ec06e324663c31ca (patch)
treef6f8b5f3c25e2e2260ab1b97f178791d575a5eb5
parent33a3d1fa5b43dbd342310b503c60faf0c560a7f3 (diff)
londiste/handlers/dispatch: caught up with recent changes
Auto-generated handlers have help and properly check their arg names now.
-rw-r--r--python/londiste/handlers/__init__.py3
-rw-r--r--python/londiste/handlers/dispatch.py65
2 files changed, 57 insertions, 11 deletions
diff --git a/python/londiste/handlers/__init__.py b/python/londiste/handlers/__init__.py
index 8467916a..92705462 100644
--- a/python/londiste/handlers/__init__.py
+++ b/python/londiste/handlers/__init__.py
@@ -32,8 +32,7 @@ def handler_args(name, cls):
return wrapper
def update(*p):
- """ Update dicts given in params with its precessor param dict
+ """ Update dicts given in params with its predecessor param dict
in reverse order """
return reduce(lambda x, y: x.update(y) or x,
(p[i] for i in range(len(p)-1,-1,-1)), {})
-
diff --git a/python/londiste/handlers/dispatch.py b/python/londiste/handlers/dispatch.py
index 2917472b..eafa201f 100644
--- a/python/londiste/handlers/dispatch.py
+++ b/python/londiste/handlers/dispatch.py
@@ -61,7 +61,7 @@ period:
part_name:
custom name template for partition table. default is None as it is built
- automatically
+ automatically.
example for daily partition: %(parent)s_%(year)s_%(month)s_%(day)s
template variables:
* parent - parent table name
@@ -79,7 +79,7 @@ part_template:
* parent - parent table name
* pkey - parent table primary keys
* schema_table - table name with replace: '.' -> '__'. for using in
- pk names etc.
+ pk names etc.
* part_field - date field name if table is partitioned by field
* part_time - time of partition
@@ -103,12 +103,12 @@ load_mode:
method:
loading method for load_mode bulk. defaults to 0
- 0 (correct) - inserts as COPY into table,
+ * 0 (correct) - inserts as COPY into table,
update as COPY into temp table and single UPDATE from there
delete as COPY into temp table and single DELETE from there
- 1 (delete) - as 'correct', but do update as DELETE + COPY
- 2 (merged) - as 'delete', but merge insert rows with update rows
- 3 (insert) - COPY inserts into table, error when other events
+ * 1 (delete) - as 'correct', but do update as DELETE + COPY
+ * 2 (merged) - as 'delete', but merge insert rows with update rows
+ * 3 (insert) - COPY inserts into table, error when other events
fields:
field name map for using just part of the fields and rename them
@@ -136,8 +136,10 @@ encoding:
and logs them as warnings
analyze:
- 0 - do not run analyze on temp tables (default)
- 1 - run analyze on temp tables
+ * 0 - do not run analyze on temp tables (default)
+ * 1 - run analyze on temp tables
+
+== NOTES ==
NB! londiste3 does not currently support table renaming and field mapping when
creating or coping initial data to destination table. --expect-sync and
@@ -636,6 +638,29 @@ class Dispatcher(BaseHandler):
else:
self.encoding_validator = None
+ def _parse_args_from_doc (self):
+ doc = __doc__
+ params_descr = []
+ params_found = False
+ for line in doc.splitlines():
+ ln = line.strip()
+ if params_found:
+ if ln.startswith("=="):
+ break
+ m = re.match ("^(\w+):$", ln)
+ if m:
+ name = m.group(1)
+ expr = text = ""
+ elif not params_descr:
+ continue
+ else:
+ name, expr, text = params_descr.pop()
+ text += ln + "\n"
+ params_descr.append ((name, expr, text))
+ elif ln == "== HANDLER ARGUMENTS ==":
+ params_found = True
+ return params_descr
+
def get_config(self):
"""Processes args dict"""
conf = skytools.dbdict()
@@ -894,6 +919,15 @@ class Dispatcher(BaseHandler):
write_hook = _write_hook)
+# add arguments' description to handler's docstring
+found = False
+for line in __doc__.splitlines():
+ if line.startswith ("== HANDLER ARGUMENTS =="):
+ found = True
+ if found:
+ Dispatcher.__doc__ += "\n" + line
+del found
+
#------------------------------------------------------------------------------
# register handler class
@@ -904,7 +938,7 @@ __londiste_handlers__ = [Dispatcher]
#------------------------------------------------------------------------------
-# helper function for creating dispachers with different default values
+# helper function for creating dispatchers with different default values
#------------------------------------------------------------------------------
handler_args = partial(handler_args, cls=Dispatcher)
@@ -931,6 +965,13 @@ BASE = { 'table_mode': 'part',
'row_mode': 'keep_latest',
}
+def set_handler_doc (cls, defs):
+ """ generate handler docstring """
+ cls.__doc__ = "Custom dispatch handler with default args.\n\n" \
+ "Parameters:\n"
+ for k,v in defs.items():
+ cls.__doc__ += " %s = %s\n" % (k,v)
+
for load, load_dict in LOAD.items():
for period, period_dict in PERIOD.items():
for mode, mode_dict in MODE.items():
@@ -942,12 +983,18 @@ for load, load_dict in LOAD.items():
def handler_func(args):
return update(args, default)
create_handler()
+ hcls = __londiste_handlers__[-1] # it was just added
+ defs = update(mode_dict, period_dict, load_dict, BASE)
+ set_handler_doc (hcls, defs)
+del (hcls, defs)
@handler_args('bulk_direct')
def bulk_direct_handler(args):
return update(args, {'load_mode': 'bulk', 'table_mode': 'direct'})
+set_handler_doc (__londiste_handlers__[-1], {'load_mode': 'bulk', 'table_mode': 'direct'})
@handler_args('direct')
def direct_handler(args):
return update(args, {'load_mode': 'direct', 'table_mode': 'direct'})
+set_handler_doc (__londiste_handlers__[-1], {'load_mode': 'direct', 'table_mode': 'direct'})