Improved py template
- General streamlining
- exit_function: New comments to indicate that this function is
optional
- signal_handler: Removed this function. This is now handled by
gen_args' gen_signal_handler.
- validate_parms: New comments to indicate that this function is
optional
- Replaced old calls with a single call to gen_setup().
Change-Id: I8b19ea4242429330ec8a989269ea1fa5043bed26
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/templates/python_pgm_template b/templates/python_pgm_template
index 260a207..11db412 100644
--- a/templates/python_pgm_template
+++ b/templates/python_pgm_template
@@ -1,25 +1,18 @@
#!/usr/bin/env python
r"""
-python_pgm_template: Copy this template as a base to get a start on a python
-program. You may remove any generic comments (like this one).
See help text for details.
"""
import sys
-save_path_0 = sys.path[0]
-del sys.path[0]
+save_dir_path = sys.path.pop(0)
-from gen_arg import *
-from gen_print import *
-from gen_valid import *
+modules = ['gen_arg', 'gen_print', 'gen_valid']
+for module in modules:
+ exec("from " + module + " import *")
-# Restore sys.path[0].
-sys.path.insert(0, save_path_0)
-
-# Set exit_on_error for gen_valid functions.
-set_exit_on_error(True)
+sys.path.insert(0, save_dir_path)
parser = argparse.ArgumentParser(
usage='%(prog)s [OPTIONS]',
@@ -43,50 +36,27 @@
catch (i.e. TERM, INT).
"""
- dprint_executing()
- dprint_var(signal_number)
+ # This function will be called by gen_exit_function(). If you have no
+ # cleanup to do, you can delete this function altogether.
# Your cleanup code here.
- qprint_pgm_footer()
-
-
-def signal_handler(signal_number,
- frame):
- r"""
- Handle signals. Without a function to catch a SIGTERM or SIGINT, our
- program would terminate immediately with return code 143 and without
- calling our exit_function.
- """
-
- # Our convention is to set up exit_function with atexit.register() so
- # there is no need to explicitly call exit_function from here.
-
- dprint_executing()
-
- # Calling exit prevents us from returning to the code that was running
- # when we received the signal.
- exit(0)
-
def validate_parms():
r"""
Validate program parameters, etc.
"""
+ # This function will be called by gen_setup(). If you have no validation
+ # to do, you can delete this function altogether.
+
# Your validation code here...
# valid_value(whatever)
- gen_post_validation(exit_function, signal_handler)
-
def main():
- gen_get_options(parser, stock_list)
-
- validate_parms()
-
- qprint_pgm_header()
+ gen_setup()
# Your code here.