def test_simple_non_lists(self): class toto: pass non_lists = [1, 2, "hello", 0.42, toto(), u"nicode"] for l in non_lists: self.assertEqual(is_list(l), False)
def _sanitize_output(output): if is_iterable(output): output = list(output) if not is_list(output): output = [output] output = list(filter(None, output)) return output
def full_scan(facts): external_id = generate_uuid().hex if not is_list(facts): facts = [facts] fact_cls = facts_services.facts_from_json(facts) tasks = [] for f in fact_cls: available_collectors = DataWriter().collectors.find_by_allowed_input( f.plugin_name ) for ac in available_collectors: tasks.append( (remote_ctrl.launch(ac, f) | scan_ctrl.add_result(external_id)) ) tasks_group = group(tasks) workflow = ( scan_ctrl.start(external_id, fact_cls, "Full scan") | tasks_group | scan_ctrl.stop(external_id) ) workflow.apply_async() return external_id
def _sanitize_output(output): if is_iterable(output): output = list(output) if not is_list(output): output = [output] output = list(filter(None, output)) print("Got: {} output facts".format(len(output))) return [out for out in output if isinstance(out, BaseFact) and out.is_valid()]
def launch(self, fact): if not self._script_arguments_: raise PluginFormatError("Incorrect script_arguments") if not is_list(fact): fact = [fact] args = self._find_and_replace_sigil(fact) stdout = self._exec(self.script_path, *args) return self.parse_result(stdout)
def _find_and_replace_sigil(self, facts): args = self.script_arguments res = [] if not is_list(args): args = [args] for arg in args: replaced = self._replace_sigil(arg, facts) if replaced is not None: res.append(replaced) return res
def allowed_input(self): return (self._allowed_input_ if is_list(self._allowed_input_) else [self._allowed_input_])
def launch(self, fact): if not is_list(fact): fact = [fact] args = self._find_and_replace_sigil(fact) stdout = self._exec(self.script_path, *args, ignore_error=True) return self.parse_result(stdout)
def test_simple_list(self): lists = [(1, 2, 3), [4, 5, 6], {7, 8, 9}] for l in lists: self.assertEqual(is_list(l), True)