From a4298d8661d5f091dde28e10ff7786659e2275d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= Date: Fri, 25 Oct 2019 12:03:08 +0200 Subject: [PATCH 1/5] Support for overriding -D parameters with dot notation --- jinja2cli/cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index 79d84db..adbae9f 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -321,7 +321,13 @@ def parse_kv_string(pairs): dict_ = {} for pair in pairs: k, v = pair.split("=", 1) - dict_[force_text(k)] = force_text(v) + k=force_text(k) + v=force_text(v) + aux=dict() + for i in reversed(k.split('.')): + aux={i:v} + v=aux + dict_.update(aux) return dict_ From 45ec806e48db49425082066bdb5bc90cd7ef0138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= Date: Fri, 25 Oct 2019 12:31:51 +0200 Subject: [PATCH 2/5] Fix whitespaces issues for Travis CI --- jinja2cli/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index adbae9f..106d28c 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -321,12 +321,12 @@ def parse_kv_string(pairs): dict_ = {} for pair in pairs: k, v = pair.split("=", 1) - k=force_text(k) - v=force_text(v) - aux=dict() + k = force_text(k) + v = force_text(v) + aux = dict() for i in reversed(k.split('.')): - aux={i:v} - v=aux + aux = { i : v } + v = aux dict_.update(aux) return dict_ From 0f7ea56584f25ac253da62d148d44e37c4a5bf1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= Date: Fri, 25 Oct 2019 12:40:28 +0200 Subject: [PATCH 3/5] @atorrescogollo --- jinja2cli/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index 106d28c..fdd4cbf 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -325,7 +325,7 @@ def parse_kv_string(pairs): v = force_text(v) aux = dict() for i in reversed(k.split('.')): - aux = { i : v } + aux = {i: v} v = aux dict_.update(aux) return dict_ From 15665494836eeb653b757406c454336ed83b6ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= Date: Fri, 25 Oct 2019 14:32:33 +0200 Subject: [PATCH 4/5] Fixed breaks when using more than two key levels --- jinja2cli/cli.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index fdd4cbf..7cb778e 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -300,7 +300,7 @@ def cli(opts, args): sys.stderr.write("ERROR: unknown section. Exiting.") return 1 - data.update(parse_kv_string(opts.D or [])) + parse_kv_string(data, opts.D or []) if opts.outfile is None: out = sys.stdout @@ -317,18 +317,24 @@ def cli(opts, args): return 0 -def parse_kv_string(pairs): +def parse_kv_string(data, pairs): dict_ = {} for pair in pairs: k, v = pair.split("=", 1) - k = force_text(k) + k = force_text(k).split('.') v = force_text(v) - aux = dict() - for i in reversed(k.split('.')): - aux = {i: v} - v = aux - dict_.update(aux) - return dict_ + + last = None + current = data + for key in k: + last = current + current = current.get(key) + if current == None: + current = {} + last[key] = current + + last[k[-1]] = v + return data class LazyHelpOption(Option): From 589ec76f8c7c1fb1fad37861e1656cb4ea316c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Torres=20Cogollo?= Date: Fri, 25 Oct 2019 14:59:35 +0200 Subject: [PATCH 5/5] Fix little issues for Travis CI --- jinja2cli/cli.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index 7cb778e..d042c8e 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -300,7 +300,7 @@ def cli(opts, args): sys.stderr.write("ERROR: unknown section. Exiting.") return 1 - parse_kv_string(data, opts.D or []) + data_update_from_kv_string(data, opts.D or []) if opts.outfile is None: out = sys.stdout @@ -317,8 +317,7 @@ def cli(opts, args): return 0 -def parse_kv_string(data, pairs): - dict_ = {} +def data_update_from_kv_string(data, pairs): for pair in pairs: k, v = pair.split("=", 1) k = force_text(k).split('.') @@ -329,7 +328,7 @@ def parse_kv_string(data, pairs): for key in k: last = current current = current.get(key) - if current == None: + if current is None: current = {} last[key] = current