From 4ee3799773c301900eba82e0a9d838eee28af6fd Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Fri, 8 Apr 2016 11:38:46 +0100 Subject: [PATCH] [config] softfail when config cannot be written --- setup.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index e1c5e23d..17205504 100644 --- a/setup.py +++ b/setup.py @@ -176,23 +176,26 @@ home = os.getenv('HOME') or os.getenv('USERPROFILE') user_file = os.path.join(home,'.config', 'GPy', 'user.cfg') print("") -if not os.path.exists(user_file): - # Does an old config exist? - old_user_file = os.path.join(home,'.gpy_user.cfg') - if os.path.exists(old_user_file): - # Move it to new location: - print("GPy: Found old config file, moving to new location {}".format(user_file)) - if not os.path.exists(os.path.dirname(user_file)): - os.makedirs(os.path.dirname(user_file)) - os.rename(old_user_file, user_file) +try: + if not os.path.exists(user_file): + # Does an old config exist? + old_user_file = os.path.join(home,'.gpy_user.cfg') + if os.path.exists(old_user_file): + # Move it to new location: + print("GPy: Found old config file, moving to new location {}".format(user_file)) + if not os.path.exists(os.path.dirname(user_file)): + os.makedirs(os.path.dirname(user_file)) + os.rename(old_user_file, user_file) + else: + # No config file exists, save informative stub to user config folder: + print("GPy: Saving user configuration file to {}".format(user_file)) + if not os.path.exists(os.path.dirname(user_file)): + os.makedirs(os.path.dirname(user_file)) + with open(user_file, 'w') as f: + with open(local_file, 'r') as l: + tmp = l.read() + f.write(tmp) else: - # No config file exists, save informative stub to user config folder: - print("GPy: Saving user configuration file to {}".format(user_file)) - if not os.path.exists(os.path.dirname(user_file)): - os.makedirs(os.path.dirname(user_file)) - with open(user_file, 'w') as f: - with open(local_file, 'r') as l: - tmp = l.read() - f.write(tmp) -else: - print("GPy: User configuration file at location {}".format(user_file)) + print("GPy: User configuration file at location {}".format(user_file)) +except: + print("GPy: Could not write user configuration file {}".format(user_file)) \ No newline at end of file