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 | ee24ff5 | 2019-12-13 14:42:59 -0600 | [diff] [blame] | 32 | def exit_function(): |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 33 | r""" |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 34 | 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] | 35 | """ |
| 36 | |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 37 | # This function will be called by gen_exit_function(). If you have no cleanup to do, you can delete |
| 38 | # this function altogether. |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 39 | |
| 40 | # Your cleanup code here. |
| 41 | |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 42 | |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 43 | def validate_parms(): |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 44 | r""" |
Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 45 | Validate program parameters, etc. |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 46 | """ |
| 47 | |
Michael Walsh | 410b178 | 2019-10-22 15:56:18 -0500 | [diff] [blame] | 48 | # This function will be called by gen_setup(). If you have no validation to do, you can delete this |
| 49 | # function altogether. |
Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 50 | |
Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 51 | # Your validation code here... |
| 52 | # valid_value(whatever) |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 53 | |
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 | def main(): |
| 56 | |
Michael Walsh | 6607a28 | 2019-09-13 14:21:01 -0500 | [diff] [blame] | 57 | gen_setup() |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 58 | |
| 59 | # Your code here. |
| 60 | |
Michael Walsh | 4cae87d | 2017-01-12 14:46:05 -0600 | [diff] [blame] | 61 | |
Michael Walsh | 2d8d7f3 | 2018-06-01 15:21:09 -0500 | [diff] [blame] | 62 | main() |