add exceptions

This commit is contained in:
ivan 2018-11-28 20:46:18 +03:00
parent 0fd4ff9b74
commit ed10aa8f03
2 changed files with 28 additions and 6 deletions

View File

@ -13,7 +13,7 @@ def main():
long_description='SSH connection and aliases manager with curses and command line interface', long_description='SSH connection and aliases manager with curses and command line interface',
long_description_content_type='text/x-rst', long_description_content_type='text/x-rst',
license='DWTWL 2.55', license='DWTWL 2.55',
version='1.04', version='1.05',
py_modules=['sshch'], py_modules=['sshch'],
scripts=['sshch/sshch'], scripts=['sshch/sshch'],
keywords='sshch ssh aliases curses manager', keywords='sshch ssh aliases curses manager',

View File

@ -20,7 +20,7 @@ import curses
from curses import textpad, panel from curses import textpad, panel
# https://gitlab.com/zlax/sshch # https://gitlab.com/zlax/sshch
version = "1.04" version = "1.05"
# expand groups by default # expand groups by default
expand_default = True expand_default = True
# path to conf dir and file, default: ~/.config/sshch.conf # path to conf dir and file, default: ~/.config/sshch.conf
@ -808,13 +808,28 @@ if __name__ == "__main__":
pass pass
if not path.exists(conf_dir): if not path.exists(conf_dir):
try:
from os import makedirs from os import makedirs
makedirs(conf_dir) makedirs(conf_dir)
except:
print("Can't make dir " + conf_dir)
exit()
conf = configparser.RawConfigParser() conf = configparser.RawConfigParser()
if not path.exists(conf_file): if not path.exists(conf_file):
try:
open(conf_file, 'w') open(conf_file, 'w')
except:
print("Can't make file at " + conf_dir)
exit()
try:
conf.read(conf_file) conf.read(conf_file)
except:
print("Error: can't read config file " + conf_file)
exit()
if len(argv) > 1: if len(argv) > 1:
try: try:
CMDOptions() CMDOptions()
@ -823,6 +838,10 @@ if __name__ == "__main__":
except configparser.Error: except configparser.Error:
print("Error: can't parse your config file, please check it manually or make new one") print("Error: can't parse your config file, please check it manually or make new one")
exit() exit()
except IOError:
print("Error: can't use your config file, please check permissionss of " + conf_file)
exit()
else: else:
try: try:
CursesMain() CursesMain()
@ -834,3 +853,6 @@ if __name__ == "__main__":
except curses.error: except curses.error:
CursesExit("".join(["Error: can't show some curses element, maybe ", CursesExit("".join(["Error: can't show some curses element, maybe ",
"your terminal is too small"])) "your terminal is too small"]))
except IOError:
CursesExit("".join(["Error: can't use your config file, please ",
"check permissionss of ", conf_file]))