bash_simple_template as model for bash programs.

Also, moved python_pgm_templates to new templates subdir.

Note: It should be the very rare case when we choose to code in bash.

Change-Id: I81813b8b3ecdd86a54bf8525fa8d4adb34a51bff
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/templates/bash_simple_template b/templates/bash_simple_template
new file mode 100755
index 0000000..85f992c
--- /dev/null
+++ b/templates/bash_simple_template
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# Template to start a simple bash program.  This is designed only for the
+# simplest of programs where all program paramters are positional, there is no
+# help text, etc.
+
+# Description of argument(s):
+# parm1            Bla, bla, bla (e.g. "example data").
+
+
+###############################################################################
+function get_parms {
+
+  # Get program parms.
+
+  parm1="${1}" ; shift
+
+  return 0
+
+}
+###############################################################################
+
+
+###############################################################################
+function validate_parms {
+
+  # Validate program parameters.
+
+  # Your validation code here.
+
+  if [ -z "${parm1}" ] ; then
+    echo "**ERROR** You must provide..." >&2
+    return 1
+  fi
+
+  return 0
+
+}
+###############################################################################
+
+
+###############################################################################
+function mainf {
+
+  # We create a mainf for a couple of reasons:
+  # The coding rules in a template are slightly different than for the true
+  # mainline.  We wish to eliminate those inconsistencies.  Examples:
+  # - The "local" builtin is allowed in functions but not in the mainline.
+  # - It is good practice to have functions return 1 rather than exit 1.
+  #   return is not valid in the mainline.  Again, we don't want to have to
+  #   care when we code things about whether we are in the mainline or a
+  #   function.
+
+  get_parms "$@" || return 1
+
+  validate_parms || return 1
+
+  # Your code here...
+
+  return 0
+
+}
+###############################################################################
+
+
+###############################################################################
+# Main
+
+  mainf "${@}"
+  rc="${?}"
+  exit "${rc}"
+
+###############################################################################
diff --git a/templates/python_pgm_template b/templates/python_pgm_template
new file mode 100644
index 0000000..fe32f67
--- /dev/null
+++ b/templates/python_pgm_template
@@ -0,0 +1,141 @@
+#!/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).
+"""
+
+import sys
+
+# python puts the program's directory path in sys.path[0].  In other words,
+# the user ordinarily has no way to override python's choice of a module from
+# its own dir.  We want to have that ability in our environment.  However, we
+# don't want to break any established python modules that depend on this
+# behavior.  So, we'll save the value from sys.path[0], delete it, import our
+# modules and then restore sys.path to its original value.
+
+save_path_0 = sys.path[0]
+del sys.path[0]
+
+from gen_arg import *
+from gen_print import *
+from gen_valid import *
+
+# Restore sys.path[0].
+sys.path.insert(0, save_path_0)
+
+###############################################################################
+# Create parser object to process command line parameters and args.
+
+# Create parser object.
+parser = argparse.ArgumentParser(
+    usage='%(prog)s [OPTIONS]',
+    description="%(prog)s will...",
+    formatter_class=argparse.RawTextHelpFormatter,
+    prefix_chars='-+')
+
+# Create arguments.
+parser.add_argument(
+    '--whatever',
+    help='bla, bla.')
+
+# The stock_list will be passed to gen_get_options.  We populate it with the
+# names of stock parm options we want.  These stock parms are pre-defined by
+# gen_get_options.
+stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)]
+###############################################################################
+
+
+###############################################################################
+def exit_function(signal_number=0,
+                  frame=None):
+
+    r"""
+    Execute whenever the program ends normally or with the signals that we
+    catch (i.e. TERM, INT).
+    """
+
+    dprint_executing()
+    dprint_var(signal_number)
+
+    # 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.  Return True or False (i.e. pass/fail)
+    accordingly.
+    """
+
+    # Your validation code here.
+
+    gen_post_validation(exit_function, signal_handler)
+
+    return True
+
+###############################################################################
+
+
+###############################################################################
+def main():
+
+    r"""
+    This is the "main" function.  The advantage of having this function vs
+    just doing this in the true mainline is that you can:
+    - Declare local variables
+    - Use "return" instead of "exit".
+    - Indent 4 chars like you would in any function.
+    This makes coding more consistent, i.e. it's easy to move code from here
+    into a function and vice versa.
+    """
+
+    if not gen_get_options(parser, stock_list):
+        return False
+
+    if not validate_parms():
+        return False
+
+    qprint_pgm_header()
+
+    # Your code here.
+
+    return True
+
+###############################################################################
+
+
+###############################################################################
+# Main
+
+if not main():
+    exit(1)
+
+###############################################################################