From fa5480e8bccec39278e9c5f81c09d1e702fd0fd7 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Sun, 24 Nov 2013 20:23:39 +0100
Subject: modtool: no more exit() in modtool package

Conflicts:
	gr-utils/python/modtool/modtool_newmod.py
---
 gr-utils/python/modtool/modtool_base.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

(limited to 'gr-utils/python/modtool/modtool_base.py')

diff --git a/gr-utils/python/modtool/modtool_base.py b/gr-utils/python/modtool/modtool_base.py
index 86cbd8f420..768bce0f77 100644
--- a/gr-utils/python/modtool/modtool_base.py
+++ b/gr-utils/python/modtool/modtool_base.py
@@ -22,11 +22,14 @@
 
 import os
 import re
-import sys
 from optparse import OptionParser, OptionGroup
 
 from util_functions import get_modname
-from templates import Templates
+
+
+class ModToolException(BaseException):
+    """ Standard exception for modtool classes. """
+    pass
 
 
 class ModTool(object):
@@ -41,8 +44,6 @@ class ModTool(object):
             self._has_subdirs[subdir] = False
             self._skip_subdirs[subdir] = False
         self.parser = self.setup_parser()
-        self.args = None
-        self.options = None
         self._dir = None
 
     def setup_parser(self):
@@ -72,20 +73,17 @@ class ModTool(object):
         parser.add_option_group(ogroup)
         return parser
 
-    def setup(self):
+    def setup(self, options, args):
         """ Initialise all internal variables, such as the module name etc. """
-        (options, self.args) = self.parser.parse_args()
         self._dir = options.directory
         if not self._check_directory(self._dir):
-            print "No GNU Radio module found in the given directory. Quitting."
-            sys.exit(1)
+            raise ModToolException('No GNU Radio module found in the given directory.')
         if options.module_name is not None:
             self._info['modname'] = options.module_name
         else:
             self._info['modname'] = get_modname()
         if self._info['modname'] is None:
-            print "No GNU Radio module found in the given directory. Quitting."
-            sys.exit(1)
+            raise ModToolException('No GNU Radio module found in the given directory.')
         print "GNU Radio module name identified: " + self._info['modname']
         if self._info['version'] == '36' and (
                 os.path.isdir(os.path.join('include', self._info['modname'])) or
@@ -101,7 +99,6 @@ class ModTool(object):
         if options.skip_grc or not self._has_subdirs['grc']:
             self._skip_subdirs['grc'] = True
         self._info['blockname'] = options.block_name
-        self.options = options
         self._setup_files()
         self._info['yes'] = options.yes
 
@@ -171,6 +168,7 @@ class ModTool(object):
         """ Override this. """
         pass
 
+
 def get_class_dict(the_globals):
     " Return a dictionary of the available commands in the form command->class "
     classdict = {}
-- 
cgit v1.2.3