...
 
Commits (2)
......@@ -18,10 +18,10 @@ You can install this tool from PyPI:
```
alcibiade@mobydick:~$ sudo pip3 install docker-ascii-map
Collecting docker-ascii-map
Downloading docker-ascii-map-1.0.0.tar.gz
Downloading docker-ascii-map-1.1.0.tar.gz
Installing collected packages: docker-ascii-map
Running setup.py install for docker-ascii-map ... done
Successfully installed docker-ascii-map-1.0.0
Successfully installed docker-ascii-map-1.1.0
```
......
__version__ = '1.0.0'
__version__ = '1.1.0'
......@@ -20,11 +20,14 @@ def supports_color():
return False
return True
def get_input_parameters() -> Tuple[bool]:
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
parser.add_argument('-f', '--follow', action='store_const', const='follow',
help='Follow status changes continuously')
args = parser.parse_args()
color_mode = supports_color()
......@@ -35,4 +38,4 @@ def get_input_parameters() -> Tuple[bool]:
if args.mono:
color_mode = False
return color_mode,
return color_mode, args.follow is not None
#!/usr/bin/env python3
import sys
import time
from docker_ascii_map.argument_parser import get_input_parameters
from docker_ascii_map.ascii_render import Renderer
from docker_ascii_map.docker_config import ConfigParser
def follow(color_mode):
try:
config_parser = ConfigParser()
while True:
print(chr(27) + "[2J")
print(chr(27) + "[;H")
renderer = Renderer()
config = config_parser.get_configuration()
text = renderer.render(config, encoding=sys.stdout.encoding, color=color_mode)
print(text)
time.sleep(2)
except KeyboardInterrupt as e:
pass
def main():
color_mode, follow_mode = get_input_parameters()
if follow_mode:
follow(color_mode)
else:
config_parser = ConfigParser()
renderer = Renderer()
config = config_parser.get_configuration()
text = renderer.render(config, encoding=sys.stdout.encoding, color=color_mode)
print(text)
if __name__ == '__main__':
color_mode = get_input_parameters()[0]
config_parser = ConfigParser()
renderer = Renderer()
config = config_parser.get_configuration()
# print(config)
text = renderer.render(config, encoding=sys.stdout.encoding, color=color_mode)
print(text)
main()
......@@ -8,9 +8,10 @@ import docker_ascii_map.argument_parser
class Args:
def __init__(self, mono=None, color=None):
def __init__(self, mono=None, color=None, follow=None):
self.mono = mono
self.color = color
self.follow = follow
class ParametersTests(unittest.TestCase):
......@@ -18,7 +19,6 @@ class ParametersTests(unittest.TestCase):
with patch('sys.platform', return_value='linux') as mock_getenv, \
patch.object(sys.stdout, 'isatty', return_value=False) as mock_stdout, \
patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual(False, r[0])
......@@ -26,7 +26,6 @@ class ParametersTests(unittest.TestCase):
with patch('sys.platform', return_value='linux') as mock_getenv, \
patch.object(sys.stdout, 'isatty', return_value=True) as mock_stdout, \
patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual(True, r[0])
......@@ -35,10 +34,23 @@ class ParametersTests(unittest.TestCase):
patch.object(sys.stdout, 'isatty', return_value=True) as mock_stdout, \
patch('os.environ', return_value=['ANSICON']) as mock_environ, \
patch.object(ArgumentParser, 'parse_args', return_value=Args()) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual(True, r[0])
def test_follow_default(self):
with patch('sys.platform', return_value='linux') as mock_getenv, \
patch.object(sys.stdout, 'isatty', return_value=True) as mock_stdout, \
patch.object(ArgumentParser, 'parse_args', return_value=Args(follow=None)) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual((True, False), r)
def test_follow_on(self):
with patch('sys.platform', return_value='linux') as mock_getenv, \
patch.object(sys.stdout, 'isatty', return_value=True) as mock_stdout, \
patch.object(ArgumentParser, 'parse_args', return_value=Args(follow='follow')) as mock_parse:
r = docker_ascii_map.argument_parser.get_input_parameters()
self.assertEqual((True, True), r)
if __name__ == '__main__':
unittest.main()