From ccea7fe50abdb0ea07ebb21965fec9025eabdb80 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Sat, 16 Feb 2019 23:27:24 +0530 Subject: [PATCH] suricatactl: Make code compatible with Python 3 Call to suricatactl was failing with Python3 with the following error: ``` Traceback (most recent call last): File "bin/suricatactl", line 40, in sys.exit(main()) File "./suricata/ctl/main.py", line 50, in main args.func(args) AttributeError: 'Namespace' object has no attribute 'func' ``` Fix this by making it run with Py3 just like it does with Py2. Closes redmine ticket #2793 --- python/suricata/ctl/filestore.py | 1 - python/suricata/ctl/main.py | 7 +++++-- python/suricata/ctl/test_filestore.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/python/suricata/ctl/filestore.py b/python/suricata/ctl/filestore.py index f9f804d343..c0f101b36e 100644 --- a/python/suricata/ctl/filestore.py +++ b/python/suricata/ctl/filestore.py @@ -30,7 +30,6 @@ class InvalidAgeFormatError(Exception): pass def register_args(parser): - parsers = parser.add_subparsers() prune_parser = parsers.add_parser("prune") diff --git a/python/suricata/ctl/main.py b/python/suricata/ctl/main.py index 6a742adaf4..1d09b900e5 100644 --- a/python/suricata/ctl/main.py +++ b/python/suricata/ctl/main.py @@ -46,5 +46,8 @@ def main(): filestore.register_args(subparsers.add_parser("filestore")) args = parser.parse_args() - - args.func(args) + try: + func = args.func + except AttributeError: + parser.error("too few arguments") + func(args) diff --git a/python/suricata/ctl/test_filestore.py b/python/suricata/ctl/test_filestore.py index 26b107fd23..0cb0dd08a9 100644 --- a/python/suricata/ctl/test_filestore.py +++ b/python/suricata/ctl/test_filestore.py @@ -2,7 +2,7 @@ from __future__ import print_function import unittest -import filestore +from suricata.ctl import filestore class PruneTestCase(unittest.TestCase):