diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-03 14:06:07 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-03 14:06:07 -0400 |
commit | 406df0cdab322d077151d2a9d449c8b4f799180d (patch) | |
tree | a6350cc1be5baa2ebe2d6f5b20bf9e3908a6b0ef | |
parent | 5ad696b2085a5e2dfa06727ae5184346dc994e63 (diff) | |
download | logincl-406df0cdab322d077151d2a9d449c8b4f799180d.tar.gz |
-rw-r--r-- | logincl/__init__.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/logincl/__init__.py b/logincl/__init__.py index ff7e179..8226c52 100644 --- a/logincl/__init__.py +++ b/logincl/__init__.py @@ -2,19 +2,29 @@ import os import atexit -DEFAULT_CLFILE = os.path.join(os.environ['HOME'], 'login.cl') +DEFAULT_CLFILE = os.path.join(os.environ['HOME'], 'iraf', 'login.cl') if 'LOGINCL' in os.environ: CLFILE = os.environ['LOGINCL'] else: CLFILE = DEFAULT_CLFILE +class LoginCLError(Exception): + pass class LoginCL(object): def __init__(self, filename): self.filename = os.path.abspath(filename) + + if not os.path.exists(self.filename): + raise LoginCLError('{0} does not exist.'.format(self.filename)) + + if not os.path.isfile(self.filename): + raise LoginCLError('{0} is not a file.'.format(self.filename)) + self.curdir = os.path.abspath(os.curdir) self.destination = os.path.join(self.curdir, os.path.basename(self.filename)) + if self.exists(): if not self.rmlink(): return @@ -33,7 +43,8 @@ class LoginCL(object): os.remove(self.destination) return True - -lcl = LoginCL(CLFILE) -atexit.register(lcl.rmlink) - +try: + lcl = LoginCL(CLFILE) + atexit.register(lcl.rmlink) +except LoginCLError: + pass |