From e55e74bdbec1ac7b16913bd525c7b24958595f89 Mon Sep 17 00:00:00 2001 From: Robin Perkins Date: Sun, 13 Jan 2019 08:02:38 +0800 Subject: [PATCH] More Pythonic EAPF than LBYL style --- setup.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 687584f..c3d121f 100644 --- a/setup.py +++ b/setup.py @@ -9,24 +9,24 @@ def create_config(): config = configparser.ConfigParser() # get existing values if they exist fileName = os.path.join(local_dir, '.nemweb_config.ini') - if (os.path.isfile(fileName)) and (os.path.exists(fileName)): - print("found existing config file: %s" % fileName) + try: config.read_file(open(fileName)) - else: - print("failed to find existing config file: %s" % fileName) + print("found existing config file: %s" % fileName) + except (OSError, configparser.ParsingError): + print("failed to read existing config file: %s" % fileName) if not config.has_section('local_settings'): config.add_section('local_settings') print('added local_settings') - if config.has_option("local_settings","sqlite_dir"): + try: old_sqlite_db_dir = config.get("local_settings","sqlite_dir") - else: + except configparser.NoOptionError: old_sqlite_db_dir = os.path.expanduser("~/NEMData/") sqlite_db_dir = input("Enter sqlite directory (abs path)[" + old_sqlite_db_dir + "]:") sqlite_db_dir = sqlite_db_dir or old_sqlite_db_dir print("set sqlite_dir to %s" % sqlite_db_dir) - if config.has_option("local_settings","start_date"): + try: old_start_date = config.get("local_settings","start_date") - else: + except configparser.NoOptionError: old_start_date = "20090701" # oldest known NEM data date start_date = input("Enter start date to begin down loading from (YYYYMMDD):[" + old_start_date + "]:") start_date = start_date or old_start_date @@ -42,7 +42,7 @@ def run(self): try: create_config() except: - pass + print("failed to create config file") install.run(self) class PostDevelopCommand(develop):