* Added long options (missing in patch)
[pacman.git] / pactest / pmfile.py
blobd78b09fa5d5e5549fd6d8bae1154bae5041184a1
1 #! /usr/bin/python
3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 # USA.
21 import os
23 from util import *
26 class pmfile:
27 """File object
28 """
30 def __init__(self, root, name):
31 self.name = name
32 self.root = root
34 filename = os.path.join(self.root, self.name)
35 self.checksum = getmd5sum(filename)
36 self.mtime = getmtime(filename)
38 def __str__(self):
39 return "%s (%s / %lu)" % (self.name, self.checksum, self.mtime)
41 def ismodified(self):
42 """
43 """
45 retval = 0
47 filename = os.path.join(self.root, self.name)
48 checksum = getmd5sum(filename)
49 mtime = getmtime(filename)
51 if debug:
52 print "ismodified(%s)" % self.name
53 print "old: %s / %s" % (self.checksum, self.mtime)
54 print "new: %s / %s" % (checksum, mtime)
56 if not self.checksum == checksum \
57 or not (self.mtime[1], self.mtime[2]) == (mtime[1], mtime[2]):
58 retval = 1
60 return retval
63 if __name__ == "__main__":
64 f = pmfile("/tmp", "foobar")
65 print f