1- #!/usr/bin/python
1+ #!/usr/bin/python3 -B
22# -*- coding: utf-8 -*-
3- #
4- # Test the parser for multidisc support.
5- #
63
7- # Copyright (c) 2017 Wintermute0110 <[email protected] > 4+ # Copyright (c) 2017-2021 Wintermute0110 <[email protected] > 85#
96# This program is free software; you can redistribute it and/or modify
107# it under the terms of the GNU General Public License as published by
1512# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1613# GNU General Public License for more details.
1714
18- # --- Python standard library ---
19- from __future__ import unicode_literals
20- import os
21- import pprint
22- import re
23- import sys
15+ # Test the parser for multidisc support.
16+
2417
2518# --- Import AEL modules ---
19+ import os , sys
2620if __name__ == "__main__" and __package__ is None :
2721 path = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' ))
2822 print ('Adding to sys.path {0}' .format (path ))
2923 sys .path .append (path )
24+ from resources .constants import *
3025from resources .utils import *
3126
32- # --- Main ----------------------------------------------------------------------------------------
33- ROM_title_list = [
34- 'Final Fantasy I (USA) (Disc 1 of 2).iso' , # TOSEC
35- 'Final Fantasy I (USA) (Disc 2 of 2).iso' ,
36- 'Final Fantasy II (USA) - (Disc 1 of 2).iso' , # Trurip
37- 'Final Fantasy II (USA) - (Disc 2 of 2).iso' ,
38- 'Final Fantasy VII (USA) (Disc 1).iso' , # Redump
39- 'Final Fantasy VII (USA) (Disc 2).iso' ,
40- 'Tomb Raider (EU).iso' ,
41- '[BIOS] PSX bios (EU).iso'
42- ]
27+ # --- Python standard library ---
28+ import pprint
29+ import re
4330
44- def text_get_ROM_basename_tokens (basename_str ):
31+ # --- BEGIN code in dev-core/test_multidisc_parser.py --------------------------------------------
32+ def get_ROM_basename_tokens (basename_str ):
4533 DEBUG_TOKEN_PARSER = False
4634
4735 # --- Parse ROM base_noext/basename_str into tokens ---
4836 reg_exp = '\[.+?\]|\(.+?\)|\{.+?\}|[^\[\(\{]+'
4937 tokens_raw = re .findall (reg_exp , basename_str )
5038 if DEBUG_TOKEN_PARSER :
51- log_debug ('text_get_ROM_basename_tokens () tokens_raw {0 }' .format (tokens_raw ))
39+ log_debug ('get_ROM_basename_tokens () tokens_raw {}' .format (tokens_raw ))
5240
53- # >> Strip tokens
41+ # Strip tokens
5442 tokens_strip = list ()
5543 for token in tokens_raw : tokens_strip .append (token .strip ())
5644 if DEBUG_TOKEN_PARSER :
57- log_debug ('text_get_ROM_basename_tokens () tokens_strip {0 }' .format (tokens_strip ))
45+ log_debug ('get_ROM_basename_tokens () tokens_strip {}' .format (tokens_strip ))
5846
59- # >> Remove empty tokens ''
47+ # Remove empty tokens ''
6048 tokens_clean = list ()
6149 for token in tokens_strip :
6250 if token : tokens_clean .append (token )
6351 if DEBUG_TOKEN_PARSER :
64- log_debug ('text_get_ROM_basename_tokens () tokens_clean {0 }' .format (tokens_clean ))
52+ log_debug ('get_ROM_basename_tokens () tokens_clean {}' .format (tokens_clean ))
6553
66- # >> Remove '-' tokens from Trurip multidisc names
54+ # Remove '-' tokens from Trurip multidisc names
6755 tokens = list ()
6856 for token in tokens_clean :
6957 if token == '-' : continue
7058 tokens .append (token )
7159 if DEBUG_TOKEN_PARSER :
72- log_debug ('text_get_ROM_basename_tokens () tokens {0 }' .format (tokens ))
60+ log_debug ('get_ROM_basename_tokens () tokens {}' .format (tokens ))
7361
7462 return tokens
7563
@@ -78,14 +66,17 @@ def __init__(self, ROM_FN):
7866 self .ROM_FN = ROM_FN
7967 self .isMultiDisc = False
8068 self .setName = ''
69+ self .discName = ROM_FN .getBase ()
8170 self .extension = ROM_FN .getExt ()
8271 self .order = 0
8372
84- def text_get_multidisc_info (ROM_FN ):
73+ def get_multidisc_info (ROM_FN ):
74+ DEBUG_FUNCTION = False
8575 MDSet = MultiDiscInfo (ROM_FN )
8676
87- # --- Parse ROM base_noext into tokens ---
88- tokens = text_get_ROM_basename_tokens (ROM_FN .getBase_noext ())
77+ # --- Parse ROM basenoext into tokens ---
78+ tokens = get_ROM_basename_tokens (ROM_FN .getBaseNoExt ())
79+ if DEBUG_FUNCTION : log_debug ('tokens: {}' .format (text_type (tokens )))
8980
9081 # --- Check if ROM belongs to a multidisc set and get set name and order ---
9182 # Algortihm:
@@ -95,46 +86,63 @@ def text_get_multidisc_info(ROM_FN):
9586 MultDiscFound = False
9687 for index , token in enumerate (tokens ):
9788 # --- Redump ---
98- matchObj = re .match (r'\(Disc ([0-9]+)\)' , token )
89+ matchObj = re .match (r'\(Dis[ck] ([0-9]+)\)' , token )
9990 if matchObj :
100- log_debug ('text_get_multidisc_info() ### Matched Redump multidisc ROM ###' )
101- tokens_idx = range (0 , len (tokens ))
102- tokens_idx .remove (index )
103- tokens_nodisc_idx = list (tokens_idx )
91+ log_debug ('get_multidisc_info() ### Matched Redump multidisc ROM ###' )
92+ tokens_nodisc_idx = list (range (0 , len (tokens )))
93+ tokens_nodisc_idx .remove (index )
10494 tokens_mdisc = [tokens [x ] for x in tokens_nodisc_idx ]
10595 MultDiscFound = True
10696 break
10797
10898 # --- TOSEC/Trurip ---
109- matchObj = re .match (r'\(Disc ([0-9]+) of ([0-9]+)\)' , token )
99+ matchObj = re .match (r'\(Dis[ck] ([0-9]+) of ([0-9]+)\)' , token )
110100 if matchObj :
111- log_debug ('text_get_multidisc_info() ### Matched TOSEC/Trurip multidisc ROM ###' )
112- tokens_idx = range (0 , len (tokens ))
113- tokens_idx .remove (index )
114- tokens_nodisc_idx = list (tokens_idx )
115- # log_debug('text_get_multidisc_info() tokens_idx = {0}'.format(tokens_idx))
116- # log_debug('text_get_multidisc_info() index = {0}'.format(index))
117- # log_debug('text_get_multidisc_info() tokens_nodisc_idx = {0}'.format(tokens_nodisc_idx))
101+ log_debug ('get_multidisc_info() ### Matched TOSEC/Trurip multidisc ROM ###' )
102+ tokens_nodisc_idx = list (range (0 , len (tokens )))
103+ tokens_nodisc_idx .remove (index )
104+ if DEBUG_FUNCTION :
105+ log_debug ('get_multidisc_info() index = {}' .format (index ))
106+ log_debug ('get_multidisc_info() tokens_nodisc_idx = {}' .format (tokens_nodisc_idx ))
118107 tokens_mdisc = [tokens [x ] for x in tokens_nodisc_idx ]
119108 MultDiscFound = True
120109 break
121110
122111 if MultDiscFound :
123112 MDSet .isMultiDisc = True
124- MDSet .setName = ' ' .join (tokens_mdisc )
113+ MDSet .setName = ' ' .join (tokens_mdisc ) + MDSet . extension
125114 MDSet .order = int (matchObj .group (1 ))
126- log_debug ('text_get_multidisc_info() base_noext "{0}"' .format (ROM_FN .getBase_noext ()))
127- log_debug ('text_get_multidisc_info() tokens {0}' .format (tokens ))
128- log_debug ('text_get_multidisc_info() tokens_mdisc {0}' .format (tokens_mdisc ))
129- log_debug ('text_get_multidisc_info() setName "{0}"' .format (MDSet .setName ))
130- log_debug ('text_get_multidisc_info() extension "{0}"' .format (MDSet .extension ))
131- log_debug ('text_get_multidisc_info() order {0}' .format (MDSet .order ))
115+ log_debug ('get_multidisc_info() base_noext "{}"' .format (ROM_FN .getBaseNoExt ()))
116+ log_debug ('get_multidisc_info() tokens "{}"' .format (tokens ))
117+ log_debug ('get_multidisc_info() tokens_mdisc "{}"' .format (tokens_mdisc ))
118+ log_debug ('get_multidisc_info() setName "{}"' .format (MDSet .setName ))
119+ log_debug ('get_multidisc_info() discName "{}"' .format (MDSet .discName ))
120+ log_debug ('get_multidisc_info() extension "{}"' .format (MDSet .extension ))
121+ log_debug ('get_multidisc_info() order "{}"' .format (MDSet .order ))
132122
133123 return MDSet
124+ # --- END code in dev-core/test_multidisc_parser.py ----------------------------------------------
134125
135- # --- Test multidisc parser -----------------------------------------------------------------------
126+ # --- Main ---------------------------------------------------------------------------------------
127+ ROM_title_list = [
128+ # TOSEC
129+ 'Final Fantasy I (USA) (Disc 1 of 2).iso' ,
130+ 'Final Fantasy I (USA) (Disc 2 of 2).iso' ,
131+ # Trurip
132+ 'Final Fantasy II (USA) - (Disc 1 of 2).iso' ,
133+ 'Final Fantasy II (USA) - (Disc 2 of 2).iso' ,
134+ # Redump
135+ 'Final Fantasy VII (USA) (Disc 1).iso' ,
136+ 'Final Fantasy VII (USA) (Disc 2).iso' ,
137+ # No tags
138+ 'Tomb Raider (EU).iso' ,
139+ '[BIOS] PSX bios (EU).iso' ,
140+ # Cornestone cases
141+ 'Final Fantasy I (Disc 1 of 2) (USA).iso' ,
142+ 'Final Fantasy I (Disc 2 of 2) (USA).iso' ,
143+ ]
136144set_log_level (LOG_DEBUG )
137145for ROM_filename in ROM_title_list :
138- print ('--------> "{0 }"' .format (ROM_filename ))
139- MDSet = text_get_multidisc_info (FileName (ROM_filename ))
146+ print ('--> Processing "{ }"' .format (ROM_filename ))
147+ MDSet = get_multidisc_info (FileName (ROM_filename ))
140148 print ('' )
0 commit comments