mirror of
https://github.com/Red5d/docker-autocompose
synced 2026-01-03 15:18:01 +00:00
Merge pull request #36 from ostafen/master
Format properly date/datetime labels
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
import datetime
|
||||
import sys, argparse, pyaml, docker
|
||||
from collections import OrderedDict
|
||||
|
||||
@@ -28,6 +28,20 @@ def render(struct, args, networks):
|
||||
pyaml.p(OrderedDict({'version': '"3"', 'services': struct, 'networks': networks}))
|
||||
|
||||
|
||||
def is_date_or_time(s: str):
|
||||
for parse_func in [datetime.date.fromisoformat, datetime.datetime.fromisoformat]:
|
||||
try:
|
||||
parse_func(s.rstrip('Z'))
|
||||
return True
|
||||
except ValueError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def fix_label(label: str):
|
||||
return f"'{label}'" if is_date_or_time(label) else label
|
||||
|
||||
|
||||
def generate(cname):
|
||||
c = docker.from_env()
|
||||
|
||||
@@ -57,7 +71,7 @@ def generate(cname):
|
||||
'environment': cattrs['Config']['Env'],
|
||||
'extra_hosts': cattrs['HostConfig']['ExtraHosts'],
|
||||
'image': cattrs['Config']['Image'],
|
||||
'labels': cattrs['Config']['Labels'],
|
||||
'labels': {label: fix_label(value) for label, value in cattrs['Config']['Labels'].items()},
|
||||
'links': cattrs['HostConfig']['Links'],
|
||||
#'log_driver': cattrs['HostConfig']['LogConfig']['Type'],
|
||||
#'log_opt': cattrs['HostConfig']['LogConfig']['Config'],
|
||||
|
||||
Reference in New Issue
Block a user