Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions backup_service.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os
import re
import git
import shutil
import requests
import zipfile
import tarfile
import logging
from datetime import datetime, timedelta
from pathlib import Path
from github import Github
# PyGithub and requests are imported inside the methods that use them, so the
# idle web process doesn't keep these heavy modules (~30 MB) in memory.
from models import db, BackupJob, RELEASE_MODES
from urllib.parse import urlparse

Expand Down Expand Up @@ -326,6 +325,7 @@ def _safe_filename(self, name):

def _download_file(self, url, destination, headers):
"""Stream a file from the GitHub API to disk"""
import requests
with requests.get(url, headers=headers, stream=True, timeout=(30, 300), allow_redirects=True) as response:
response.raise_for_status()
with open(destination, 'wb') as f:
Expand All @@ -348,6 +348,7 @@ def _download_releases(self, repository, releases_dir):
owner, repo_name = owner_repo

token = repository.github_token.strip() if repository.github_token else ''
from github import Github
g = Github(token) if token else Github()
gh_repo = g.get_repo(f"{owner}/{repo_name}")

Expand Down Expand Up @@ -520,6 +521,7 @@ def verify_github_access(self, repo_url, github_token=None):
if repo_name.endswith('.git'):
repo_name = repo_name[:-4]

from github import Github
if github_token:
g = Github(github_token)
else:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ werkzeug==3.1.8
bcrypt==5.0.0
APScheduler==3.11.3
PyGithub==2.10.0
gitpython==3.1.62
python-dotenv==1.2.3
requests==2.34.2
sqlalchemy==2.0.54
Expand Down
Loading