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