github-backup 0.62.1__py3-none-any.whl → 0.64.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- github_backup/__init__.py +1 -1
- github_backup/cli.py +1 -1
- github_backup/github_backup.py +91 -53
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/METADATA +1 -1
- github_backup-0.64.0.dist-info/RECORD +12 -0
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/WHEEL +1 -1
- github_backup-0.62.1.dist-info/RECORD +0 -12
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/entry_points.txt +0 -0
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/licenses/LICENSE.txt +0 -0
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/top_level.txt +0 -0
- {github_backup-0.62.1.dist-info → github_backup-0.64.0.dist-info}/zip-safe +0 -0
github_backup/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.64.0"
|
github_backup/cli.py
CHANGED
|
@@ -81,7 +81,7 @@ def main():
|
|
|
81
81
|
repositories = retrieve_repositories(args, authenticated_user)
|
|
82
82
|
repositories = filter_repositories(args, repositories)
|
|
83
83
|
backup_repositories(args, output_directory, repositories)
|
|
84
|
-
backup_account(args, output_directory)
|
|
84
|
+
backup_account(args, output_directory, authenticated_user)
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
if __name__ == "__main__":
|
github_backup/github_backup.py
CHANGED
|
@@ -12,11 +12,11 @@ import os
|
|
|
12
12
|
import platform
|
|
13
13
|
import random
|
|
14
14
|
import re
|
|
15
|
-
import select
|
|
16
15
|
import socket
|
|
17
16
|
import ssl
|
|
18
17
|
import subprocess
|
|
19
18
|
import sys
|
|
19
|
+
import threading
|
|
20
20
|
import time
|
|
21
21
|
from collections.abc import Generator
|
|
22
22
|
from datetime import datetime
|
|
@@ -91,32 +91,37 @@ def logging_subprocess(
|
|
|
91
91
|
child = subprocess.Popen(
|
|
92
92
|
popenargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs
|
|
93
93
|
)
|
|
94
|
-
if sys.platform == "win32":
|
|
95
|
-
logger.info(
|
|
96
|
-
"Windows operating system detected - no subprocess logging will be returned"
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
log_level = {child.stdout: stdout_log_level, child.stderr: stderr_log_level}
|
|
100
|
-
|
|
101
|
-
def check_io():
|
|
102
|
-
if sys.platform == "win32":
|
|
103
|
-
return
|
|
104
|
-
ready_to_read = select.select([child.stdout, child.stderr], [], [], 1000)[0]
|
|
105
|
-
for io in ready_to_read:
|
|
106
|
-
line = io.readline()
|
|
107
|
-
if not logger:
|
|
108
|
-
continue
|
|
109
|
-
if not (io == child.stderr and not line):
|
|
110
|
-
logger.log(log_level[io], line[:-1])
|
|
111
|
-
|
|
112
|
-
# keep checking stdout/stderr until the child exits
|
|
113
|
-
while child.poll() is None:
|
|
114
|
-
check_io()
|
|
115
94
|
|
|
116
|
-
|
|
95
|
+
def log_output(pipe, log_level):
|
|
96
|
+
# Drain the pipe from a thread so the child never blocks on a full
|
|
97
|
+
# pipe buffer (issue #519), logging each line as it arrives.
|
|
98
|
+
with pipe:
|
|
99
|
+
for line in iter(pipe.readline, b""):
|
|
100
|
+
try:
|
|
101
|
+
logger.log(log_level, line.rstrip(b"\r\n"))
|
|
102
|
+
except Exception:
|
|
103
|
+
# Keep draining even if logging fails, or the child
|
|
104
|
+
# blocks on a full pipe buffer again
|
|
105
|
+
pass
|
|
106
|
+
|
|
107
|
+
threads = [
|
|
108
|
+
threading.Thread(
|
|
109
|
+
target=log_output, args=(child.stdout, stdout_log_level), daemon=True
|
|
110
|
+
),
|
|
111
|
+
threading.Thread(
|
|
112
|
+
target=log_output, args=(child.stderr, stderr_log_level), daemon=True
|
|
113
|
+
),
|
|
114
|
+
]
|
|
115
|
+
for thread in threads:
|
|
116
|
+
thread.start()
|
|
117
117
|
|
|
118
118
|
rc = child.wait()
|
|
119
119
|
|
|
120
|
+
# Timeout in case a grandchild inherited the pipe handles and keeps
|
|
121
|
+
# them open past the child's exit, which would delay EOF indefinitely
|
|
122
|
+
for thread in threads:
|
|
123
|
+
thread.join(timeout=60)
|
|
124
|
+
|
|
120
125
|
if rc != 0:
|
|
121
126
|
print("{} returned {}:".format(popenargs[0], rc), file=sys.stderr)
|
|
122
127
|
print("\t", " ".join(popenargs), file=sys.stderr)
|
|
@@ -2657,10 +2662,20 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
|
|
|
2657
2662
|
def pull_is_due_for_repository_checkpoint(pull):
|
|
2658
2663
|
return not repository_since or pull["updated_at"] > repository_since
|
|
2659
2664
|
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2665
|
+
try:
|
|
2666
|
+
if not args.include_pull_details:
|
|
2667
|
+
pull_states = ["open", "closed"]
|
|
2668
|
+
for pull_state in pull_states:
|
|
2669
|
+
query_args["state"] = pull_state
|
|
2670
|
+
for pull in retrieve_data(
|
|
2671
|
+
args, _pulls_template, query_args=query_args, lazy=True
|
|
2672
|
+
):
|
|
2673
|
+
track_newest_pull_update(pull)
|
|
2674
|
+
if pulls_since and pull["updated_at"] <= pulls_since:
|
|
2675
|
+
break
|
|
2676
|
+
if not pulls_since or pull["updated_at"] > pulls_since:
|
|
2677
|
+
pulls[pull["number"]] = pull
|
|
2678
|
+
else:
|
|
2664
2679
|
for pull in retrieve_data(
|
|
2665
2680
|
args, _pulls_template, query_args=query_args, lazy=True
|
|
2666
2681
|
):
|
|
@@ -2669,22 +2684,29 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
|
|
|
2669
2684
|
break
|
|
2670
2685
|
if not pulls_since or pull["updated_at"] > pulls_since:
|
|
2671
2686
|
pulls[pull["number"]] = pull
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2687
|
+
except HTTPError as e:
|
|
2688
|
+
# Repositories with pull requests disabled return HTTP 404 for the
|
|
2689
|
+
# listing endpoint; treat that as "no pull requests" rather than a
|
|
2690
|
+
# fatal error. retrieve_data is lazy here, so the 404 surfaces during
|
|
2691
|
+
# iteration. Only the listing call is guarded — a 404 on an individual
|
|
2692
|
+
# pull's detail fetch below is a different condition and must propagate.
|
|
2693
|
+
if e.code == 404:
|
|
2694
|
+
logger.info("Pull requests are disabled for this repository, skipping")
|
|
2695
|
+
return
|
|
2696
|
+
raise
|
|
2697
|
+
|
|
2698
|
+
if args.include_pull_details:
|
|
2699
|
+
# Replace the summary payload with the full pull detail. Done outside
|
|
2700
|
+
# the disabled-feature guard above so a 404 on a single pull (e.g. one
|
|
2701
|
+
# deleted between listing and fetch) is not mistaken for the whole
|
|
2702
|
+
# feature being disabled, which would discard every collected pull.
|
|
2703
|
+
for number in list(pulls.keys()):
|
|
2704
|
+
if pull_is_due_for_repository_checkpoint(pulls[number]):
|
|
2705
|
+
pulls[number] = retrieve_data(
|
|
2706
|
+
args,
|
|
2707
|
+
_pulls_template + "/{}".format(number),
|
|
2708
|
+
paginated=False,
|
|
2709
|
+
)[0]
|
|
2688
2710
|
|
|
2689
2711
|
logger.info("Saving {0} pull requests to disk".format(len(list(pulls.keys()))))
|
|
2690
2712
|
# Comments from pulls API are only _review_ comments
|
|
@@ -2813,8 +2835,8 @@ def backup_security_advisories(args, repo_cwd, repository, repos_template):
|
|
|
2813
2835
|
|
|
2814
2836
|
try:
|
|
2815
2837
|
_advisories = retrieve_data(args, template)
|
|
2816
|
-
except
|
|
2817
|
-
if
|
|
2838
|
+
except HTTPError as e:
|
|
2839
|
+
if e.code == 404:
|
|
2818
2840
|
logger.info("Security advisories are not available for this repository, skipping")
|
|
2819
2841
|
return
|
|
2820
2842
|
raise
|
|
@@ -2861,8 +2883,8 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
|
|
|
2861
2883
|
template = "{0}/{1}/hooks".format(repos_template, repository["full_name"])
|
|
2862
2884
|
try:
|
|
2863
2885
|
_backup_data(args, "hooks", template, output_file, hook_cwd)
|
|
2864
|
-
except
|
|
2865
|
-
if
|
|
2886
|
+
except HTTPError as e:
|
|
2887
|
+
if e.code == 404:
|
|
2866
2888
|
logger.info("Unable to read hooks, skipping")
|
|
2867
2889
|
else:
|
|
2868
2890
|
raise e
|
|
@@ -3046,8 +3068,10 @@ def fetch_repository(
|
|
|
3046
3068
|
logging_subprocess(git_command, cwd=local_dir)
|
|
3047
3069
|
|
|
3048
3070
|
|
|
3049
|
-
def backup_account(args, output_directory):
|
|
3071
|
+
def backup_account(args, output_directory, authenticated_user=None):
|
|
3050
3072
|
account_cwd = os.path.join(output_directory, "account")
|
|
3073
|
+
if authenticated_user is None:
|
|
3074
|
+
authenticated_user = {"login": None}
|
|
3051
3075
|
|
|
3052
3076
|
if args.include_starred or args.include_everything:
|
|
3053
3077
|
output_file = "{0}/starred.json".format(account_cwd)
|
|
@@ -3057,11 +3081,25 @@ def backup_account(args, output_directory):
|
|
|
3057
3081
|
_backup_data(args, "starred repositories", template, output_file, account_cwd)
|
|
3058
3082
|
|
|
3059
3083
|
if args.include_watched or args.include_everything:
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3084
|
+
# GitHub deprecated /users/{username}/subscriptions; watched
|
|
3085
|
+
# repositories are only available for the authenticated user via
|
|
3086
|
+
# /user/subscriptions.
|
|
3087
|
+
if (
|
|
3088
|
+
not authenticated_user.get("login")
|
|
3089
|
+
or args.user.lower() != authenticated_user["login"].lower()
|
|
3090
|
+
):
|
|
3091
|
+
logger.warning(
|
|
3092
|
+
"Cannot retrieve watched repositories for '%s'. GitHub only allows access to the authenticated user's watched repositories.",
|
|
3093
|
+
args.user,
|
|
3094
|
+
)
|
|
3095
|
+
else:
|
|
3096
|
+
output_file = "{0}/watched.json".format(account_cwd)
|
|
3097
|
+
template = "https://{0}/user/subscriptions".format(
|
|
3098
|
+
get_github_api_host(args)
|
|
3099
|
+
)
|
|
3100
|
+
_backup_data(
|
|
3101
|
+
args, "watched repositories", template, output_file, account_cwd
|
|
3102
|
+
)
|
|
3065
3103
|
|
|
3066
3104
|
if args.include_followers or args.include_everything:
|
|
3067
3105
|
output_file = "{0}/followers.json".format(account_cwd)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
github_backup/__init__.py,sha256=4aEOIqCiMfp1lfhnZ0isYinRITBjjNflprA4nXib3RQ,23
|
|
2
|
+
github_backup/__main__.py,sha256=3yorCiC63maaxbjdtaeAs-G-yAAxKSO3mprhGfa1Fho,271
|
|
3
|
+
github_backup/cli.py,sha256=JTiXPOvB8id8LopREOEd1W_FLvuf9SOZU5buMRPFd9U,2922
|
|
4
|
+
github_backup/github_backup.py,sha256=S5uxqZsYMnOGBYuEX9Dy1sipyUDyaeU7qXoLjkz3nLk,116637
|
|
5
|
+
github_backup/graphql_queries.py,sha256=QBIXcGzGunilMpHfL32cTO_AAzxuQD27QII1V9K_Yw4,4883
|
|
6
|
+
github_backup-0.64.0.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
7
|
+
github_backup-0.64.0.dist-info/METADATA,sha256=XSm6FyyldS86S0nFxbOMcS1lNkP0vVb8nTNLAMdF0J4,32426
|
|
8
|
+
github_backup-0.64.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
9
|
+
github_backup-0.64.0.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
|
|
10
|
+
github_backup-0.64.0.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
11
|
+
github_backup-0.64.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
12
|
+
github_backup-0.64.0.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
github_backup/__init__.py,sha256=jT5y_EapSG_XUwBZcJ6_jD1uAUUE11ZbHJwMsKfUuQM,23
|
|
2
|
-
github_backup/__main__.py,sha256=3yorCiC63maaxbjdtaeAs-G-yAAxKSO3mprhGfa1Fho,271
|
|
3
|
-
github_backup/cli.py,sha256=gPYU0CviuHB19y8RHhcD0p8xHS3UcJbBIK6HVfWazTc,2902
|
|
4
|
-
github_backup/github_backup.py,sha256=KIYfHJxxQn82C2K8RaAl4wmOSClxQWoBW8kFyFZ8pUw,114736
|
|
5
|
-
github_backup/graphql_queries.py,sha256=QBIXcGzGunilMpHfL32cTO_AAzxuQD27QII1V9K_Yw4,4883
|
|
6
|
-
github_backup-0.62.1.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
7
|
-
github_backup-0.62.1.dist-info/METADATA,sha256=5WD559hLSwkWmjiAtOFqZnyv-ycErCS7z1LUSAkdqRs,32426
|
|
8
|
-
github_backup-0.62.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
9
|
-
github_backup-0.62.1.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
|
|
10
|
-
github_backup-0.62.1.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
11
|
-
github_backup-0.62.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
12
|
-
github_backup-0.62.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|