aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PKGBUILD2
-rw-r--r--getch.py38
-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
-rwxr-xr-xsrc/python-sshmgr/sshmgr/manager.py20
-rwxr-xr-xsshmgr.py83
7 files changed, 15 insertions, 261 deletions
diff --git a/PKGBUILD b/PKGBUILD
index b3e8f6d..d6faa92 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -9,7 +9,7 @@
# Maintainer: Jan Tuomi <jan-sebastian.tuomi@aalto.fi>
pkgname=python-sshmgr
pkgver=0.1
-pkgrel=2
+pkgrel=4
pkgdesc="Minimal ssh connection manager"
arch=('x86_64' 'i386')
url=""
diff --git a/getch.py b/getch.py
deleted file mode 100644
index be6203f..0000000
--- a/getch.py
+++ /dev/null
@@ -1,38 +0,0 @@
-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/setup.py b/src/python-sshmgr-0.1/setup.py
deleted file mode 100644
index 929b2fb..0000000
--- a/src/python-sshmgr-0.1/setup.py
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/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
deleted file mode 100644
index be6203f..0000000
--- a/src/python-sshmgr-0.1/src/getch.py
+++ /dev/null
@@ -1,38 +0,0 @@
-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
deleted file mode 100755
index 497df06..0000000
--- a/src/python-sshmgr-0.1/src/sshmgr
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/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()
diff --git a/src/python-sshmgr/sshmgr/manager.py b/src/python-sshmgr/sshmgr/manager.py
index a55aa07..25a411f 100755
--- a/src/python-sshmgr/sshmgr/manager.py
+++ b/src/python-sshmgr/sshmgr/manager.py
@@ -2,23 +2,25 @@
from os import system
from sshmgr.utils.getch import getch
import os.path
-
-CONN_DB_PATH = os.path.join(os.path.expanduser("~"), ".sshmgr-db")
+import argparse
class Manager:
+
+ CONN_DB_PATH = os.path.join(os.path.expanduser("~"), ".sshmgr-db")
+
def __init__(self):
pass
def load_conns(self):
conns = []
try:
- with open(CONN_DB_PATH) as f:
+ with open(self.CONN_DB_PATH) as f:
conns = [l.strip() for l in f.readlines()]
except FileNotFoundError:
- with open(CONN_DB_PATH, 'w') as f:
+ with open(self.CONN_DB_PATH, 'w') as f:
conns = []
except:
- print("Could not load connections from file. ({:s})".format(CONN_DB_PATH))
+ print("Could not load connections from file. ({:s})".format(self.CONN_DB_PATH))
getch()
return conns
@@ -30,7 +32,7 @@ class Manager:
self.save_conns(conns)
def save_conns(self, conns):
- with open(CONN_DB_PATH, 'w') as f:
+ with open(self.CONN_DB_PATH, 'w') as f:
for conn in conns:
f.write("{:s}\n".format(conn))
@@ -93,6 +95,12 @@ class Manager:
return
def start():
+ parser = argparse.ArgumentParser(description="Simple text GUI tool for managing SSH connections.")
+ parser.add_argument('--db-path', help="set the path to the data file", default="~/.sshmgr-db")
+ args = parser.parse_args()
+
+ Manager.CONN_DB_PATH = os.path.expanduser(args.db_path)
+
s = Manager()
s.run()
diff --git a/sshmgr.py b/sshmgr.py
deleted file mode 100755
index 497df06..0000000
--- a/sshmgr.py
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/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()