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