summaryrefslogtreecommitdiff
path: root/logincl/__init__.py
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-02 15:11:23 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-02 15:11:23 -0400
commit5ad696b2085a5e2dfa06727ae5184346dc994e63 (patch)
tree70988cf324fa08933dd3caf805e747d6635bf3d7 /logincl/__init__.py
downloadlogincl-5ad696b2085a5e2dfa06727ae5184346dc994e63.tar.gz
Initial commit
Diffstat (limited to 'logincl/__init__.py')
-rw-r--r--logincl/__init__.py39
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)
+