2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
4 from RarslaveCommon import *
6 # PAR2Set-derived types
11 import PAR2Set_EF_OLDRAR
12 import PAR2Set_EF_NEWRAR
14 class RarslaveDetector (object):
16 # A tuple of tuples with the following definition:
17 # (TYPE_NAME, DETECTION_FUNCTION, PAR2Set-derived class)
19 TYPES = ( (PAR2Set_JOIN.detect_JOIN, PAR2Set_JOIN.PAR2Set_JOIN),
20 (PAR2Set_ZIP.detect_ZIP, PAR2Set_ZIP.PAR2Set_ZIP),
21 (PAR2Set_OLDRAR.detect_OLDRAR, PAR2Set_OLDRAR.PAR2Set_OLDRAR),
22 (PAR2Set_NEWRAR.detect_NEWRAR, PAR2Set_NEWRAR.PAR2Set_NEWRAR),
23 (PAR2Set_EF_OLDRAR.detect_EF_OLDRAR, PAR2Set_EF_OLDRAR.PAR2Set_EF_OLDRAR),
24 (PAR2Set_EF_NEWRAR.detect_EF_NEWRAR, PAR2Set_EF_NEWRAR.PAR2Set_EF_NEWRAR),
27 def __init__ (self, dir, p2file):
29 # The real "meat" of the class
32 self.basename = get_basename (p2file)
34 # Find files that match by name only
35 self.name_matched_files = find_name_matches (self.dir, self.basename)
37 # Find all par2 files for this set using name matches
38 self.all_p2files = find_par2_files (self.name_matched_files)
40 # Try to get the protected files for this set
41 self.prot_matched_files = parse_all_par2 (self.dir, self.p2file, self.all_p2files)
43 def runMatchingTypes (self):
44 # Now tries to run every type of PAR2Set-derived class for which the detector
45 # detects that the class is valid.
49 for (detector, classname) in self.TYPES:
50 if detector (self.name_matched_files, self.prot_matched_files):
51 # The detector matched, so we're up and running!
53 p2set = classname (self.dir, self.p2file)
56 debugMessage ('Detected type: %s' % p2set)
58 # Try to have rarslave do it's thing
61 # If something already worked, there is no need to continue,
62 # since we've already finished!
66 fatalMessage ('Detected type failed for: %s' % self.p2file)
68 # Make sure we detected at least one valid type
70 fatalMessage ('Unable to determine type: %s' % self.p2file)
71 verboseMessage ('The following information will help in writing a detector:')
72 verboseMessage ('name_matches: %s' % self.name_matched_files)
73 verboseMessage ('prot_matches: %s' % self.prot_matched_files)
76 # Make sure that something worked
78 fatalMessage ('All types failed for: %s' % self.p2file)
85 if __name__ == '__main__':