github-backup 0.63.0__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.63.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__":
@@ -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)
@@ -3063,8 +3068,10 @@ def fetch_repository(
3063
3068
  logging_subprocess(git_command, cwd=local_dir)
3064
3069
 
3065
3070
 
3066
- def backup_account(args, output_directory):
3071
+ def backup_account(args, output_directory, authenticated_user=None):
3067
3072
  account_cwd = os.path.join(output_directory, "account")
3073
+ if authenticated_user is None:
3074
+ authenticated_user = {"login": None}
3068
3075
 
3069
3076
  if args.include_starred or args.include_everything:
3070
3077
  output_file = "{0}/starred.json".format(account_cwd)
@@ -3074,11 +3081,25 @@ def backup_account(args, output_directory):
3074
3081
  _backup_data(args, "starred repositories", template, output_file, account_cwd)
3075
3082
 
3076
3083
  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)
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
+ )
3082
3103
 
3083
3104
  if args.include_followers or args.include_everything:
3084
3105
  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.0
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=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,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,,