Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5694

Re: [Python-de] yaml config mit python editieren

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From robert rottermann <robert@redcor.ch>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] yaml config mit python editieren
Date Sat, 10 Oct 2020 13:47:34 +0200
Lines 90
Message-ID <mailman.1291.1602330461.9580.python-de@python.org> (permalink)
References <09de33f7-e3b5-26b6-90d3-8e9c9b7788be@fuhrmann.homedns.org> <8221f608-2a51-2594-e12a-1cdb0332b8ea@redcor.ch>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Lj3ZUSEjdNHRTkbqkjef+gMocpTjmLiilXZPEREAKVrw==
Return-Path <robert@redcor.ch>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
Authentication-Results mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=redcor.ch header.i=@redcor.ch header.b=HhXYAmoG; dkim-adsp=pass; dkim-atps=neutral
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=redcor.ch; s=201908; t=1602330454; bh=UPotIvxi2xfsBLOVaiX+zAV2YcxDjmW+X0N/rMKu2Qk=; h=Subject:To:References:From:Date:In-Reply-To:From; b=HhXYAmoGVihWhAmWN17wJXskNESGMTw9zNGY7usjyyDfY6h/hzLLrj27KthsaQtMh UT6fseyM9rRC26jkT+oMw7u4KabOFrG94ew5MKcAfb8l/NB43YZv201TSXtF7v2s8U zgRe1Aub4U2WLeUIE31palqTv8zFLxZRQpqeU2GUk8jxflvn7FfkVt/76N5JgceVUE 46KjWJ+iq2Z3zVnbdRW9Cg82nMy5zCkz6YW/MM7BjOUp5RlCIIWOQa+yBtLpT5UZv8 iMJN5za0uelpFwXzrujz91lrulK6z/W9uRVPc6d28OsQvs3LIDojxQian1gyGwdfcF k14iCPd6VhCfw==
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1
In-Reply-To <09de33f7-e3b5-26b6-90d3-8e9c9b7788be@fuhrmann.homedns.org>
Content-Language de-CH
X-Content-Filtered-By Mailman/MimeDel 2.1.34
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.34
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <8221f608-2a51-2594-e12a-1cdb0332b8ea@redcor.ch>
X-Mailman-Original-References <09de33f7-e3b5-26b6-90d3-8e9c9b7788be@fuhrmann.homedns.org>
Xref csiph.com de.comp.lang.python:5694

Show key headers only | View raw


StephanOn 10.10.20 09:39, Stefan Fuhrmann wrote:
> Hallo zusammen,
>
> ich habe eine docker-compose.yml und möchte diese editieren, was mir nicht 
> gelingt.

beliegend zwei Dateien:

config.yaml:
     das is ein Template, das zu Generieren einer yaml-Datei die aus einem 
Template-Ordner gelesen wird.

construct_default.py:
     ersetzt die "Platzhalter"  und schreibt die yaml Datei.

Ich mache da alles sehr "händisch". Geht wohl eleganter, funktioniert aber bestens.

Gruss

Robert

>
> #!/usr/bin/python3
>  2
>  3 import subprocess
>  4 import shutil
>  5 import os
>  6 import docker
>  7 #client = docker.DockerClient(base_url="unix://var/run/docker.sock", 
> version='auto')
>  8 client = docker.from_env()
>  9 import sys
> 10 import yaml
> 11print(sys.version)
> 12
> 1
> 21
> 22
> 23 with open('docker-compose.yml', "r") as f:
>
> 24     # The FullLoader parameter handles the conversion from YAML
> 25     # scalar values to Python the dictionary format26     # docker_compose 
> = yaml.load(file, Loader=yaml.FullLoader)
>
> 27     docker_compose  = yaml.full_load(f)
>
> 28 #    docker_compose  = yaml.load(f, Loader=yaml.FullLoader)
> 29 #    docker_compose['MYSQL_ROOT_PASSWORD'] = "test"
> 30 #docker_compose["services"]["db"]["environment"]['MYSQL_ROOT_PASSWORD'] = 
> docker_compose.update("{{{pass}}}", "passing")
> 31
> 32     #docker_compose.update("{{{pass}}}", "Passing")
> 33
> 34    # txt = "pass"
> 35    # x = txt.replace("pass", "apples")
> 36     docker_compose["services"]["db"]["environment"] = 
> docker_compose.update("pass", "apples")
> 37
> 38 #    print(docker_compose)
> 39    # docker_compose = docker_compose.replace("{{{pass}}}", "passingpass")
> 40
> 41
> 42 with open('docker-compose.yml', "w") as f:
> 43     yaml.dump(docker_compose, f)
>
> in der docker-compose habe ich bei MYSQL_ROOT_PASSWORD=pass eingetragen, weil 
> ich dachte, wenn ich da was einfaches stehen habe, kann ich es ersetzen.
>
> Das funktioniert so leider nicht. Jetzt wird bis "environment" in der yaml 
> alles weggeschnitten.
>
>
> Wie kann ich eine docker-compose.yml mit  python editieren?
>
> Kann jemand helfen?
>
>
> Danke!
>
> Gruß
>
> Stefan
>
>
> _______________________________________________
> python-de maillist  -  python-de@python.org
> https://mail.python.org/mailman/listinfo/python-de

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

Re: [Python-de] yaml config mit python editieren robert rottermann <robert@redcor.ch> - 2020-10-10 13:47 +0200

csiph-web