baseuploader.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os.path
  2. from terroroftinytown.tracker.bootstrap import Bootstrap
  3. class BaseUploaderBootstrap(Bootstrap):
  4. def setup_args(self):
  5. super().setup_args()
  6. self.arg_parser.add_argument('directory')
  7. self.arg_parser.add_argument('--title', required=True)
  8. self.arg_parser.add_argument('--identifier', required=True)
  9. def start(self, args=None):
  10. super().start(args=args)
  11. directory = self.args.directory
  12. if not os.path.isdir(directory):
  13. raise Exception('Path is not a directory')
  14. filenames = [os.path.join(directory, filename)
  15. for filename in os.listdir(directory)]
  16. for filename in filenames:
  17. if not os.path.isfile(filename):
  18. raise Exception('{} is not a file'.format(filename))
  19. identifier = self.args.identifier
  20. title = self.args.title
  21. collection = self.config['iaexporter']['collection']
  22. access_key = self.config['iaexporter']['access_key']
  23. secret_key = self.config['iaexporter']['secret_key']
  24. description = self.config['iaexporter']['description']
  25. subject_items = ['urlteam', 'terroroftinytown', 'archiveteam']
  26. for path in filenames:
  27. filename = os.path.basename(path)
  28. assert '/' not in filename
  29. shortener_id = filename.split('.', 1)[0]
  30. subject_items.append(shortener_id)
  31. subject = ';'.join(subject_items)
  32. assert identifier
  33. assert title
  34. assert collection
  35. assert access_key
  36. assert secret_key
  37. assert description
  38. assert subject
  39. self.identifier = identifier
  40. self.title = title
  41. self.collection = collection
  42. self.access_key = access_key
  43. self.secret_key = secret_key
  44. self.description = description
  45. self.filenames = filenames
  46. self.subject = subject
  47. self.upload()
  48. def upload(self):
  49. raise NotImplementedError()