find_newer revision 5887
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User# Permission is hereby granted, free of charge, to any person obtaining a
5347c0fcb04eaea19d9f39795646239f487c6207Tinderbox User# copy of this software and associated documentation files (the
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# "Software"), to deal in the Software without restriction, including
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# without limitation the rights to use, copy, modify, merge, publish,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# distribute, and/or sell copies of the Software, and to permit persons
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# to whom the Software is furnished to do so, provided that the above
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# copyright notice(s) and this permission notice appear in all copies of
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# the Software and that both the above copyright notice(s) and this
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# permission notice appear in supporting documentation.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# Except as contained in this notice, the name of a copyright holder
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User# shall not be used in advertising or otherwise to promote the sale, use
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# or other dealings in this Software without prior written authorization
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# of the copyright holder.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein###########################################################################
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + "Usage: find_newer.py [options] dir...\n\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + " --name glob find files matching glob\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + " --newer ref find files newer than a reference file"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + " -c compare ctimes (the time the file status was last changed)\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + " -m compare mtimes (the time the file was last modified)\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + " -a compare atimes (the time the file was last accessed)\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + "\nNote: if more than one of -c -m and -a are specified, find_newer will\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein self.msg = self.msg + "compare the most recent of the given times\n"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeindef find_newer_files(dir, comp_time, ref_time, reobj, follow_links):
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein print >>sys.stderr, "Warning: infinite loop of symlinks"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein file = os.path.abspath(os.path.join(root, file))
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User if get_file_time (stat, comp_time) > ref_time:
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User # no reference time, print all files that match the regex
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User # descend into subdirectories that are really symlinks
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein d = os.path.abspath(os.path.join(root, os.readlink(d)))
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein find_newer_files(d, comp_time, ref_time, reobj, follow_links)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # parse the command line args
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User opts, args = getopt.getopt(argv[1:], "hcmaf", ["help", "newer=", "name="])
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if o == "-c":
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User elif o == "-m":
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein elif o == "-a":
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein print >>sys.stderr, "Use --help for usage information"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # default: compare ctime
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # return stat time as floats
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein print >>sys.stderr, "Cannot stat reference file: %s" % ref_file
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein print >>sys.stderr, "Directory not found: %s" % dir