9b1c68a855d571c4e8c9629e94baa41a95077300
[rarslave2.git] / PAR2Set / OldRAR.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=92:
3
4 import PAR2Set.Base
5 import rsutil.common
6
7 #
8 # This is an old-style rar type
9 #
10 # It will detect sets like the following:
11 # X.par2
12 # X.vol0+1.par2
13 # X.vol1+2.par2
14 # X.rar
15 # X.r00
16 # X.r01
17 #
18 # OR
19 #
20 # ABC.rar
21 # ABC.r00
22 # ABC.r01
23 #
24 # Where the PAR2 files protect all files that do not match in basename
25 # with the PAR2 file itself.
26 #
27
28 def detector (name_files, prot_files):
29         return rsutil.common.has_a_match ('^.*\.r00$', prot_files)
30
31
32 class OldRAR (PAR2Set.Base.Base):
33
34         def __repr__ (self):
35                 return 'OLDRAR'
36
37         def find_extraction_heads (self):
38                 return rsutil.common.find_matches ('^.*\.rar', self.all_files)
39
40         def extraction_function (self, file, todir):
41                 assert os.path.isfile (file)
42                 assert os.path.isdir (todir)
43
44                 RAR_CMD = rsutil.common.config_get_value ('commands', 'unrar')
45
46                 cmd = '%s \"%s\"' % (RAR_CMD, file)
47                 ret = rsutil.common.run_command (cmd, todir)
48
49                 # Check error code
50                 if ret != 0:
51                         return -rsutil.common.EEXTRACT
52
53                 return rsutil.common.SUCCESS
54