浏览代码

Add option to full scan or just update when importing

Colin Powell 3 年之前
父节点
当前提交
edd6206c2d
共有 2 个文件被更改,包括 15 次插入3 次删除
  1. 7 0
      games/management/commands/import_gamelist_xml_file.py
  2. 8 3
      games/utils.py

+ 7 - 0
games/management/commands/import_gamelist_xml_file.py

@@ -13,11 +13,18 @@ class Command(BaseCommand):
             action="store_true",
             help="Import from specific file",
         )
+        parser.add_argument(
+            "--full-scan",
+            type=bool,
+            default=False,
+            help="Update all files, even ones we already know about",
+        )
 
     def handle(self, *args, **options):
         games = import_gamelist_file_to_db_for_system(
             options["system"],
             options["file"],
+            options["full_scan"],
         )
         if games:
             self.stdout.write(

+ 8 - 3
games/utils.py

@@ -24,7 +24,9 @@ def update_media_root_for_import(file_path):
     return suffix
 
 
-def import_gamelist_file_to_db_for_system(game_system_slug, file_path=None):
+def import_gamelist_file_to_db_for_system(
+    game_system_slug, file_path=None, full_scan=False
+):
     imported_games = []
     if not file_path:
         file_path = os.path.join(settings.ROMS_DIR, game_system_slug, "gamelist.xml")
@@ -44,6 +46,11 @@ def import_gamelist_file_to_db_for_system(game_system_slug, file_path=None):
     games = gamelist.findall("game")
     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:
+            logger.info(f"Found game {game} and not doing full scan, so skipping")
+            continue
+
         english_patched = "patched" in name.lower()
         undub = "undub" in name.lower()
         hack = "hack" in name.lower()
@@ -96,8 +103,6 @@ def import_gamelist_file_to_db_for_system(game_system_slug, file_path=None):
             video_path = update_media_root_for_import(video_path_elem.text)
         marquee_path = update_media_root_for_import(game.find("marquee").text)
 
-        obj, created = Game.objects.get_or_create(name=name)
-
         obj.game_system = game_system
         obj.developer = developer
         obj.publisher = publisher