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
16 class RarslaveDetector (object):
18 # A tuple of tuples with the following definition:
19 # (TYPE_NAME, DETECTION_FUNCTION, PAR2Set-derived class)
21 TYPES = ( (PAR2Set_JOIN.detect_JOIN, PAR2Set_JOIN.PAR2Set_JOIN),
22 (PAR2Set_ZIP.detect_ZIP, PAR2Set_ZIP.PAR2Set_ZIP),
23 (PAR2Set_OLDRAR.detect_OLDRAR, PAR2Set_OLDRAR.PAR2Set_OLDRAR),
24 (PAR2Set_NEWRAR.detect_NEWRAR, PAR2Set_NEWRAR.PAR2Set_NEWRAR),
25 (PAR2Set_EF_OLDRAR.detect_EF_OLDRAR, PAR2Set_EF_OLDRAR.PAR2Set_EF_OLDRAR),
26 (PAR2Set_EF_NEWRAR.detect_EF_NEWRAR, PAR2Set_EF_NEWRAR.PAR2Set_EF_NEWRAR),
29 def __init__ (self, dir, p2file):
31 # The real "meat" of the class
34 self.basename = get_basename (p2file)
36 # Find files that match by name only
37 self.name_matched_files = find_name_matches (self.dir, self.basename)
39 # Find all par2 files for this set using name matches
40 self.all_p2files = find_par2_files (self.name_matched_files)
42 # Try to get the protected files for this set
43 self.prot_matched_files = parse_all_par2 (self.dir, self.p2file, self.all_p2files)
45 def runMatchingTypes (self):
46 # Now tries to run every type of PAR2Set-derived class for which the detector
47 # detects that the class is valid.
51 for (detector, classname) in self.TYPES:
52 if detector (self.name_matched_files, self.prot_matched_files):
53 # The detector matched, so we're up and running!
55 p2set = classname (self.dir, self.p2file)
58 logging.debug ('Detected type: %s' % p2set)
60 # Try to have rarslave do it's thing
63 # If something already worked, there is no need to continue,
64 # since we've already finished!
68 logging.error ('Detected type failed for: %s' % self.p2file)
70 # Make sure we detected at least one valid type
72 logging.warning ('Unable to determine type: %s' % self.p2file)
73 logging.debug ('The following information will help in writing a detector:')
74 logging.debug ('name_matches: %s' % self.name_matched_files)
75 logging.debug ('prot_matches: %s' % self.prot_matched_files)
78 # Make sure that something worked
80 logging.critical ('All types failed for: %s' % self.p2file)
87 if __name__ == '__main__':