Skip to content

Commit

Permalink
Updated python bootstrap file to be leaner
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-parlette committed Apr 15, 2018
1 parent 517bbf2 commit 05da215
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions bootstrap/python
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/python

import argparse
import logging
import logging as log
import os
import yaml

global config

VERSION = "0"

def merge(x, y):
"""
Expand Down Expand Up @@ -34,38 +33,26 @@ if __name__ == "__main__":
parser.add_argument(
'-c', '--config', help='Specify a config file to use',
type=str, default='config.yaml')
parser.add_argument('--version', action='version', version='0')
parser.add_argument(
'-l', '--log-level', help='Log level, default is INFO',
default=log.INFO)
parser.add_argument('--version', action='version', version=VERSION)
args = parser.parse_args()

# Setup logging options
log_level = logging.DEBUG if args.debug else logging.INFO
log = logging.getLogger(os.path.basename(__file__))
log.setLevel(log_level)
formatter = logging.Formatter('%(asctime)s:%(name)s:%(levelname)s'
':%(funcName)s(%(lineno)i):%(message)s')

# Console Logging
ch = logging.StreamHandler()
ch.setLevel(log_level)
ch.setFormatter(formatter)
log.addHandler(ch)

# File Logging
fh = logging.FileHandler(os.path.basename(__file__) + '.log')
fh.setLevel(log_level)
fh.setFormatter(formatter)
log.addHandler(fh)
log_format = '%(asctime)s:%(name)s:%(levelname)s:%(funcName)s(%(lineno)i):%(message)s'
log.basicConfig(filename="{}.log".format(os.path.basename(__file__)),
level=args.log_level.upper(),
format=log_format)

log.info("Initializing...")

log.info("Loading configuration...")
# Load Config
global config
defaults = {
# "setting": "value",
}
if os.path.isfile(args.config):
log.debug("Loading config file %s" % args.config)
log.debug("Loading config file from {}".format(args.config))
config = yaml.load(file(args.config))
if config:
# config contains items
Expand All @@ -79,9 +66,9 @@ if __name__ == "__main__":
log.debug("Config file does not exist, creating a default config...")
config = defaults

log.debug("Config loaded as:\n%s, saving this to disk" % str(config))
log.debug("Config loaded as:\n{}, saving this to disk".format(str(config)))
with open(args.config, 'w') as outfile:
outfile.write(yaml.dump(config, default_flow_style=False))
log.debug("Config loaded as:\n%s" % str(config))
log.debug("Config loaded as:\n{}".format(str(config)))

log.info("Initialization complete")

0 comments on commit 05da215

Please sign in to comment.