Last active
September 27, 2016 14:35
-
-
Save srgrn/061e144e70812a8ce10d to your computer and use it in GitHub Desktop.
simple runner script skeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ <replace with string description> """ | |
| import json | |
| import argparse | |
| import sys | |
| import logging | |
| CONFIG = None | |
| def setup(args): | |
| log_level = 'WARNING' | |
| if args.debug: | |
| import pdb | |
| log_level = 'DEBUG' | |
| log_format = '%(asctime)-15s - %(levelname)s - %(message)s' | |
| logging.basicConfig(format=log_format, level=log_level) | |
| logging.debug('Setup logging configuration') | |
| if args.config: | |
| logging.debug('loading config file') | |
| try: | |
| with open(args.config) as configfile: | |
| config = json.load(configfile) | |
| except IOError: | |
| logging.critical("Failed to load the file") | |
| sys.exit(1) | |
| except ValueError: | |
| logging.critical("Failed to read the config file probably not proper json") | |
| sys.exit(1) | |
| except Exception, e: | |
| raise e | |
| return config | |
| else: | |
| logging.debug('no config file specified') | |
| return None | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('-c', '--config', help='configuration file to load', default='config.json') | |
| parser.add_argument('-D', '--debug', help='enable debug mode', action='store_true') | |
| args = parser.parse_args() | |
| global CONFIG | |
| CONFIG = setup(args) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment