From 22c06a48e12117d2a2d2c133755b21a1b1fdbc65 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Tue, 30 Apr 2019 12:53:59 +0200 Subject: [PATCH] protect main --- location/__main__.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/location/__main__.py b/location/__main__.py index a6aef4a..6c5a481 100644 --- a/location/__main__.py +++ b/location/__main__.py @@ -5,20 +5,24 @@ from location import get_logger, get_locations, iter_locations, get_groups from kython.klogging import setup_logzero -logger = get_logger() -setup_logzero(logger, level=logging.INFO) +def main(): + logger = get_logger() + setup_logzero(logger, level=logging.INFO) -if len(sys.argv) > 1: - cmd = sys.argv[1] - if cmd == "update_cache": - from location import update_cache, get_locations - update_cache() - get_locations(cached=True) + if len(sys.argv) > 1: + cmd = sys.argv[1] + if cmd == "update_cache": + from location import update_cache, get_locations + update_cache() + get_locations(cached=True) + else: + raise RuntimeError(f"Unknown command {cmd}") else: - raise RuntimeError(f"Unknown command {cmd}") -else: - for p in get_groups(cached=True): - print(p) - # TODO need datetime! + for p in get_groups(cached=True): + print(p) + # TODO need datetime! + +if __name__ == '__main__': + main()