From 6ea4acaab2a0ee86764dec3fa3e8a8be79330409 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 13 Jun 2021 04:50:21 +0200 Subject: [PATCH] [mod] use with tempfile.TemporaryDirectory --- README-generator/webhook.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README-generator/webhook.py b/README-generator/webhook.py index e33f994..5f52c7b 100755 --- a/README-generator/webhook.py +++ b/README-generator/webhook.py @@ -1,6 +1,6 @@ import subprocess import os -import shutil +import tempfile from github_webhook import Webhook from flask import Flask @@ -43,8 +43,7 @@ def on_push(data): repository = data["repository"]["full_name"] branch = data["ref"].split("/", 2)[2] - folder = subprocess.check_output(["mktemp", "-d"]).decode('utf-8').strip() - try: + with tempfile.TemporaryDirectory() as folder: git(["clone", f"https://{login}:{token}@github.com/{repository}", "--single-branch", "--branch", branch, folder]) generate_READMEs(folder) @@ -56,9 +55,7 @@ def on_push(data): git(["commit", "-a", "-m", "Auto-update README", "--author='Yunohost-Bot <>'"], in_folder=folder) git(["push", "origin", branch, "--quiet"], in_folder=folder) - finally: - if os.path.exists(folder): - shutil.rmtree(folder) + if __name__ == "__main__": app.run(host="0.0.0.0", port=8123)