head     1.12106;
access   ;
symbols  ;
locks    ;comment  @@;


1.12106
date     2013.02.02.17.38.28;  author p4;  state Exp;
branches ;
next     ;


desc
@@


1.12106
log
@@
text
@#
# Copyright 2009 Perforce Software.
# This file is part of the Perforce Scripting Class.
# See license.txt for Copyright information.
#
# Module:	relnotes.py
#                     
# Purpose: 	Generate a limited list of changelists
# 		for a given path.

import sys
from types import *
from P4 import P4, P4Exception
p4 = P4()

def init():
    # Use p4.api_level = <value> to set the data
    # returned by the server to a specific
    # Perforce release, e.g. for 2009.1:
    # p4.api_level = 65
    # The default exception level is two, but we
    # explicitly state it here for reference:
    
    p4.exception_level = 2

    # The p4.prog string is available to Perforce 
    # admin users running p4 monitor show -e

    p4.prog = "Release Notes"
    p4.client = "script_ws"
    try:
	p4.connect()
    except P4Exception:
	# If we cannot connect to the server, that
	# is a client program error. We do not get
	# server error or warning messages, so we
	# go ahead and exit with a message.
	print "Cannot connect to the server."
	sys.exit(1)
        
def getdata(cd):
    try:
	res = p4.run(cd)
	if (len(res) > 0):
	    if (p4.tagged):
		if not isinstance(res[0], DictType):
		    print "Data is not a dictionary. \n"
		    p4.disconnect()
		    sys.exit(1)
	    return res
	else:
	    print "No data returned from command: ", cd, "\n"
    except P4Exception:
	for e in p4.errors:
	    print "Errors: " + e
	    sys.exit(1)
	for w in p4.warnings:
	    print "Warnings: " + w

# ########################################################
# PRINT DATA TO STANDARD OUTPUT
# Use this subroutine if you wish to print the results of
# your command.

def printdata(r):
    if not (isinstance(r, types.NoneType)):
	for i in range(len(r)):
	    if (p4.tagged):
		dict = r[i]
		for key in dict.keys():
		    print "%s :: %s" % (key,dict[key])
	    else:
		print r[i]
            
# ######################################################
# WRITE TO A FILE

def writedata(): 
    print "Write data to a file. \n"
    # Get the array of changelist descriptions from your 
    # data  below. 
    # Open a file handle for your releasenotes file.
    # Iterate over your array and print 
    # Change number <changelist number> and
    # Description <changelist description> from your array.
    # close the file handle to your releasenotes file.

# #######################################################
# Construct your command string here as an array, "cmd."
# The syntax is cmd = ("p4command", "flags", "filespecs")
#
#  MAIN PROGRAM

init()
cmd = ("changes", "-s", "submitted", "//Sim/Prod/REL2.1/src/...")
chg = getdata(cmd)

# Get changelists and push the changelist descriptions to an array.

for i in range(len(chg)):
    dict = chg[i]
    chg1 = dict["change"]
    print chg1 

    # Use the chg1 variable to construct a command
    # that performs a 'describe -s' on each changelist
    # using the API command string syntax. 
    # Use getdata(your_command) and push the array
    # to a results array e.g. push(your_array, your_description);

# Create a releasenotes file by finishing the writedata subroutine above.

# writedata(your_array);

# #####################################################
# Terminate your instance of P4 cleanly:

p4.disconnect()                
@
