Add NoExtract detector
[rarslave2.git] / RarslaveDetector.py
index 9f14261..0895e46 100644 (file)
@@ -1,15 +1,16 @@
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
 #!/usr/bin/env python
 # vim: set ts=4 sts=4 sw=4 textwidth=92:
 
-from RarslaveCommon import *
+import rsutil.common
 
 # PAR2Set-derived types
 
 # PAR2Set-derived types
-import PAR2Set_JOIN
-import PAR2Set_ZIP
-import PAR2Set_OLDRAR
-import PAR2Set_NEWRAR
-import PAR2Set_EF_OLDRAR
-import PAR2Set_EF_NEWRAR
+import PAR2Set.Join
+import PAR2Set.ZIP
+import PAR2Set.OldRAR
+import PAR2Set.NewRAR
+import PAR2Set.ExtractFirstOldRAR
+import PAR2Set.ExtractFirstNewRAR
+import PAR2Set.NoExtract
 
 import logging
 
 
 import logging
 
@@ -18,12 +19,13 @@ class RarslaveDetector (object):
        # A tuple of tuples with the following definition:
        # (TYPE_NAME, DETECTION_FUNCTION, PAR2Set-derived class)
 
        # A tuple of tuples with the following definition:
        # (TYPE_NAME, DETECTION_FUNCTION, PAR2Set-derived class)
 
-       TYPES = (       (PAR2Set_JOIN.detect_JOIN, PAR2Set_JOIN.PAR2Set_JOIN),
-                               (PAR2Set_ZIP.detect_ZIP, PAR2Set_ZIP.PAR2Set_ZIP),
-                               (PAR2Set_OLDRAR.detect_OLDRAR, PAR2Set_OLDRAR.PAR2Set_OLDRAR),
-                               (PAR2Set_NEWRAR.detect_NEWRAR, PAR2Set_NEWRAR.PAR2Set_NEWRAR),
-                               (PAR2Set_EF_OLDRAR.detect_EF_OLDRAR, PAR2Set_EF_OLDRAR.PAR2Set_EF_OLDRAR),
-                               (PAR2Set_EF_NEWRAR.detect_EF_NEWRAR, PAR2Set_EF_NEWRAR.PAR2Set_EF_NEWRAR),
+       TYPES = (       (PAR2Set.Join.detector,   PAR2Set.Join.Join),
+                               (PAR2Set.ZIP.detector,    PAR2Set.ZIP.ZIP),
+                               (PAR2Set.OldRAR.detector, PAR2Set.OldRAR.OldRAR),
+                               (PAR2Set.NewRAR.detector, PAR2Set.NewRAR.NewRAR),
+                               (PAR2Set.ExtractFirstOldRAR.detector, PAR2Set.ExtractFirstOldRAR.ExtractFirstOldRAR),
+                               (PAR2Set.ExtractFirstNewRAR.detector, PAR2Set.ExtractFirstNewRAR.ExtractFirstNewRAR),
+                               (PAR2Set.NoExtract.detector, PAR2Set.NoExtract.NoExtract),
                        )
 
        def __init__ (self, dir, p2file):
                        )
 
        def __init__ (self, dir, p2file):
@@ -31,16 +33,16 @@ class RarslaveDetector (object):
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
                # The real "meat" of the class
                self.dir = dir
                self.p2file = p2file
-               self.basename = get_basename (p2file)
+               self.basename = rsutil.common.get_basename (p2file)
 
                # Find files that match by name only
 
                # Find files that match by name only
-               self.name_matched_files = find_name_matches (self.dir, self.basename)
+               self.name_matched_files = rsutil.common.find_name_matches (self.dir, self.basename)
 
                # Find all par2 files for this set using name matches
 
                # Find all par2 files for this set using name matches
-               self.all_p2files = find_par2_files (self.name_matched_files)
+               self.all_p2files = rsutil.common.find_par2_files (self.name_matched_files)
 
                # Try to get the protected files for this set
 
                # Try to get the protected files for this set
-               self.prot_matched_files = parse_all_par2 (self.dir, self.p2file, self.all_p2files)
+               self.prot_matched_files = rsutil.common.parse_all_par2 (self.dir, self.p2file, self.all_p2files)
 
        def runMatchingTypes (self):
                # Now tries to run every type of PAR2Set-derived class for which the detector
 
        def runMatchingTypes (self):
                # Now tries to run every type of PAR2Set-derived class for which the detector
@@ -62,7 +64,7 @@ class RarslaveDetector (object):
 
                                # If something already worked, there is no need to continue,
                                # since we've already finished!
 
                                # If something already worked, there is no need to continue,
                                # since we've already finished!
-                               if ret == SUCCESS:
+                               if ret == rsutil.common.SUCCESS:
                                        break
                                else:
                                        logging.error ('Detected type failed for: %s' % self.p2file)
                                        break
                                else:
                                        logging.error ('Detected type failed for: %s' % self.p2file)
@@ -73,10 +75,10 @@ class RarslaveDetector (object):
                        logging.debug ('The following information will help in writing a detector:')
                        logging.debug ('name_matches: %s' % self.name_matched_files)
                        logging.debug ('prot_matches: %s' % self.prot_matched_files)
                        logging.debug ('The following information will help in writing a detector:')
                        logging.debug ('name_matches: %s' % self.name_matched_files)
                        logging.debug ('prot_matches: %s' % self.prot_matched_files)
-                       return -EDETECT
+                       return -rsutil.common.EDETECT
 
                # Make sure that something worked
 
                # Make sure that something worked
-               if ret != SUCCESS:
+               if ret != rsutil.common.SUCCESS:
                        logging.critical ('All types failed for: %s' % self.p2file)
 
                return ret
                        logging.critical ('All types failed for: %s' % self.p2file)
 
                return ret