...
 
......@@ -92,3 +92,4 @@ ENV/
/.idea/
/MANIFEST
......@@ -6,13 +6,27 @@ A set of python scripts displaying the local docker containers structure and sta
* python 3.5
* docker-py
## Install
You can install this tool from PyPI:
```
alcibiade@mobydick:~$ sudo pip3 install docker-ascii-map
Collecting docker-ascii-map
Downloading docker-ascii-map-0.1.tar.gz
Installing collected packages: docker-ascii-map
Running setup.py install for docker-ascii-map ... done
Successfully installed docker-ascii-map-0.1
```
## Usage
Below is a sample of a host running several applications on multiple networks.
A container is routing traffic to these networks from the host.
```
alcibiade@mobydick:~/docker-ascii-map$ python3 src/docker-ascii-map.py
alcibiade@mobydick:~/docker-ascii-map$ docker-ascii-map.py
+- chesscorp_default ----------------+
| [✓] chesscorp_web_1 |
......
......@@ -2,10 +2,10 @@ from distutils.core import setup
setup(
name='docker-ascii-map',
version='0.1',
packages=[''],
version='0.2',
packages=['docker_ascii_map'],
package_dir={'': 'src'},
scripts=['src/docker-ascii-map.py'],
scripts=['src/docker_ascii_map/docker-ascii-map.py'],
url='https://github.com/ChessCorp/docker-ascii-map',
license='MIT',
author='Yannick Kirschhoffer',
......
from docker_config import Configuration, Container
from widget import *
from docker_ascii_map.widget import *
from docker_ascii_map.docker_config import Configuration, Container
def build_container_widget(container: Container) -> Widget:
def build_container_widget(container: Container, encoding: str) -> Widget:
lines = []
if container.status == 'running':
statuschar = u"\u2713"
if encoding == 'UTF-8':
statuschar = u"\u2713" if container.status == 'running' else u"\u274c"
else:
statuschar = u"\u274c"
statuschar = 'V' if container.status == 'running' else 'x'
lines.append('[' + statuschar + '] ' + container.name)
lines.append(' ' + container.image)
container_widget = Paragraph(lines)
......@@ -41,7 +43,7 @@ class Renderer:
def __init__(self):
pass
def render(self, config: Configuration):
def render(self, config: Configuration, encoding: str = 'UTF-8'):
network_widgets = []
networks = build_ordered_network_list(config)
......@@ -56,7 +58,7 @@ class Renderer:
for container in config.containers:
if [net] == container.networks:
container_widget = build_container_widget(container)
container_widget = build_container_widget(container, encoding)
cnt_widgets_map[container] = container_widget
net_widgets.append(container_widget)
......@@ -71,7 +73,7 @@ class Renderer:
for container in config.containers:
if len(container.networks) > 1:
c = Padding(build_container_widget(container), Size(1, 0))
c = Padding(build_container_widget(container, encoding), Size(1, 0))
cnt_widgets_map[container] = c
padded = Padding(c, Size(12, 2))
bridge_widgets.append(padded)
......
#!/usr/bin/env python3
from ascii_render import Renderer
from docker_config import ConfigParser
import sys
from docker_ascii_map.docker_config import ConfigParser
from docker_ascii_map.ascii_render import Renderer
if __name__ == '__main__':
parser = ConfigParser()
......@@ -8,5 +11,5 @@ if __name__ == '__main__':
config = parser.get_configuration()
# print(config)
text = renderer.render(config)
text = renderer.render(config, sys.stdout.encoding)
print(text)
from typing import List, Tuple
from raster import Raster
from docker_ascii_map.raster import Raster
class Size:
......
import unittest
from ascii_render import Renderer
from docker_config import *
from docker_ascii_map.docker_config import *
from docker_ascii_map.ascii_render import Renderer
class RenderingTests(unittest.TestCase):
......@@ -29,6 +30,24 @@ class RenderingTests(unittest.TestCase):
'+----------------------------+\n',
renderer.render(config))
def test_ascii_fallback(self):
config = Configuration([
Container('n1', 'running', ['net1'], 'group1/image-long-name', []),
Container('n2', 'stopped', ['net2'], 'group2/image-short', []),
])
renderer = Renderer()
self.assertEqual(
'+- net1 ---------------------+\n'
'| [V] n1 |\n'
'| group1/image-long-name |\n'
'+----------------------------+\n'
'+- net2 ---------------------+\n'
'| [x] n2 |\n'
'| group2/image-short |\n'
'+----------------------------+\n',
renderer.render(config, 'ascii'))
def test_dual_net_config(self):
self.maxDiff = None
config = Configuration([
......
import unittest
from raster import Raster, Boundary
from docker_ascii_map.raster import Raster, Boundary
class RasterTests(unittest.TestCase):
......
import unittest
from raster import Boundary
from widget import *
from docker_ascii_map.widget import *
from docker_ascii_map.raster import Boundary
class ModelTests(unittest.TestCase):
......