Skip to content

Commit

Permalink
remove manage.py as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
emre committed Jul 18, 2013
1 parent c6f638e commit af11550
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='stormssh',
version='0.4.2',
version='0.4.3',
packages=['storm'],
url='http://github.com/emre/storm',
license='MIT',
Expand All @@ -16,7 +16,6 @@
],
install_requires=list(filter(None, [
"paramiko",
"manage.py",
"termcolor",
"argparse" if sys.version_info[:2] < (2, 7) else None,
])),)
4 changes: 2 additions & 2 deletions storm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import getpass

__version__ = '0.4.2'
__version__ = '0.4.3'


class Storm(object):
Expand Down Expand Up @@ -59,7 +59,7 @@ def search_host(self, search_string):
results = self.ssh_config.search_host(search_string)
formatted_results = []
for host_entry in results:
formatted_results.append(" {0} -> {1}@{2}:{3}\n".format(
formatted_results.append(" {0} -> {1}@{2}:{3}\n".format(
host_entry.get("host"),
host_entry.get("options").get("user", getpass.getuser()),
host_entry.get("options").get("hostname"),
Expand Down
34 changes: 28 additions & 6 deletions storm/bin/storm
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python


import getpass
import __builtin__

from storm import Storm
from storm import __version__
Expand Down Expand Up @@ -98,18 +100,36 @@ def list():
Lists all hosts from ssh config.
"""
try:
result = 'listing entries:\n'
result = colored('listing entries:\n\n', 'white')
result_stack = ""
for host in storm_.list_entries(True):

if host.get("type") == 'entry':
if not host.get("host") == "*":
result += " {0} -> {1}@{2}:{3}\n".format(
host["host"],
result += " {0} -> {1}@{2}:{3}".format(
colored(host["host"], 'white'),
host.get("options").get("user", default_user),
host.get("options").get("hostname", "[hostname_not_specified]"),
host.get("options").get("port", 22)
)

extra = False
for key, value in host.get("options").iteritems():

if not key in ["user", "hostname", "port"]:
if not extra:
custom_options = colored('\n\t[custom options] ', 'white')
result += " {0}".format(custom_options)
extra = True

if isinstance(value, __builtin__.list):
value = ",".join(value)

result += "{0}={1} ".format(key, value)
if extra:
result = result[0:-1]

result += "\n\n"
else:
result_stack = " (*) -> "
for key, value in host.get("options").iteritems():
Expand Down Expand Up @@ -141,9 +161,11 @@ def search(search_text):
results = storm_.search_host(search_text)
if len(results) == 0:
print ('no results found.')
message = 'Listing results for {0}:\n'.format(search_text)
message += "".join(results)
print message

if len(results) > 0:
message = 'Listing results for {0}:\n'.format(search_text)
message += "".join(results)
print message
except Exception as error:
print get_formatted_message(str(error), 'error')

Expand Down
26 changes: 26 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ def test_search_host(self):
results = self.storm.ssh_config.search_host("netsca")
self.assertEqual(len(results), 1)

def test_custom_options(self):
custom_options= [
"StrictHostKeyChecking=no",
"UserKnownHostsFile=/dev/null",
]
self.storm.add_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options)
self.storm.ssh_config.write_to_ssh_config()

for item in self.storm.ssh_config.config_data:
if item.get("host") == 'host_with_custom_option':
self.assertEqual(item.get("options").get("StrictHostKeyChecking"), 'no')
self.assertEqual(item.get("options").get("UserKnownHostsFile"), '/dev/null')

custom_options = [
"StrictHostKeyChecking=yes",
"UserKnownHostsFile=/home/emre/foo",
]
self.storm.edit_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options)
self.storm.ssh_config.write_to_ssh_config()

for item in self.storm.ssh_config.config_data:
if item.get("host") == 'host_with_custom_option':
self.assertEqual(item.get("options").get("StrictHostKeyChecking"), 'yes')
self.assertEqual(item.get("options").get("UserKnownHostsFile"), '/home/emre/foo')


def tearDown(self):
os.unlink('/tmp/ssh_config')

Expand Down

0 comments on commit af11550

Please sign in to comment.