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