From ed10aa8f0311d2dee632c870ac332e33884c810e Mon Sep 17 00:00:00 2001 From: zlaxy Date: Wed, 28 Nov 2018 20:46:18 +0300 Subject: [PATCH] add exceptions --- setup.py | 2 +- sshch/sshch | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 1a479cd..df22e9a 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def main(): long_description='SSH connection and aliases manager with curses and command line interface', long_description_content_type='text/x-rst', license='DWTWL 2.55', - version='1.04', + version='1.05', py_modules=['sshch'], scripts=['sshch/sshch'], keywords='sshch ssh aliases curses manager', diff --git a/sshch/sshch b/sshch/sshch index 2120471..1992a49 100755 --- a/sshch/sshch +++ b/sshch/sshch @@ -20,7 +20,7 @@ import curses from curses import textpad, panel # https://gitlab.com/zlax/sshch -version = "1.04" +version = "1.05" # expand groups by default expand_default = True # path to conf dir and file, default: ~/.config/sshch.conf @@ -808,13 +808,28 @@ if __name__ == "__main__": pass if not path.exists(conf_dir): - from os import makedirs - makedirs(conf_dir) + try: + from os import makedirs + makedirs(conf_dir) + except: + print("Can't make dir " + conf_dir) + exit() conf = configparser.RawConfigParser() + if not path.exists(conf_file): - open(conf_file, 'w') - conf.read(conf_file) + try: + open(conf_file, 'w') + except: + print("Can't make file at " + conf_dir) + exit() + + try: + conf.read(conf_file) + except: + print("Error: can't read config file " + conf_file) + exit() + if len(argv) > 1: try: CMDOptions() @@ -823,6 +838,10 @@ if __name__ == "__main__": except configparser.Error: print("Error: can't parse your config file, please check it manually or make new one") exit() + except IOError: + print("Error: can't use your config file, please check permissionss of " + conf_file) + exit() + else: try: CursesMain() @@ -834,3 +853,6 @@ if __name__ == "__main__": except curses.error: CursesExit("".join(["Error: can't show some curses element, maybe ", "your terminal is too small"])) + except IOError: + CursesExit("".join(["Error: can't use your config file, please ", + "check permissionss of ", conf_file]))