Add support for Join sets where the parity protects the split files
[rarslave2.git] / PAR2Set / CompareSet.py
1 #!/usr/bin/env python
2 # vim: set ts=4 sts=4 sw=4 textwidth=80:
3
4 """
5 Holds the PAR2Set CompareSet class
6
7 This class is used in the detection of PAR2Sets, and is provided here
8 to reduce the coupling between rarslave.py and the PAR2Set classes.
9
10 You should create one of these, and then send it to any of the other PAR2Set
11 classes' constructor.
12 """
13
14 __author__    = "Ira W. Snyder (devel@irasnyder.com)"
15 __copyright__ = "Copyright (c) 2008 Ira W. Snyder (devel@irasnyder.com)"
16 __license__   = "GNU GPL v2 (or, at your option, any later version)"
17
18 #    CompareSet.py
19 #
20 #    Copyright (C) 2008  Ira W. Snyder (devel@irasnyder.com)
21 #
22 #    This program is free software; you can redistribute it and/or modify
23 #    it under the terms of the GNU General Public License as published by
24 #    the Free Software Foundation; either version 2 of the License, or
25 #    (at your option) any later version.
26 #
27 #    This program is distributed in the hope that it will be useful,
28 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
29 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 #    GNU General Public License for more details.
31 #
32 #    You should have received a copy of the GNU General Public License
33 #    along with this program; if not, write to the Free Software
34 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
36 from PAR2Set import utils, par2parser
37
38 class CompareSet(object):
39
40     ############################################################################
41
42     def __init__(self, directory, parityFile):
43         self.directory = directory
44         self.parityFile = parityFile
45
46         self.baseName = utils.getBasename(parityFile)
47         self.similarlyNamedFiles = utils.findFileNameMatches(directory, self.baseName)
48
49         # WARNING: This is likely to raise an exception!
50         # WARNING: Don't forget to check for it :)
51         self.protectedFiles = par2parser.getProtectedFiles(directory, parityFile)
52
53         # Sort so the compare works as expected
54         self.similarlyNamedFiles.sort()
55         self.protectedFiles.sort()
56
57     ############################################################################
58
59     def __eq__(self, rhs):
60
61         return  self.directory == rhs.directory \
62             and self.baseName == rhs.baseName \
63             and self.similarlyNamedFiles == rhs.similarlyNamedFiles \
64             and self.protectedFiles == rhs.protectedFiles
65
66     ############################################################################
67
68     def __str__(self):
69         s  = '%s\n' % repr(self)
70         s += 'directory: %s\n' % self.directory
71         s += 'parityFile: %s\n' % self.parityFile
72         s += 'baseName: %s\n' % self.baseName
73         s += 'similarlyNamedFiles:\n'
74         for f in self.similarlyNamedFiles:
75             s += '-> %s\n' % f
76         s += 'protectedFiles:\n'
77         for f in self.protectedFiles:
78             s += '-> %s\n' % f
79
80         return s
81
82     ############################################################################
83