github-backup 0.44.1__py3-none-any.whl → 0.45.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 +1 -1
- github_backup/github_backup.py +41 -7
- {github_backup-0.44.1.data → github_backup-0.45.1.data}/scripts/github-backup +13 -11
- {github_backup-0.44.1.dist-info → github_backup-0.45.1.dist-info}/METADATA +8 -2
- github_backup-0.45.1.dist-info/RECORD +9 -0
- {github_backup-0.44.1.dist-info → github_backup-0.45.1.dist-info}/WHEEL +1 -1
- github_backup-0.44.1.dist-info/RECORD +0 -9
- {github_backup-0.44.1.dist-info → github_backup-0.45.1.dist-info}/LICENSE.txt +0 -0
- {github_backup-0.44.1.dist-info → github_backup-0.45.1.dist-info}/top_level.txt +0 -0
- {github_backup-0.44.1.dist-info → github_backup-0.45.1.dist-info}/zip-safe +0 -0
github_backup/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.45.1"
|
github_backup/github_backup.py
CHANGED
|
@@ -23,6 +23,7 @@ from urllib.error import HTTPError, URLError
|
|
|
23
23
|
from urllib.parse import quote as urlquote
|
|
24
24
|
from urllib.parse import urlencode, urlparse
|
|
25
25
|
from urllib.request import HTTPRedirectHandler, Request, build_opener, urlopen
|
|
26
|
+
from datetime import datetime
|
|
26
27
|
|
|
27
28
|
try:
|
|
28
29
|
from . import __version__
|
|
@@ -376,6 +377,19 @@ def parse_args(args=None):
|
|
|
376
377
|
dest="include_releases",
|
|
377
378
|
help="include release information, not including assets or binaries",
|
|
378
379
|
)
|
|
380
|
+
parser.add_argument(
|
|
381
|
+
"--latest-releases",
|
|
382
|
+
type=int,
|
|
383
|
+
default=0,
|
|
384
|
+
dest="number_of_latest_releases",
|
|
385
|
+
help="include certain number of the latest releases; only applies if including releases",
|
|
386
|
+
)
|
|
387
|
+
parser.add_argument(
|
|
388
|
+
"--skip-prerelease",
|
|
389
|
+
action="store_true",
|
|
390
|
+
dest="skip_prerelease",
|
|
391
|
+
help="skip prerelease and draft versions; only applies if including releases",
|
|
392
|
+
)
|
|
379
393
|
parser.add_argument(
|
|
380
394
|
"--assets",
|
|
381
395
|
action="store_true",
|
|
@@ -497,7 +511,7 @@ def get_github_host(args):
|
|
|
497
511
|
|
|
498
512
|
|
|
499
513
|
def read_file_contents(file_uri):
|
|
500
|
-
return open(file_uri[len(FILE_URI_PREFIX)
|
|
514
|
+
return open(file_uri[len(FILE_URI_PREFIX):], "rt").readline().strip()
|
|
501
515
|
|
|
502
516
|
|
|
503
517
|
def get_github_repo_url(args, repository):
|
|
@@ -763,14 +777,19 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
|
|
|
763
777
|
return request
|
|
764
778
|
|
|
765
779
|
|
|
766
|
-
def download_file(url, path, auth):
|
|
780
|
+
def download_file(url, path, auth, as_app=False, fine=False):
|
|
767
781
|
# Skip downloading release assets if they already exist on disk so we don't redownload on every sync
|
|
768
782
|
if os.path.exists(path):
|
|
769
783
|
return
|
|
770
784
|
|
|
771
|
-
request =
|
|
785
|
+
request = _construct_request(per_page=100,
|
|
786
|
+
page=1,
|
|
787
|
+
query_args={},
|
|
788
|
+
template=url,
|
|
789
|
+
auth=auth,
|
|
790
|
+
as_app=as_app,
|
|
791
|
+
fine=fine)
|
|
772
792
|
request.add_header("Accept", "application/octet-stream")
|
|
773
|
-
request.add_header("Authorization", "Basic ".encode("ascii") + auth)
|
|
774
793
|
opener = build_opener(S3HTTPRedirectHandler)
|
|
775
794
|
|
|
776
795
|
try:
|
|
@@ -1189,8 +1208,11 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
|
|
|
1189
1208
|
template = "{0}/{1}/hooks".format(repos_template, repository["full_name"])
|
|
1190
1209
|
try:
|
|
1191
1210
|
_backup_data(args, "hooks", template, output_file, hook_cwd)
|
|
1192
|
-
except
|
|
1193
|
-
|
|
1211
|
+
except Exception as e:
|
|
1212
|
+
if "404" in str(e):
|
|
1213
|
+
logger.info("Unable to read hooks, skipping")
|
|
1214
|
+
else:
|
|
1215
|
+
raise e
|
|
1194
1216
|
|
|
1195
1217
|
|
|
1196
1218
|
def backup_releases(args, repo_cwd, repository, repos_template, include_assets=False):
|
|
@@ -1206,8 +1228,18 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
|
|
|
1206
1228
|
release_template = "{0}/{1}/releases".format(repos_template, repository_fullname)
|
|
1207
1229
|
releases = retrieve_data(args, release_template, query_args=query_args)
|
|
1208
1230
|
|
|
1231
|
+
if args.skip_prerelease:
|
|
1232
|
+
releases = [r for r in releases if not r["prerelease"] and not r["draft"]]
|
|
1233
|
+
|
|
1234
|
+
if args.number_of_latest_releases and args.number_of_latest_releases < len(releases):
|
|
1235
|
+
releases.sort(key=lambda item: datetime.strptime(item["created_at"], "%Y-%m-%dT%H:%M:%SZ"),
|
|
1236
|
+
reverse=True)
|
|
1237
|
+
releases = releases[:args.number_of_latest_releases]
|
|
1238
|
+
logger.info("Saving the latest {0} releases to disk".format(len(releases)))
|
|
1239
|
+
else:
|
|
1240
|
+
logger.info("Saving {0} releases to disk".format(len(releases)))
|
|
1241
|
+
|
|
1209
1242
|
# for each release, store it
|
|
1210
|
-
logger.info("Saving {0} releases to disk".format(len(releases)))
|
|
1211
1243
|
for release in releases:
|
|
1212
1244
|
release_name = release["tag_name"]
|
|
1213
1245
|
release_name_safe = release_name.replace("/", "__")
|
|
@@ -1228,6 +1260,8 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
|
|
|
1228
1260
|
asset["url"],
|
|
1229
1261
|
os.path.join(release_assets_cwd, asset["name"]),
|
|
1230
1262
|
get_auth(args),
|
|
1263
|
+
as_app=args.as_app,
|
|
1264
|
+
fine=True if args.token_fine is not None else False
|
|
1231
1265
|
)
|
|
1232
1266
|
|
|
1233
1267
|
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
#!python
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
format='%(asctime)s.%(msecs)03d: %(message)s',
|
|
7
|
-
datefmt='%Y-%m-%dT%H:%M:%S',
|
|
8
|
-
level=logging.INFO
|
|
9
|
-
)
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
10
6
|
|
|
11
7
|
from github_backup.github_backup import (
|
|
12
8
|
backup_account,
|
|
@@ -20,6 +16,12 @@ from github_backup.github_backup import (
|
|
|
20
16
|
retrieve_repositories,
|
|
21
17
|
)
|
|
22
18
|
|
|
19
|
+
logging.basicConfig(
|
|
20
|
+
format="%(asctime)s.%(msecs)03d: %(message)s",
|
|
21
|
+
datefmt="%Y-%m-%dT%H:%M:%S",
|
|
22
|
+
level=logging.INFO,
|
|
23
|
+
)
|
|
24
|
+
|
|
23
25
|
|
|
24
26
|
def main():
|
|
25
27
|
args = parse_args()
|
|
@@ -29,7 +31,7 @@ def main():
|
|
|
29
31
|
|
|
30
32
|
output_directory = os.path.realpath(args.output_directory)
|
|
31
33
|
if not os.path.isdir(output_directory):
|
|
32
|
-
logger.info(
|
|
34
|
+
logger.info("Create output directory {0}".format(output_directory))
|
|
33
35
|
mkdir_p(output_directory)
|
|
34
36
|
|
|
35
37
|
if args.lfs_clone:
|
|
@@ -41,10 +43,10 @@ def main():
|
|
|
41
43
|
logger.root.setLevel(log_level)
|
|
42
44
|
|
|
43
45
|
if not args.as_app:
|
|
44
|
-
logger.info(
|
|
46
|
+
logger.info("Backing up user {0} to {1}".format(args.user, output_directory))
|
|
45
47
|
authenticated_user = get_authenticated_user(args)
|
|
46
48
|
else:
|
|
47
|
-
authenticated_user = {
|
|
49
|
+
authenticated_user = {"login": None}
|
|
48
50
|
|
|
49
51
|
repositories = retrieve_repositories(args, authenticated_user)
|
|
50
52
|
repositories = filter_repositories(args, repositories)
|
|
@@ -52,7 +54,7 @@ def main():
|
|
|
52
54
|
backup_account(args, output_directory)
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
if __name__ ==
|
|
57
|
+
if __name__ == "__main__":
|
|
56
58
|
try:
|
|
57
59
|
main()
|
|
58
60
|
except Exception as e:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: github-backup
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.45.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
|
|
@@ -67,7 +67,9 @@ CLI Help output::
|
|
|
67
67
|
[-P] [-F] [--prefer-ssh] [-v]
|
|
68
68
|
[--keychain-name OSX_KEYCHAIN_ITEM_NAME]
|
|
69
69
|
[--keychain-account OSX_KEYCHAIN_ITEM_ACCOUNT]
|
|
70
|
-
[--releases] [--
|
|
70
|
+
[--releases] [--latest-releases NUMBER_OF_LATEST_RELEASES]
|
|
71
|
+
[--skip-prerelease] [--assets]
|
|
72
|
+
[--exclude [REPOSITORY [REPOSITORY ...]]
|
|
71
73
|
[--throttle-limit THROTTLE_LIMIT] [--throttle-pause THROTTLE_PAUSE]
|
|
72
74
|
USER
|
|
73
75
|
|
|
@@ -142,6 +144,10 @@ CLI Help output::
|
|
|
142
144
|
keychain that holds the personal access or OAuth token
|
|
143
145
|
--releases include release information, not including assets or
|
|
144
146
|
binaries
|
|
147
|
+
--latest-releases NUMBER_OF_LATEST_RELEASES
|
|
148
|
+
include certain number of the latest releases;
|
|
149
|
+
only applies if including releases
|
|
150
|
+
--skip-prerelease skip prerelease and draft versions; only applies if including releases
|
|
145
151
|
--assets include assets alongside release information; only
|
|
146
152
|
applies if including releases
|
|
147
153
|
--exclude [REPOSITORY [REPOSITORY ...]]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
github_backup/__init__.py,sha256=k6XkSrvyDuFc67Nxl_RWyH21_ppyiOXAjH6tmCnm1aM,23
|
|
2
|
+
github_backup/github_backup.py,sha256=EiYRWJZI5VK-T3QREblmg3YH7dAY74t1zRd5c5yNFsk,48052
|
|
3
|
+
github_backup-0.45.1.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
|
|
4
|
+
github_backup-0.45.1.dist-info/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
5
|
+
github_backup-0.45.1.dist-info/METADATA,sha256=ur9wzktX3GKicuJud9Roo13T7N2w3HpJ7waZPPqAPRo,18970
|
|
6
|
+
github_backup-0.45.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
7
|
+
github_backup-0.45.1.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
8
|
+
github_backup-0.45.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
+
github_backup-0.45.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
github_backup/__init__.py,sha256=ZDD-b1AJzaso91jggbcesxnf2F7iAueyqfbMaJ4TrtA,23
|
|
2
|
-
github_backup/github_backup.py,sha256=vljpTYUGna4K8jG8hkCsvemkOPyCwhQU0kg6WyBaWJo,46644
|
|
3
|
-
github_backup-0.44.1.data/scripts/github-backup,sha256=UXvwQ9ouaV6W_jXSgF_4WitYB3nbwwDjdSrDFiaLogM,1533
|
|
4
|
-
github_backup-0.44.1.dist-info/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
|
|
5
|
-
github_backup-0.44.1.dist-info/METADATA,sha256=tPQX4Ixa88ZGs1fbXR-CJ6cl1TAs4uwTgX85c5XUAW8,18581
|
|
6
|
-
github_backup-0.44.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
7
|
-
github_backup-0.44.1.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
|
|
8
|
-
github_backup-0.44.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
-
github_backup-0.44.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|