| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python | 
 | 2 |  | 
 | 3 | r""" | 
| Michael Walsh | e5391dc | 2019-07-22 17:18:30 -0500 | [diff] [blame] | 4 | See help text for details. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 5 | """ | 
 | 6 |  | 
 | 7 | import sys | 
 | 8 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 9 | save_dir_path = sys.path.pop(0) | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 10 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 11 | modules = ['gen_arg', 'gen_print', 'gen_valid'] | 
 | 12 | for module in modules: | 
 | 13 |     exec("from " + module + " import *") | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 14 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 15 | sys.path.insert(0, save_dir_path) | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 16 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 17 | parser = argparse.ArgumentParser( | 
 | 18 |     usage='%(prog)s [OPTIONS]', | 
 | 19 |     description="%(prog)s will...", | 
| Michael Walsh | d0741f8 | 2017-12-21 14:04:21 -0600 | [diff] [blame] | 20 |     formatter_class=argparse.ArgumentDefaultsHelpFormatter, | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 21 |     prefix_chars='-+') | 
 | 22 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 23 | parser.add_argument( | 
 | 24 |     '--whatever', | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 25 |     default='', | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 26 |     help='bla, bla.') | 
 | 27 |  | 
| Michael Walsh | 41dda1b | 2017-09-14 11:42:29 -0500 | [diff] [blame] | 28 | # Populate stock_list with options we want. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 29 | stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)] | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 30 |  | 
 | 31 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 32 | def exit_function(signal_number=0, | 
 | 33 |                   frame=None): | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 34 |     r""" | 
| Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 35 |     Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT). | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 36 |     """ | 
 | 37 |  | 
| Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 38 |     # This function will be called by gen_exit_function().  If you have no cleanup to do, you can delete | 
 | 39 |     # this function altogether. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 40 |  | 
 | 41 |     # Your cleanup code here. | 
 | 42 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 43 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 44 | def validate_parms(): | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 45 |     r""" | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 46 |     Validate program parameters, etc. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 47 |     """ | 
 | 48 |  | 
| Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 49 |     # This function will be called by gen_setup().  If you have no validation to do, you can delete this | 
 | 50 |     # function altogether. | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 51 |  | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 52 |     # Your validation code here... | 
 | 53 |     # valid_value(whatever) | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 54 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 55 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 56 | def main(): | 
 | 57 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 58 |     gen_setup() | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 59 |  | 
 | 60 |     # Your code here. | 
 | 61 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 62 |  | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 63 | main() |