From 3407994e00ddf74fef5f10bbaae1fd1f488a1b51 Mon Sep 17 00:00:00 2001 From: Ben Rudolph Date: Fri, 23 Mar 2018 17:37:11 -0700 Subject: [PATCH 1/3] extract run function --- bonobo/contrib/django/commands.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bonobo/contrib/django/commands.py b/bonobo/contrib/django/commands.py index eda6141..b54edd8 100644 --- a/bonobo/contrib/django/commands.py +++ b/bonobo/contrib/django/commands.py @@ -44,13 +44,7 @@ class ETLCommand(BaseCommand): def info(self, *args, **kwargs): self.logger.info(*args, **kwargs) - def handle(self, *args, **options): - _stdout_backup, _stderr_backup = self.stdout, self.stderr - - self.stdout = OutputWrapper(ConsoleOutputPlugin._stdout, ending=CLEAR_EOL + '\n') - self.stderr = OutputWrapper(ConsoleOutputPlugin._stderr, ending=CLEAR_EOL + '\n') - self.stderr.style_func = lambda x: Fore.LIGHTRED_EX + Back.RED + '!' + Style.RESET_ALL + ' ' + x - + def run(self, *args, **options): with bonobo.parse_args(options) as options: services = self.get_services() graph_coll = self.get_graph(*args, **options) @@ -65,4 +59,13 @@ class ETLCommand(BaseCommand): print(term.lightblack(' ... return value: ' + str(result))) print() + def handle(self, *args, **options): + _stdout_backup, _stderr_backup = self.stdout, self.stderr + + self.stdout = OutputWrapper(ConsoleOutputPlugin._stdout, ending=CLEAR_EOL + '\n') + self.stderr = OutputWrapper(ConsoleOutputPlugin._stderr, ending=CLEAR_EOL + '\n') + self.stderr.style_func = lambda x: Fore.LIGHTRED_EX + Back.RED + '!' + Style.RESET_ALL + ' ' + x + + self.run(*args, **kwargs) + self.stdout, self.stderr = _stdout_backup, _stderr_backup From d5b3c2e3033142753a4fce841789beb70e006b56 Mon Sep 17 00:00:00 2001 From: Ben Rudolph Date: Fri, 23 Mar 2018 17:43:50 -0700 Subject: [PATCH 2/3] store results --- bonobo/contrib/django/commands.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bonobo/contrib/django/commands.py b/bonobo/contrib/django/commands.py index b54edd8..4edcd09 100644 --- a/bonobo/contrib/django/commands.py +++ b/bonobo/contrib/django/commands.py @@ -45,6 +45,7 @@ class ETLCommand(BaseCommand): self.logger.info(*args, **kwargs) def run(self, *args, **options): + results = [] with bonobo.parse_args(options) as options: services = self.get_services() graph_coll = self.get_graph(*args, **options) @@ -56,9 +57,12 @@ class ETLCommand(BaseCommand): assert isinstance(graph, bonobo.Graph), 'Invalid graph provided.' print(term.lightwhite('{}. {}'.format(i + 1, graph.name))) result = bonobo.run(graph, services=services) + results.append(result) print(term.lightblack(' ... return value: ' + str(result))) print() + return results + def handle(self, *args, **options): _stdout_backup, _stderr_backup = self.stdout, self.stderr From 5cab4effeac1c1fe7b7f8dce5c93ae9ba608f63b Mon Sep 17 00:00:00 2001 From: Ben Rudolph Date: Fri, 23 Mar 2018 17:45:47 -0700 Subject: [PATCH 3/3] allow for overriding strategy --- bonobo/contrib/django/commands.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bonobo/contrib/django/commands.py b/bonobo/contrib/django/commands.py index 4edcd09..ac5f387 100644 --- a/bonobo/contrib/django/commands.py +++ b/bonobo/contrib/django/commands.py @@ -41,6 +41,9 @@ class ETLCommand(BaseCommand): def get_services(self): return {} + def get_strategy(self): + return None + def info(self, *args, **kwargs): self.logger.info(*args, **kwargs) @@ -48,6 +51,7 @@ class ETLCommand(BaseCommand): results = [] with bonobo.parse_args(options) as options: services = self.get_services() + strategy = self.get_strategy() graph_coll = self.get_graph(*args, **options) if not isinstance(graph_coll, GeneratorType): @@ -56,7 +60,7 @@ class ETLCommand(BaseCommand): for i, graph in enumerate(graph_coll): assert isinstance(graph, bonobo.Graph), 'Invalid graph provided.' print(term.lightwhite('{}. {}'.format(i + 1, graph.name))) - result = bonobo.run(graph, services=services) + result = bonobo.run(graph, services=services, strategy=strategy) results.append(result) print(term.lightblack(' ... return value: ' + str(result))) print()