From d2d8d15bb6fdf2579eb0c04bbe88ff3bb4f90d1c Mon Sep 17 00:00:00 2001 From: Karina5005 Date: Fri, 8 Sep 2023 11:08:03 +0300 Subject: [PATCH 1/4] add retry --- backup_github/backup.py | 6 ++++++ backup_github/utils.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backup_github/backup.py b/backup_github/backup.py index 1ed0fff..45b882a 100644 --- a/backup_github/backup.py +++ b/backup_github/backup.py @@ -2,6 +2,7 @@ import os import shutil import subprocess +import time from pathlib import Path from typing import Optional @@ -107,6 +108,11 @@ def __save_repo_content(self, repository, dir): ) try: subprocess_handle(subprocess.call, ["git", "clone", "--bare", repo_url]) + if not os.path.exists(f"{repository}.git"): + time.sleep(10) + subprocess_handle(subprocess.call, ["git", "clone", "--bare", repo_url]) + if not os.path.exists(f"{repository}.git"): + raise subprocess.CalledProcessError except subprocess.CalledProcessError: shutil.rmtree(f"{dir}/{repository}") logging.error(f"Repository {repository} backup error, will be skipped") diff --git a/backup_github/utils.py b/backup_github/utils.py index de89b50..7312491 100644 --- a/backup_github/utils.py +++ b/backup_github/utils.py @@ -22,8 +22,9 @@ def subprocess_handle(func, args): except subprocess.CalledProcessError as e: logging.error("Subprocess call error") logging.error("exit code: {}".format(e.returncode)) - logging.error("stdout: {}".format(e.output.decode(sys.getfilesystemencoding()))) - logging.error("stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding()))) + if e.output: + logging.error("stdout: {}".format(e.output.decode(sys.getfilesystemencoding()))) + logging.error("stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding()))) raise e From 853129d7a7d9757d816b5982ef921a2d008a8e6d Mon Sep 17 00:00:00 2001 From: Karina5005 Date: Fri, 8 Sep 2023 11:12:32 +0300 Subject: [PATCH 2/4] fix black --- backup_github/backup.py | 4 +++- backup_github/utils.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backup_github/backup.py b/backup_github/backup.py index 45b882a..5445b38 100644 --- a/backup_github/backup.py +++ b/backup_github/backup.py @@ -110,7 +110,9 @@ def __save_repo_content(self, repository, dir): subprocess_handle(subprocess.call, ["git", "clone", "--bare", repo_url]) if not os.path.exists(f"{repository}.git"): time.sleep(10) - subprocess_handle(subprocess.call, ["git", "clone", "--bare", repo_url]) + subprocess_handle( + subprocess.call, ["git", "clone", "--bare", repo_url] + ) if not os.path.exists(f"{repository}.git"): raise subprocess.CalledProcessError except subprocess.CalledProcessError: diff --git a/backup_github/utils.py b/backup_github/utils.py index 7312491..f473810 100644 --- a/backup_github/utils.py +++ b/backup_github/utils.py @@ -23,8 +23,12 @@ def subprocess_handle(func, args): logging.error("Subprocess call error") logging.error("exit code: {}".format(e.returncode)) if e.output: - logging.error("stdout: {}".format(e.output.decode(sys.getfilesystemencoding()))) - logging.error("stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding()))) + logging.error( + "stdout: {}".format(e.output.decode(sys.getfilesystemencoding())) + ) + logging.error( + "stderr: {}".format(e.stderr.decode(sys.getfilesystemencoding())) + ) raise e From 65c13f915dada31acba1c79a4073f9845b1814cd Mon Sep 17 00:00:00 2001 From: Karina5005 Date: Fri, 8 Sep 2023 12:18:57 +0300 Subject: [PATCH 3/4] fix raise error --- backup_github/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup_github/backup.py b/backup_github/backup.py index 5445b38..62308cb 100644 --- a/backup_github/backup.py +++ b/backup_github/backup.py @@ -114,7 +114,7 @@ def __save_repo_content(self, repository, dir): subprocess.call, ["git", "clone", "--bare", repo_url] ) if not os.path.exists(f"{repository}.git"): - raise subprocess.CalledProcessError + raise subprocess.CalledProcessError(1, ["git", "clone", "--bare", repo_url]) except subprocess.CalledProcessError: shutil.rmtree(f"{dir}/{repository}") logging.error(f"Repository {repository} backup error, will be skipped") From 36aa98fb2e8f825d46d0fce25ec44a05e0613183 Mon Sep 17 00:00:00 2001 From: Karina5005 Date: Fri, 15 Sep 2023 13:40:16 +0300 Subject: [PATCH 4/4] fix black --- backup_github/backup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backup_github/backup.py b/backup_github/backup.py index 62308cb..d98e6ec 100644 --- a/backup_github/backup.py +++ b/backup_github/backup.py @@ -114,7 +114,9 @@ def __save_repo_content(self, repository, dir): subprocess.call, ["git", "clone", "--bare", repo_url] ) if not os.path.exists(f"{repository}.git"): - raise subprocess.CalledProcessError(1, ["git", "clone", "--bare", repo_url]) + raise subprocess.CalledProcessError( + 1, ["git", "clone", "--bare", repo_url] + ) except subprocess.CalledProcessError: shutil.rmtree(f"{dir}/{repository}") logging.error(f"Repository {repository} backup error, will be skipped")