#!/usr/bin/env python '''Print changes from last label ''' # ===================================================== # Copyright (c) Miki Tebeka # This file is under the GNU Public License (GPL), see # http://www.gnu.org/copyleft/gpl.html for more details # ===================================================== __author__ = "Miki Tebeka " # $Id: //guest/miki_tebeka/change_log.py#2 $ from os import popen, environ from datetime import date def client_path(client): '''Return path for client''' return "//%s/..." % client def chlog(client, label): '''Return lines of last change''' # Client path path = client_path(client) # Last changelist last = popen("p4 changes -m1 %s" % path).read().split()[1] # Previous change list prev = popen("p4 changes -m1 %s@%s" % (path, label)).read().split()[1] # Get all change list data (without diff) s = "" # Return value for line in popen("p4 changes %s@%s,@%s" % (path, prev, last)): change = line.split()[1] s += popen("p4 describe -s %s" % change).read() return s def get_last_label(client): '''Get last label for client''' label = "" max_date = None # Get last label for line in popen("p4 labels %s" % client_path(client)): fields = line.strip().split() l = fields[1] # Current label y, m, d = fields[2].split("/") # Current date d = date(int(y), int(m), int(d)) if not label: label = l max_date = d continue # Check if label is newer than current if max_date < d: max_date = d label = l return label if __name__ == "__main__": from optparse import OptionParser parser = OptionParser("usgae: %prog [options]", version="%prog version 0.0.2") parser.add_option("-c", help="client name", dest="client", default="") parser.add_option("-l", help="last label name", dest="label", default="") opts, args = parser.parse_args() if args: parser.error("wrong number of arguments") # Will exit if not opts.client: try: opts.client = environ["P4CLIENT"] except KeyError: raise SystemExit("error: P4CLIENT not set and -c not given") if not opts.label: opts.label = get_last_label(opts.client) if not opts.label: m = "error: last label for %s not found and -l not specified" % \ client raise SystemExit(msg) print chlog(opts.client, opts.label)