pydates revision 2588
2026N/A#!/usr/bin/python2.6
2026N/A
2026N/A# This program is free software; you can redistribute it and/or modify
2026N/A# it under the terms of the GNU General Public License version 2
2026N/A# as published by the Free Software Foundation.
2026N/A#
2026N/A# This program is distributed in the hope that it will be useful,
2026N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2026N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2026N/A# GNU General Public License for more details.
2026N/A#
2026N/A# You should have received a copy of the GNU General Public License
2026N/A# along with this program; if not, write to the Free Software
2026N/A# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2026N/A#
2026N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2026N/A
2026N/A
2026N/A# Create a dictionary (timestamps) mapping paths of python files in the modules
2026N/A# directory to their timestamps. If a file is modified, its timestamp is the
2026N/A# filesystem timestamp. If it's unchanged, its timestamp is the timestamp of
2026N/A# the last changeset which modified it.
2026N/A
2245N/Aimport os
2026N/Aimport time
2026N/Aimport mercurial.cmdutil as cmdutil
2026N/Aimport mercurial.match as matchmod
2026N/Afrom mercurial.localrepo import localrepository
2026N/Afrom mercurial.ui import ui
2026N/A
2026N/Amyui = ui()
2026N/Arepo = localrepository(myui, cmdutil.findrepo(os.getcwd()))
2026N/A
2026N/A# Match only python files in src/modules.
2026N/Amatchfn = matchmod.match(repo.root, os.getcwd(), patterns=["re:src/modules/.*\.py$"])
2026N/A
2026N/A# Dummy prep function.
2026N/Adef prep(ctx, fns):
2026N/A pass
2026N/A
2026N/A# Get the set of matching files in the working directory parent.
2026N/Amanifest = set(
2026N/A f
2026N/A for f in repo["."]
2026N/A if f.startswith("src/modules/") and f.endswith(".py")
2026N/A)
2026N/A
2026N/A# Find out which files have changed.
2026N/Astatus = repo.status(match=matchfn)
2026N/A
2026N/Atimestamps = {}
2026N/A
2026N/A# Handle the modified files first: get their timestamps from the filesystem.
2026N/A# Remove the filenames from "manifest" so that we don't look for their changeset
2026N/A# timestamps in the next loop.
2026N/Afor f in status[0] + status[1]:
2026N/A if f in manifest:
2026N/A timestamps[f] = \
2026N/A os.stat(os.path.join(repo.root, f)).st_mtime
2026N/A manifest.remove(f)
2026N/A
2026N/A# Now walk backwards through the changesets from the working directory parent
2026N/A# (making sure we don't look at changesets that aren't ancestors), and for each
2026N/A# file that still needs a timestamp, grab it from the changeset and make sure we
2026N/A# don't look at it again.
2026N/Arevs = ['reverse(ancestors(.))']
2026N/Afor ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev': revs}, prep):
2026N/A for f in ctx.files():
2026N/A if f in manifest:
2026N/A timestamps[f] = ctx.date()[0]
2026N/A manifest.remove(f)
2026N/A
2026N/Afor name, stamp in timestamps.iteritems():
2026N/A print stamp, name
2026N/A
2026N/A# Get the timestamp of the workspace. If it's unmodified, then use the
2026N/A# timestamp of the parent of the working directory, and the latest timestamp of
2026N/A# the modified and added files if not. (We would do removed, but we don't know
2026N/A# when they were removed.)
2026N/As = repo.status()
2026N/Amodadd = s[0] + s[1]
2026N/Aif any(modadd):
2026N/A print max((
2026N/A os.stat(os.path.join(repo.root, f)).st_mtime
2026N/A for f in modadd
2026N/A )), "."
2268N/Aelse:
2026N/A print repo["."].date()[0], "."
2026N/A