[PAR2SET] Add missing os declarations
[rarslave2.git] / PAR2Set / ZIP.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 a regular zip file 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.zip
15 # ABC.zip
16 #
17 # Where the PAR2 files protect a file named X.zip and/or ABC.zip.
18 #
19
20 def detector (name_files, prot_files):
21         all_files = rsutil.common.no_duplicates (name_files + prot_files)
22         return rsutil.common.has_a_match ('^.*\.zip$', all_files)
23
24
25 class ZIP (PAR2Set.Base.Base):
26
27         def __repr__ (self):
28                 return 'ZIP'
29
30         def find_extraction_heads (self):
31                 return rsutil.common.find_matches ('^.*\.zip', self.all_files)
32
33         def extraction_function (self, file, todir):
34                 ZIP_CMD = rsutil.common.config_get_value ('commands', 'unzip')
35
36                 cmd = ZIP_CMD % (file, todir)
37                 ret = rsutil.common.run_command (cmd)
38
39                 # Check error code
40                 if ret != 0:
41                         return -rsutil.common.EEXTRACT
42
43                 return rsutil.common.SUCCESS
44