github-backup 0.44.1__py3-none-any.whl → 0.45.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.44.1"
1
+ __version__ = "0.45.0"
@@ -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) :], "rt").readline().strip()
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):
@@ -1189,8 +1203,11 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
1189
1203
  template = "{0}/{1}/hooks".format(repos_template, repository["full_name"])
1190
1204
  try:
1191
1205
  _backup_data(args, "hooks", template, output_file, hook_cwd)
1192
- except SystemExit:
1193
- logger.info("Unable to read hooks, skipping")
1206
+ except Exception as e:
1207
+ if "404" in str(e):
1208
+ logger.info("Unable to read hooks, skipping")
1209
+ else:
1210
+ raise e
1194
1211
 
1195
1212
 
1196
1213
  def backup_releases(args, repo_cwd, repository, repos_template, include_assets=False):
@@ -1206,8 +1223,18 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
1206
1223
  release_template = "{0}/{1}/releases".format(repos_template, repository_fullname)
1207
1224
  releases = retrieve_data(args, release_template, query_args=query_args)
1208
1225
 
1226
+ if args.skip_prerelease:
1227
+ releases = [r for r in releases if not r["prerelease"] and not r["draft"]]
1228
+
1229
+ if args.number_of_latest_releases and args.number_of_latest_releases < len(releases):
1230
+ releases.sort(key=lambda item: datetime.strptime(item["created_at"], "%Y-%m-%dT%H:%M:%SZ"),
1231
+ reverse=True)
1232
+ releases = releases[:args.number_of_latest_releases]
1233
+ logger.info("Saving the latest {0} releases to disk".format(len(releases)))
1234
+ else:
1235
+ logger.info("Saving {0} releases to disk".format(len(releases)))
1236
+
1209
1237
  # for each release, store it
1210
- logger.info("Saving {0} releases to disk".format(len(releases)))
1211
1238
  for release in releases:
1212
1239
  release_name = release["tag_name"]
1213
1240
  release_name_safe = release_name.replace("/", "__")
@@ -1,12 +1,8 @@
1
1
  #!python
2
2
 
3
- import os, sys, logging
4
-
5
- logging.basicConfig(
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('Create output directory {0}'.format(output_directory))
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('Backing up user {0} to {1}'.format(args.user, output_directory))
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 = {'login': None}
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__ == '__main__':
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.44.1
3
+ Version: 0.45.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
@@ -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] [--assets] [--exclude [REPOSITORY [REPOSITORY ...]]
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=p2Xvd610sh3godS2s3KpBCKAbfwwnEs-mH0Q6wQI5LE,23
2
+ github_backup/github_backup.py,sha256=4DX06Tbj6QtSRgEsWBNWqV1cvrryZBvf7RUmxDlG2dg,47687
3
+ github_backup-0.45.0.data/scripts/github-backup,sha256=I79TNA67phytRmI9nm_LlD9h2zauXFOsOn9tYyAy9pU,1546
4
+ github_backup-0.45.0.dist-info/LICENSE.txt,sha256=ML-pLyn1qtAKo_DHMcQ8-p7k3f8cp-IR-mf5B49R2rk,1085
5
+ github_backup-0.45.0.dist-info/METADATA,sha256=fRe-Ut7k4UVvklGr4nWUNPowGMQoKvnaF5wGZLrx16o,18970
6
+ github_backup-0.45.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
7
+ github_backup-0.45.0.dist-info/top_level.txt,sha256=Za6fKRAlxZ0b3ZBH_osPqklLe14LetdNAkvAQANT2AA,14
8
+ github_backup-0.45.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
9
+ github_backup-0.45.0.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,,