Bladeren bron

Show all files found and allow skipping existing

Colin Powell 3 jaren geleden
bovenliggende
commit
f0dfba79a6
2 gewijzigde bestanden met toevoegingen van 20 en 13 verwijderingen
  1. 10 5
      games/management/commands/import_gamelist_xml_file.py
  2. 10 8
      games/utils.py

+ 10 - 5
games/management/commands/import_gamelist_xml_file.py

@@ -15,20 +15,25 @@ class Command(BaseCommand):
         )
         parser.add_argument(
             "--full-scan",
-            type=bool,
-            default=False,
+            action="store_true",
             help="Update all files, even ones we already know about",
         )
 
     def handle(self, *args, **options):
-        games = import_gamelist_file_to_db_for_system(
+        results = import_gamelist_file_to_db_for_system(
             options["system"],
             options["file"],
             options["full_scan"],
         )
-        if games:
+        imported = results["imported"]
+        not_imported = results["not_imported"]
+        if imported:
+            self.stdout.write(
+                self.style.SUCCESS(f"Successfully imported {len(imported)} games")
+            )
+        if not_imported and not imported:
             self.stdout.write(
-                self.style.SUCCESS(f"Successfully imported {len(games)} games")
+                self.style.SUCCESS(f"Found, but did not update {len(not_imported)} games (use --full-scan to update)")
             )
         else:
             self.stdout.write(

+ 10 - 8
games/utils.py

@@ -12,7 +12,7 @@ import logging
 logger = logging.Logger(__name__)
 
 US_STRINGS = ["(u)", "(usa)", "(us)"]
-JP_STRINGS = ["(j)", "japan", "jp"]
+JP_STRINGS = ["(j)", "japan", "jp", "jpn"]
 EU_STRINGS = ["(e)", "eur", "europe", "pal"]
 
 
@@ -28,6 +28,7 @@ def import_gamelist_file_to_db_for_system(
     game_system_slug, file_path=None, full_scan=False
 ):
     imported_games = []
+    not_imported_games = []
     if not file_path:
         file_path = os.path.join(settings.ROMS_DIR, game_system_slug, "gamelist.xml")
     if not os.path.exists(file_path):
@@ -47,7 +48,9 @@ def import_gamelist_file_to_db_for_system(
     for game in games:
         name = game.find("name").text
         obj, created = Game.objects.get_or_create(name=name)
+
         if not created and not full_scan:
+            not_imported_games.append(game)
             logger.info(f"Found game {game} and not doing full scan, so skipping")
             continue
 
@@ -123,7 +126,7 @@ def import_gamelist_file_to_db_for_system(
         obj.save()
 
         imported_games.append(game)
-    return imported_games
+    return {"imported": imported_games, "not_imported": not_imported_games}
 
 
 def export_gamelist_file_to_path_for_system(game_system_slug, file_path=None):
@@ -181,17 +184,13 @@ def skyscrape_console(game_system_slug):
     scraper_site = settings.SCRAPER_SITE
 
     # If the config file is relative, append our base dir
-    print(f"Preparing to scrape game info for {game_system_slug}")
     if scraper_config[0] != "/":
         scraper_config = os.path.join(settings.BASE_DIR, scraper_config)
     if not os.path.exists(scraper_config):
         logger.info(f"Config file not found at {scraper_config}")
-        print(f"Config file not found at {scraper_config}")
         return
-    print(f"Using configuration file from {scraper_config}")
+    logger.info(f"Scraping game info using configuration file from {scraper_config}")
 
-    # scrape_cmd = f"{binary} -c {config_file} -s {site} -u {user}:{password} -t {threads} -f emulationstation -p {game_system_slug}"
-    # load_cmd = f"{binary} -f emulationstation -p {game_system_slug}"
     scrape_output = subprocess.run(
         [
             scraper_binary,
@@ -199,6 +198,8 @@ def skyscrape_console(game_system_slug):
             f"{scraper_config}",
             "-s",
             f"{scraper_site}",
+            "-f",
+            "emulationstation",
             "-p",
             f"{game_system_slug}",
         ],
@@ -210,12 +211,13 @@ def skyscrape_console(game_system_slug):
             "-c",
             f"{scraper_config}",
             "-f",
-            "{scraper_site}",
+            "emulationstation",
             "-p",
             f"{game_system_slug}",
         ],
         capture_output=True,
     )
+    # TODO We should progressively pipe output to a log file instead of this
     print(scrape_output)
     print(load_output)
     return scrape_output, load_output