diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-02 15:11:23 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-02 15:11:23 -0400 |
commit | 5ad696b2085a5e2dfa06727ae5184346dc994e63 (patch) | |
tree | 70988cf324fa08933dd3caf805e747d6635bf3d7 /logincl/__init__.py | |
download | logincl-5ad696b2085a5e2dfa06727ae5184346dc994e63.tar.gz |
Initial commit
Diffstat (limited to 'logincl/__init__.py')
-rw-r--r-- | logincl/__init__.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/logincl/__init__.py b/logincl/__init__.py new file mode 100644 index 0000000..ff7e179 --- /dev/null +++ b/logincl/__init__.py @@ -0,0 +1,39 @@ +import os +import atexit + + +DEFAULT_CLFILE = os.path.join(os.environ['HOME'], 'login.cl') + +if 'LOGINCL' in os.environ: + CLFILE = os.environ['LOGINCL'] +else: + CLFILE = DEFAULT_CLFILE + + +class LoginCL(object): + def __init__(self, filename): + self.filename = os.path.abspath(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 + self.mklink() + + def exists(self): + return os.path.exists(self.destination) + + def mklink(self): + os.symlink(self.filename, self.destination) + + def rmlink(self): + if not os.path.islink(self.destination): + return False + + os.remove(self.destination) + return True + + +lcl = LoginCL(CLFILE) +atexit.register(lcl.rmlink) + |