2 # vim: set ts=4 sts=4 sw=4 textwidth=80:
5 Holds the PAR2Set CompareSet class
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.
10 You should create one of these, and then send it to any of the other PAR2Set
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)"
20 # Copyright (C) 2008 Ira W. Snyder (devel@irasnyder.com)
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.
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.
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
36 from PAR2Set import utils, par2parser
38 class CompareSet(object):
40 ############################################################################
42 def __init__(self, directory, parityFile):
43 self.directory = directory
44 self.parityFile = parityFile
46 self.baseName = utils.getBasename(parityFile)
47 self.similarlyNamedFiles = utils.findFileNameMatches(directory, self.baseName)
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)
53 # Sort so the compare works as expected
54 self.similarlyNamedFiles.sort()
55 self.protectedFiles.sort()
57 ############################################################################
59 def __eq__(self, rhs):
61 return self.directory == rhs.directory \
62 and self.baseName == rhs.baseName \
63 and self.similarlyNamedFiles == rhs.similarlyNamedFiles \
64 and self.protectedFiles == rhs.protectedFiles
66 ############################################################################
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:
76 s += 'protectedFiles:\n'
77 for f in self.protectedFiles:
82 ############################################################################