| 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""" | 
|  | 35 | Execute whenever the program ends normally or with the signals that we | 
|  | 36 | catch (i.e. TERM, INT). | 
|  | 37 | """ | 
|  | 38 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 39 | # This function will be called by gen_exit_function().  If you have no | 
|  | 40 | # cleanup to do, you can delete this function altogether. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 41 |  | 
|  | 42 | # Your cleanup code here. | 
|  | 43 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 44 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 45 | def validate_parms(): | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 46 | r""" | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 47 | Validate program parameters, etc. | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 48 | """ | 
|  | 49 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 50 | # This function will be called by gen_setup().  If you have no validation | 
|  | 51 | # to do, you can delete this function altogether. | 
|  | 52 |  | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 53 | # Your validation code here... | 
|  | 54 | # valid_value(whatever) | 
| 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 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 57 | def main(): | 
|  | 58 |  | 
| Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 59 | gen_setup() | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 60 |  | 
|  | 61 | # Your code here. | 
|  | 62 |  | 
| Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 63 |  | 
| Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 64 | main() |