github-backup 0.51.1__py3-none-any.whl → 0.51.3__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/github_backup.py +66 -44
- {github_backup-0.51.1.dist-info → github_backup-0.51.3.dist-info}/METADATA +1 -1
- github_backup-0.51.3.dist-info/RECORD +9 -0
- github_backup-0.51.1.dist-info/RECORD +0 -9
- {github_backup-0.51.1.data → github_backup-0.51.3.data}/scripts/github-backup +0 -0
- {github_backup-0.51.1.dist-info → github_backup-0.51.3.dist-info}/WHEEL +0 -0
- {github_backup-0.51.1.dist-info → github_backup-0.51.3.dist-info}/licenses/LICENSE.txt +0 -0
- {github_backup-0.51.1.dist-info → github_backup-0.51.3.dist-info}/top_level.txt +0 -0
- {github_backup-0.51.1.dist-info → github_backup-0.51.3.dist-info}/zip-safe +0 -0
github_backup/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.51.
|
|
1
|
+
__version__ = "0.51.3"
|
github_backup/github_backup.py
CHANGED
|
@@ -37,22 +37,33 @@ FNULL = open(os.devnull, "w")
|
|
|
37
37
|
FILE_URI_PREFIX = "file://"
|
|
38
38
|
logger = logging.getLogger(__name__)
|
|
39
39
|
|
|
40
|
+
# Setup SSL context with fallback chain
|
|
40
41
|
https_ctx = ssl.create_default_context()
|
|
41
|
-
if
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
if https_ctx.get_ca_certs():
|
|
43
|
+
# Layer 1: Certificates pre-loaded from system (file-based)
|
|
44
|
+
pass
|
|
45
|
+
else:
|
|
46
|
+
paths = ssl.get_default_verify_paths()
|
|
47
|
+
if (paths.cafile and os.path.exists(paths.cafile)) or (
|
|
48
|
+
paths.capath and os.path.exists(paths.capath)
|
|
49
|
+
):
|
|
50
|
+
# Layer 2: Cert paths exist, will be lazy-loaded on first use (directory-based)
|
|
51
|
+
pass
|
|
52
|
+
else:
|
|
53
|
+
# Layer 3: Try certifi package as optional fallback
|
|
54
|
+
try:
|
|
55
|
+
import certifi
|
|
56
|
+
|
|
57
|
+
https_ctx = ssl.create_default_context(cafile=certifi.where())
|
|
58
|
+
except ImportError:
|
|
59
|
+
# All layers failed - no certificates available anywhere
|
|
60
|
+
sys.exit(
|
|
61
|
+
"\nERROR: No CA certificates found. Cannot connect to GitHub over SSL.\n\n"
|
|
62
|
+
"Solutions you can explore:\n"
|
|
63
|
+
" 1. pip install certifi\n"
|
|
64
|
+
" 2. Alpine: apk add ca-certificates\n"
|
|
65
|
+
" 3. Debian/Ubuntu: apt-get install ca-certificates\n\n"
|
|
66
|
+
)
|
|
56
67
|
|
|
57
68
|
|
|
58
69
|
def logging_subprocess(
|
|
@@ -581,27 +592,26 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
|
|
581
592
|
auth = get_auth(args, encode=not args.as_app)
|
|
582
593
|
query_args = get_query_args(query_args)
|
|
583
594
|
per_page = 100
|
|
584
|
-
|
|
595
|
+
next_url = None
|
|
585
596
|
|
|
586
597
|
while True:
|
|
587
598
|
if single_request:
|
|
588
|
-
|
|
599
|
+
request_per_page = None
|
|
589
600
|
else:
|
|
590
|
-
|
|
591
|
-
request_page, request_per_page = page, per_page
|
|
601
|
+
request_per_page = per_page
|
|
592
602
|
|
|
593
603
|
request = _construct_request(
|
|
594
604
|
request_per_page,
|
|
595
|
-
request_page,
|
|
596
605
|
query_args,
|
|
597
|
-
template,
|
|
606
|
+
next_url or template,
|
|
598
607
|
auth,
|
|
599
608
|
as_app=args.as_app,
|
|
600
609
|
fine=True if args.token_fine is not None else False,
|
|
601
610
|
) # noqa
|
|
602
|
-
r, errors = _get_response(request, auth, template)
|
|
611
|
+
r, errors = _get_response(request, auth, next_url or template)
|
|
603
612
|
|
|
604
613
|
status_code = int(r.getcode())
|
|
614
|
+
|
|
605
615
|
# Check if we got correct data
|
|
606
616
|
try:
|
|
607
617
|
response = json.loads(r.read().decode("utf-8"))
|
|
@@ -633,15 +643,14 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
|
|
633
643
|
retries += 1
|
|
634
644
|
time.sleep(5)
|
|
635
645
|
request = _construct_request(
|
|
636
|
-
|
|
637
|
-
page,
|
|
646
|
+
request_per_page,
|
|
638
647
|
query_args,
|
|
639
|
-
template,
|
|
648
|
+
next_url or template,
|
|
640
649
|
auth,
|
|
641
650
|
as_app=args.as_app,
|
|
642
651
|
fine=True if args.token_fine is not None else False,
|
|
643
652
|
) # noqa
|
|
644
|
-
r, errors = _get_response(request, auth, template)
|
|
653
|
+
r, errors = _get_response(request, auth, next_url or template)
|
|
645
654
|
|
|
646
655
|
status_code = int(r.getcode())
|
|
647
656
|
try:
|
|
@@ -671,7 +680,16 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
|
|
|
671
680
|
if type(response) is list:
|
|
672
681
|
for resp in response:
|
|
673
682
|
yield resp
|
|
674
|
-
|
|
683
|
+
# Parse Link header for next page URL (cursor-based pagination)
|
|
684
|
+
link_header = r.headers.get("Link", "")
|
|
685
|
+
next_url = None
|
|
686
|
+
if link_header:
|
|
687
|
+
# Parse Link header: <https://api.github.com/...?per_page=100&after=cursor>; rel="next"
|
|
688
|
+
for link in link_header.split(","):
|
|
689
|
+
if 'rel="next"' in link:
|
|
690
|
+
next_url = link[link.find("<") + 1:link.find(">")]
|
|
691
|
+
break
|
|
692
|
+
if not next_url:
|
|
675
693
|
break
|
|
676
694
|
elif type(response) is dict and single_request:
|
|
677
695
|
yield response
|
|
@@ -724,22 +742,27 @@ def _get_response(request, auth, template):
|
|
|
724
742
|
|
|
725
743
|
|
|
726
744
|
def _construct_request(
|
|
727
|
-
per_page,
|
|
745
|
+
per_page, query_args, template, auth, as_app=None, fine=False
|
|
728
746
|
):
|
|
729
|
-
|
|
730
|
-
if
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
if query_args:
|
|
735
|
-
all_query_args.update(query_args)
|
|
736
|
-
|
|
737
|
-
request_url = template
|
|
738
|
-
if all_query_args:
|
|
739
|
-
querystring = urlencode(all_query_args)
|
|
740
|
-
request_url = template + "?" + querystring
|
|
747
|
+
# If template is already a full URL with query params (from Link header), use it directly
|
|
748
|
+
if "?" in template and template.startswith("http"):
|
|
749
|
+
request_url = template
|
|
750
|
+
# Extract query string for logging
|
|
751
|
+
querystring = template.split("?", 1)[1]
|
|
741
752
|
else:
|
|
742
|
-
|
|
753
|
+
# Build URL with query parameters
|
|
754
|
+
all_query_args = {}
|
|
755
|
+
if per_page:
|
|
756
|
+
all_query_args["per_page"] = per_page
|
|
757
|
+
if query_args:
|
|
758
|
+
all_query_args.update(query_args)
|
|
759
|
+
|
|
760
|
+
request_url = template
|
|
761
|
+
if all_query_args:
|
|
762
|
+
querystring = urlencode(all_query_args)
|
|
763
|
+
request_url = template + "?" + querystring
|
|
764
|
+
else:
|
|
765
|
+
querystring = ""
|
|
743
766
|
|
|
744
767
|
request = Request(request_url)
|
|
745
768
|
if auth is not None:
|
|
@@ -755,7 +778,7 @@ def _construct_request(
|
|
|
755
778
|
"Accept", "application/vnd.github.machine-man-preview+json"
|
|
756
779
|
)
|
|
757
780
|
|
|
758
|
-
log_url = template
|
|
781
|
+
log_url = template if "?" not in template else template.split("?")[0]
|
|
759
782
|
if querystring:
|
|
760
783
|
log_url += "?" + querystring
|
|
761
784
|
logger.info("Requesting {}".format(log_url))
|
|
@@ -832,8 +855,7 @@ def download_file(url, path, auth, as_app=False, fine=False):
|
|
|
832
855
|
return
|
|
833
856
|
|
|
834
857
|
request = _construct_request(
|
|
835
|
-
per_page=
|
|
836
|
-
page=1,
|
|
858
|
+
per_page=None,
|
|
837
859
|
query_args={},
|
|
838
860
|
template=url,
|
|
839
861
|
auth=auth,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
github_backup/__init__.py,sha256=sAWIo0cwKX_KPS0IfEe_3-fBMoQG8DTarkiPtqUIFPA,23
|
|
2
|
+
github_backup/github_backup.py,sha256=mNTcVRvdVEt5M8LNCO6zXV0c7g2w_Mm8Rb4Cv6jo2yA,76237
|
|
3
|
+
github_backup-0.51.3.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
|
|
4
|
+
github_backup-0.51.3.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
5
|
+
github_backup-0.51.3.dist-info/METADATA,sha256=JstsidKzhrLnOHESpVtf2-s4a_6oUCb8y_PIMiCVfas,21544
|
|
6
|
+
github_backup-0.51.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
github_backup-0.51.3.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
8
|
+
github_backup-0.51.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
+
github_backup-0.51.3.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
github_backup/__init__.py,sha256=1aQCHIs4QPNUtw_wChzJwhINvlLDSxS3S3qxxd-DKeU,23
|
|
2
|
-
github_backup/github_backup.py,sha256=2N0crWKzRfkb5ZOlI5pn2NRxSXOmApmdB68noATWAbk,74783
|
|
3
|
-
github_backup-0.51.1.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
|
|
4
|
-
github_backup-0.51.1.dist-info/licenses/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
5
|
-
github_backup-0.51.1.dist-info/METADATA,sha256=rjm9_2D5ivEA1y9NUJhVbKA3C113jd0Jq3ATaGrvdhA,21544
|
|
6
|
-
github_backup-0.51.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
github_backup-0.51.1.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
8
|
-
github_backup-0.51.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
-
github_backup-0.51.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|