Skip to content

Instantly share code, notes, and snippets.

@kujiy
Created December 14, 2017 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kujiy/6c9fa234e985a5f57ffccc6c9dea5197 to your computer and use it in GitHub Desktop.
Save kujiy/6c9fa234e985a5f57ffccc6c9dea5197 to your computer and use it in GitHub Desktop.
A tool creating comma-separated server list for docker phpmyadmin container #
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A tool creating comma-separated server list for docker phpmyadmin container
# Make these lines from python dictionary
#
## PMA_VERBOSES=server1,server2,server3,...
## PMA_HOSTS=192.168.1.2,10.0.0.200,172.16.1.3,...
## PMA_PORTS=3306,13306,3307,...
#
# How to use
# 1. python phpmyadmin-dblist.py > dblist.env
#
# 2. Insert to docker-compose.yml
#
# env_file:
# - ./dblist.env
#
# 3. docker-compose up -d
#
# server difinition
from collections import OrderedDict
DBs = OrderedDict()
### WRITE YOUR SERVERS HERE
DBs['server1'] = {
'ip': '192.168.1.2',
'port': '' # empty=default=3306
}
DBs['server2'] = {
'ip': '10.0.0.200',
'port': '13306'
}
DBs['server3'] = {
'ip': '172.16.1.3',
'port': '3307'
}
# Cups
OUT = OrderedDict()
OUT["PMA_VERBOSES"] = OrderedDict()
OUT["PMA_HOSTS"] = OrderedDict()
OUT["PMA_PORTS"] = OrderedDict()
# Loop for separating to each dictionary
for (db, items) in DBs.items():
ip = items["ip"]
port = items["port"]
# Set default port
if port == '' :
port = 3306
# make each line
OUT["PMA_VERBOSES"][db] = db
OUT["PMA_HOSTS"][db] = ip
OUT["PMA_PORTS"][db] = port
# print(db)
# print("ip="+items["ip"])
# print("port="+items["port"])
# print(OUT)
# Loop to make each strings
for (line, val) in OUT.items():
# make key= part
line = line + "="
for i in val.values():
# push value with comma
line += str(i) + ","
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment