__main__.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # iagitup - Download github repository and upload it to the Internet Archive with metadata.
  4. # Copyright (C) 2017-2018 Giovanni Damiola
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. from __future__ import unicode_literals
  18. __author__ = "Giovanni Damiola"
  19. __copyright__ = "Copyright 2018, Giovanni Damiola"
  20. __main_name__ = 'iagitup'
  21. __license__ = 'GPLv3'
  22. __status__ = "Production/Stable"
  23. __version__ = "v1.7"
  24. import os
  25. import sys
  26. import shutil
  27. import argparse
  28. import json
  29. from . import iagitup
  30. PROGRAM_DESCRIPTION = 'A tool to archive a GitHub repository to the Internet Archive. \
  31. The script downloads the GitHub repository, creates a git bundle and uploads \
  32. it to archive.org. https://github.com/gdamdam/iagitup'
  33. # Configure argparser
  34. parser = argparse.ArgumentParser(description=PROGRAM_DESCRIPTION)
  35. parser.add_argument('--metadata', '-m', default=None, type=str, required=False, help="custom metadata to add to the archive.org item")
  36. parser.add_argument('--version', '-v', action='version', version=__version__)
  37. parser.add_argument('gitubeurl', type=str, help='[GITHUB REPO] to archive')
  38. args = parser.parse_args()
  39. def main():
  40. iagitup.check_ia_credentials()
  41. URL = args.gitubeurl
  42. custom_metadata = args.metadata
  43. md = None
  44. custom_meta_dict = None
  45. print(":: Downloading %s repository..." % URL)
  46. gh_repo_data, repo_folder = iagitup.repo_download(URL)
  47. # parse supplemental metadata.
  48. if custom_metadata != None:
  49. custom_meta_dict = {}
  50. for meta in custom_metadata.split(','):
  51. k, v = meta.split(':')
  52. custom_meta_dict[k] = v
  53. # upload the repo on IA
  54. identifier, meta, bundle_filename= iagitup.upload_ia(repo_folder, gh_repo_data, custom_meta=custom_meta_dict)
  55. # cleaning
  56. shutil.rmtree(repo_folder)
  57. # output
  58. print("\n:: Upload FINISHED. Item information:")
  59. print("Identifier: %s" % meta['title'])
  60. print("Archived repository URL: \n \thttps://archive.org/details/%s" % identifier)
  61. print("Archived git bundle file: \n \thttps://archive.org/download/{0}/{1}.bundle \n\n".format(identifier, bundle_filename))
  62. if __name__ == '__main__':
  63. main()