Blender 5.1.2 (#1)
Refactoring to works with the new blender depot config Reviewed-on: #1 Co-authored-by: stilobique <contact@aurelien-vaillant.net>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import logging
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
|
||||
from pathlib import Path
|
||||
from subprocess import run, CalledProcessError
|
||||
|
||||
|
||||
def clean_all_dockers():
|
||||
"""
|
||||
Nettoie Docker pour tous les contextes disponibles (default, podman, ...).
|
||||
Equivalent a, pour chaque contexte :
|
||||
docker context use <context>
|
||||
docker system prune -a -f
|
||||
Puis remet le contexte d'origine en place a la fin.
|
||||
"""
|
||||
logs_dir = Path(os.getcwd(), 'logs')
|
||||
logs_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
logger = logging.getLogger('blender_docker.clean')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.propagate = False
|
||||
if not logger.handlers:
|
||||
handler = logging.FileHandler(logs_dir / 'clean.log')
|
||||
handler.setFormatter(logging.Formatter(
|
||||
'%(asctime)s|%(name)s [%(levelname)s] %(message)s'
|
||||
))
|
||||
logger.addHandler(handler)
|
||||
|
||||
# Contexte courant, pour le restaurer a la fin
|
||||
original_context = run(
|
||||
['docker', 'context', 'show'],
|
||||
capture_output=True, text=True, check=True
|
||||
).stdout.strip()
|
||||
logger.info(f'Contexte d\'origine: {original_context}')
|
||||
|
||||
# Liste de tous les contextes disponibles (format json, un objet par ligne)
|
||||
contexts_raw = run(
|
||||
['docker', 'context', 'ls', '--format', '{{json .}}'],
|
||||
capture_output=True, text=True, check=True
|
||||
).stdout.strip().splitlines()
|
||||
contexts = [json.loads(line)['Name'] for line in contexts_raw if line]
|
||||
|
||||
print(f'\tContextes trouves: {contexts}')
|
||||
logger.info(f'Contextes trouves: {contexts}')
|
||||
|
||||
for context in contexts:
|
||||
try:
|
||||
print(f'\tNettoyage du contexte: {context}')
|
||||
logger.info(f'Nettoyage du contexte: {context}')
|
||||
|
||||
run(['docker', 'context', 'use', context], check=True)
|
||||
|
||||
result = run(
|
||||
['docker', 'system', 'prune', '-a', '-f'],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
|
||||
print(f'\t{result.stdout.strip()}')
|
||||
logger.info(result.stdout.strip())
|
||||
|
||||
except CalledProcessError as e:
|
||||
print(f'\tErreur sur le contexte {context}: {e.stderr.strip()}')
|
||||
logger.error(f'Erreur sur le contexte {context}: {e.stderr.strip()}')
|
||||
|
||||
# On remet le contexte d'origine
|
||||
run(['docker', 'context', 'use', original_context], check=True)
|
||||
print(f'\tContexte restaure: {original_context}')
|
||||
logger.info(f'Contexte restaure: {original_context}')
|
||||
|
||||
|
||||
def get_all_tags_from_blender():
|
||||
"""From the Gitea api, get all blender tags release"""
|
||||
r = requests.get(r"https://projects.blender.org/api/v1/repos/blender/blender/tags")
|
||||
print(r.text)
|
||||
j = r.json()
|
||||
|
||||
# All tags data:
|
||||
for release in j:
|
||||
print(release)
|
||||
|
||||
|
||||
def get_all_tags_from_docker():
|
||||
"""From the Gitea api, get all blender tags release"""
|
||||
r = requests.get(r"https://hub.docker.com/v2/namespaces/stilobique/repositories/blender/tags")
|
||||
print(r.text)
|
||||
j = r.json()
|
||||
|
||||
# All tags data:
|
||||
for release in j:
|
||||
print(release)
|
||||
Reference in New Issue
Block a user