github-backup 0.63.0__py3-none-any.whl → 0.64.1__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.63.0"
1
+ __version__ = "0.64.1"
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__":
@@ -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
94
 
112
- # keep checking stdout/stderr until the child exits
113
- while child.poll() is None:
114
- check_io()
115
-
116
- check_io() # check again to catch anything after the process exits
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)
@@ -2104,7 +2109,10 @@ def backup_repositories(args, output_directory, repositories):
2104
2109
  )
2105
2110
 
2106
2111
  if repository.get("is_gist"):
2107
- # dump gist information to a file as well
2112
+ # dump gist information to a file as well; the clone may have
2113
+ # been skipped (e.g. DMCA-blocked or empty gist), so make sure
2114
+ # the directory exists
2115
+ mkdir_p(repo_cwd)
2108
2116
  output_file = "{0}/gist.json".format(repo_cwd)
2109
2117
  with codecs.open(output_file, "w", encoding="utf-8") as f:
2110
2118
  json_dump(repository, f)
@@ -3063,8 +3071,10 @@ def fetch_repository(
3063
3071
  logging_subprocess(git_command, cwd=local_dir)
3064
3072
 
3065
3073
 
3066
- def backup_account(args, output_directory):
3074
+ def backup_account(args, output_directory, authenticated_user=None):
3067
3075
  account_cwd = os.path.join(output_directory, "account")
3076
+ if authenticated_user is None:
3077
+ authenticated_user = {"login": None}
3068
3078
 
3069
3079
  if args.include_starred or args.include_everything:
3070
3080
  output_file = "{0}/starred.json".format(account_cwd)
@@ -3074,11 +3084,25 @@ def backup_account(args, output_directory):
3074
3084
  _backup_data(args, "starred repositories", template, output_file, account_cwd)
3075
3085
 
3076
3086
  if args.include_watched or args.include_everything:
3077
- output_file = "{0}/watched.json".format(account_cwd)
3078
- template = "https://{0}/users/{1}/subscriptions".format(
3079
- get_github_api_host(args), args.user
3080
- )
3081
- _backup_data(args, "watched repositories", template, output_file, account_cwd)
3087
+ # GitHub deprecated /users/{username}/subscriptions; watched
3088
+ # repositories are only available for the authenticated user via
3089
+ # /user/subscriptions.
3090
+ if (
3091
+ not authenticated_user.get("login")
3092
+ or args.user.lower() != authenticated_user["login"].lower()
3093
+ ):
3094
+ logger.warning(
3095
+ "Cannot retrieve watched repositories for '%s'. GitHub only allows access to the authenticated user's watched repositories.",
3096
+ args.user,
3097
+ )
3098
+ else:
3099
+ output_file = "{0}/watched.json".format(account_cwd)
3100
+ template = "https://{0}/user/subscriptions".format(
3101
+ get_github_api_host(args)
3102
+ )
3103
+ _backup_data(
3104
+ args, "watched repositories", template, output_file, account_cwd
3105
+ )
3082
3106
 
3083
3107
  if args.include_followers or args.include_everything:
3084
3108
  output_file = "{0}/followers.json".format(account_cwd)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-backup
3
- Version: 0.63.0
3
+ Version: 0.64.1
4
4
  Summary: backup a github user or organization
5
5
  Home-page: http://github.com/josegonzalez/python-github-backup
6
6
  Author: Jose Diaz-Gonzalez
@@ -0,0 +1,12 @@
1
+ github_backup/__init__.py,sha256=T4-vW_ByO6apa0V-uPVXwtgvQiE-ODq0knBtcK_morc,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=nVScdDkx-UVu-c1kU2Sx5z6YlapO_2rFFQYi_3leJ3U,116809
5
+ github_backup/graphql_queries.py,sha256=QBIXcGzGunilMpHfL32cTO_AAzxuQD27QII1V9K_Yw4,4883
6
+ github_backup-0.64.1.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
7
+ github_backup-0.64.1.dist-info/METADATA,sha256=dO_Y2fyGPk7gi12MfanNPjW2P3E7rlO1JmsNjs402ts,32426
8
+ github_backup-0.64.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
9
+ github_backup-0.64.1.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
10
+ github_backup-0.64.1.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
11
+ github_backup-0.64.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
+ github_backup-0.64.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (83.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- github_backup/__init__.py,sha256=Q5rNe5SDDfUHvL3frAP-ZMPMx4ucG3RXhgWSZiluxeM,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=z4YvI61NedaDnE256GB-3pfbaJ5rwpZx4KItgjCaQnk,115713
5
- github_backup/graphql_queries.py,sha256=QBIXcGzGunilMpHfL32cTO_AAzxuQD27QII1V9K_Yw4,4883
6
- github_backup-0.63.0.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
7
- github_backup-0.63.0.dist-info/METADATA,sha256=a6sgqCD4lUo95EkTCN04g4ufzT-RoyfXdD67GlGpJkk,32426
8
- github_backup-0.63.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
9
- github_backup-0.63.0.dist-info/entry_points.txt,sha256=cLPKK7MqC77QVb6HnT2mnyL_f-ciavJG_Y9vVHlCF68,57
10
- github_backup-0.63.0.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
11
- github_backup-0.63.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
12
- github_backup-0.63.0.dist-info/RECORD,,