Add support for Join sets where the parity protects the split files
[rarslave2.git] / PAR2Set / NewRAR.py
index 7c8f25b..fc55d1c 100644 (file)
@@ -40,37 +40,23 @@ __license__   = "GNU GPL v2 (or, at your option, any later version)"
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-import os
-import PAR2Set.Base
-import rsutil.common
+from PAR2Set import Base, utils
 
+class NewRAR(Base):
 
-def detector (name_files, prot_files):
-       """Detector for the NewRAR type"""
+    ############################################################################
 
-       return rsutil.common.has_a_match ('^.*\.part0*1\.rar$', prot_files)
+    def detect(self):
+        if not utils.hasAMatch('^.*\.part0*1\.rar$', self.protectedFiles):
+            raise TypeError
 
+    ############################################################################
 
-class NewRAR (PAR2Set.Base.Base):
+    def extract(self):
+        files = utils.findMatches('^.*\.part0*1\.rar$', self.protectedFiles)
 
-       """Class for new-style rar sets"""
+        for f in files:
+            utils.runCommand(['unrar', 'x', '-o+', f], self.directory)
 
-       def __repr__ (self):
-               return 'NEWRAR'
-
-       def find_extraction_heads (self):
-               """Find the files to start extraction from. These end in '.part0*1.rar'"""
-
-               return rsutil.common.find_matches ('^.*\.part0*1\.rar$', self.all_files)
-
-       def extraction_function (self, file, todir):
-               """Extract a single rar file to the directory todir.
-
-                  file -- the file to be extracted
-                  todir -- the directory to extract into"""
-
-               assert os.path.isfile (file)
-               assert os.path.isdir (todir)
-
-               rsutil.common.run_command(['unrar', 'x', '-o+', file], todir)
+    ############################################################################