ce2fdfacb385325d316951b7d074327098e77ffc
[rarslave2.git] / PAR2Set / NoExtract.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 import logging
5 import PAR2Set.Base
6 import rsutil.common
7
8 #
9 # This is a class that will only repair and delete, not extract
10 #
11 # It will detect sets like the following:
12 # X.par2
13 # X.vol0+1.par2
14 # X.vol1+2.par2
15 # 01.mp3
16 # 02.mp3
17 # 03.mp3
18 #
19 # Where the PAR2 files protect the mp3 files.
20 #
21
22 def detector (name_files, prot_files):
23         EXTRACT_REGEX = rsutil.common.config_get_value ('regular expressions', 'extractable_regex')
24         return not rsutil.common.has_a_match (EXTRACT_REGEX, prot_files)
25
26
27 class NoExtract (PAR2Set.Base.Base):
28
29         def __repr__ (self):
30                 return 'NoExtract'
31
32         def runAll (self):
33
34                 # Repair Stage
35                 ret = self.runVerifyAndRepair ()
36
37                 if ret != rsutil.common.SUCCESS:
38                         logging.critical ('Repair stage failed for: %s' % self.p2file)
39                         return -rsutil.common.ECHECK
40
41                 self.update_matches ()
42
43                 # Deletion Stage
44                 ret = self.runDelete ()
45
46                 if ret != rsutil.common.SUCCESS:
47                         logging.critical ('Deletion stage failed for: %s' % self.p2file)
48                         return -rsutil.common.EDELETE
49
50                 logging.info ('Successfully completed: %s' % self.p2file)
51                 return rsutil.common.SUCCESS
52