import_gamelist_xml_file.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.core.management.base import BaseCommand, CommandError
  2. from games.utils import import_gamelist_file_to_db_for_system
  3. class Command(BaseCommand):
  4. help = "Import all games found in a given gamelist XML file"
  5. def add_arguments(self, parser):
  6. parser.add_argument("system", type=str)
  7. parser.add_argument(
  8. "--file",
  9. action="store_true",
  10. help="Import from specific file",
  11. )
  12. parser.add_argument(
  13. "--full-scan",
  14. action="store_true",
  15. help="Update all files, even ones we already know about",
  16. )
  17. def handle(self, *args, **options):
  18. results = import_gamelist_file_to_db_for_system(
  19. options["system"],
  20. options["file"],
  21. options["full_scan"],
  22. )
  23. imported = results["imported"]
  24. not_imported = results["not_imported"]
  25. if imported:
  26. self.stdout.write(
  27. self.style.SUCCESS(f"Successfully imported {len(imported)} games")
  28. )
  29. if not_imported and not imported:
  30. self.stdout.write(
  31. self.style.SUCCESS(f"Found, but did not update {len(not_imported)} games (use --full-scan to update)")
  32. )
  33. else:
  34. self.stdout.write(
  35. self.style.ERROR(
  36. "No games imported, check for gamelist.xml file or re-run scraper"
  37. )
  38. )