You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.7 KiB

  1. diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py
  2. index 4ef8b7e..82cbdca 100644
  3. --- a/github_backup/github_backup.py
  4. +++ b/github_backup/github_backup.py
  5. @@ -425,7 +425,7 @@ def get_github_repo_url(args, repository):
  6. return repo_url
  7. -def retrieve_data_gen(args, template, query_args=None, single_request=False):
  8. +def retrieve_data_gen(args, template, query_args=None, single_request=False, optional=False):
  9. auth = get_auth(args, encode=not args.as_app)
  10. query_args = get_query_args(query_args)
  11. per_page = 100
  12. @@ -452,6 +452,11 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
  13. else:
  14. read_error = False
  15. + # Requested data does not exist for this repository, but that was expected.
  16. + # Generate an empty list.
  17. + if status_code == 404 and optional:
  18. + return
  19. +
  20. # be gentle with API request limit and throttle requests if remaining requests getting low
  21. limit_remaining = int(r.headers.get('x-ratelimit-remaining', 0))
  22. if args.throttle_limit and limit_remaining <= args.throttle_limit:
  23. @@ -509,8 +514,8 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False):
  24. break
  25. -def retrieve_data(args, template, query_args=None, single_request=False):
  26. - return list(retrieve_data_gen(args, template, query_args, single_request))
  27. +def retrieve_data(args, template, query_args=None, single_request=False, optional=False):
  28. + return list(retrieve_data_gen(args, template, query_args, single_request, optional))
  29. def get_query_args(query_args=None):
  30. @@ -1011,7 +1016,8 @@ def backup_hooks(args, repo_cwd, repository, repos_template):
  31. 'hooks',
  32. template,
  33. output_file,
  34. - hook_cwd)
  35. + hook_cwd,
  36. + optional=not args.include_hooks)
  37. except SystemExit:
  38. log_info("Unable to read hooks, skipping")
  39. @@ -1158,12 +1164,12 @@ def backup_account(args, output_directory):
  40. account_cwd)
  41. -def _backup_data(args, name, template, output_file, output_directory):
  42. +def _backup_data(args, name, template, output_file, output_directory, optional=False):
  43. skip_existing = args.skip_existing
  44. if not skip_existing or not os.path.exists(output_file):
  45. log_info('Retrieving {0} {1}'.format(args.user, name))
  46. mkdir_p(output_directory)
  47. - data = retrieve_data(args, template)
  48. + data = retrieve_data(args, template, optional=optional)
  49. log_info('Writing {0} {1} to disk'.format(len(data), name))
  50. with codecs.open(output_file, 'w', encoding='utf-8') as f: