Re: yaml config mit python editieren

robert rottermann <[email protected]>
Newsgroups gmane.comp.python.general.german
Message-ID <[email protected]>
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  -  [email protected]
> https://mail.python.org/mailman/listinfo/python-de


_______________________________________________
python-de maillist  -  [email protected]
https://mail.python.org/mailman/listinfo/python-de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.