aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-03-17 00:28:13 +0200
committerJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-03-17 23:02:34 +0200
commitddbf8a86cf4ef071f289aceda1035818948d2292 (patch)
tree9f8bb8abb8d30139d261ba2bf0146838b915b235
parent8665af9d1eb0a5d343f9f1f6fe2c4c185c1aced3 (diff)
Add package utils
-rw-r--r--PKGBUILD35
-rw-r--r--src/python-sshmgr-0.1/setup.py12
-rw-r--r--src/python-sshmgr-0.1/src/getch.py38
-rwxr-xr-xsrc/python-sshmgr-0.1/src/sshmgr83
4 files changed, 168 insertions, 0 deletions
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 0000000..2378c00
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,35 @@
+# This is an example PKGBUILD file. Use this as a start to creating your own,
+# and remove these comments. For more information, see 'man PKGBUILD'.
+# NOTE: Please fill out the license field for your package! If it is unknown,
+# then please put 'unknown'.
+
+# See http://wiki.archlinux.org/index.php/Python_Package_Guidelines for more
+# information on Python packaging.
+
+# Maintainer: Your Name <jan-sebastian.tuomi@aalto.fi>
+pkgname=python-sshmgr
+pkgver=0.1
+pkgrel=1
+pkgdesc="Minimal ssh connection manager"
+arch=('x86_64' 'i386')
+url=""
+license=('GPL')
+groups=()
+depends=('python' 'screen')
+makedepends=()
+provides=()
+conflicts=()
+replaces=()
+backup=()
+options=(!emptydirs)
+install=
+source=()
+md5sums=()
+
+package() {
+ cd "$srcdir/$pkgname-$pkgver"
+ python setup.py install --root="$pkgdir/" --optimize=1
+}
+
+# vim:set ts=2 sw=2 et:
+
diff --git a/src/python-sshmgr-0.1/setup.py b/src/python-sshmgr-0.1/setup.py
new file mode 100644
index 0000000..929b2fb
--- /dev/null
+++ b/src/python-sshmgr-0.1/setup.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+
+setup(name='sshmgr',
+ version='0.1',
+ description='',
+ author='Jan Tuomi',
+ author_email='jan-sebastian.tuomi@aalto.fi',
+ url='',
+ packages=['src'],
+ )
diff --git a/src/python-sshmgr-0.1/src/getch.py b/src/python-sshmgr-0.1/src/getch.py
new file mode 100644
index 0000000..be6203f
--- /dev/null
+++ b/src/python-sshmgr-0.1/src/getch.py
@@ -0,0 +1,38 @@
+class _Getch:
+ """Gets a single character from standard input. Does not echo to the
+screen."""
+ def __init__(self):
+ try:
+ self.impl = _GetchWindows()
+ except ImportError:
+ self.impl = _GetchUnix()
+
+ def __call__(self): return self.impl()
+
+
+class _GetchUnix:
+ def __init__(self):
+ import tty, sys
+
+ def __call__(self):
+ import sys, tty, termios
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ try:
+ tty.setraw(sys.stdin.fileno())
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ return ch
+
+
+class _GetchWindows:
+ def __init__(self):
+ import msvcrt
+
+ def __call__(self):
+ import msvcrt
+ return msvcrt.getch()
+
+
+getch = _Getch()
diff --git a/src/python-sshmgr-0.1/src/sshmgr b/src/python-sshmgr-0.1/src/sshmgr
new file mode 100755
index 0000000..497df06
--- /dev/null
+++ b/src/python-sshmgr-0.1/src/sshmgr
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+from getch import *
+from os import system
+
+CONN_DB_PATH = "sshmgr-db"
+
+def load_conns():
+ conns = []
+ with open(CONN_DB_PATH) as f:
+ conns = [l.strip() for l in f.readlines()]
+ return conns
+
+def create_new(conns):
+ name = input("Name the new connection: ")
+ conns.append(name)
+
+ save_conns(conns)
+
+def save_conns(conns):
+ with open(CONN_DB_PATH, 'w') as f:
+ for conn in conns:
+ f.write("{:s}\n".format(conn))
+
+def get_connection(conns, c):
+ try:
+ num = int(c)
+ except ValueError:
+ print("Selection needs to be a number!")
+ return False
+
+ if num < 1 or num > len(conns):
+ print("Selection not in range!")
+ return False
+
+ selection = conns[num - 1]
+ return selection
+
+def connect(connection):
+ system("screen ssh {}".format(connection))
+
+def delete_conn(conns):
+ c = input("Which connection should be removed? ")
+ deleted = get_connection(conns, c)
+ if not deleted:
+ print("Nothing was deleted.")
+ getch()
+ return
+
+ conns = [conn for conn in conns if conn != deleted]
+ save_conns(conns)
+
+def main():
+ running = True
+ while running:
+ conns = load_conns()
+ system("clear")
+
+ print("Select connection: ")
+ for i,conn in enumerate(conns):
+ print("({:d}) {:s}".format(i + 1, conn))
+ print("(n) New connection")
+ print("(d) Delete connection")
+ print("(q) Quit")
+
+ c = getch()
+
+ if (c == "q"):
+ return
+ elif (c == "d"):
+ delete_conn(conns)
+ elif (c == "n"):
+ create_new(conns)
+ else:
+ connection = get_connection(conns, c)
+ if not connection:
+ print("Select a valid connection.")
+ getch()
+ else:
+ connect(connection)
+ return
+
+if __name__ == "__main__":
+ main()