#!/usr/bin/python
#
# Trigger script to prevent changing file types to +S
#
# ChangeTypeTrigger.py
#
#
# Copyright Sven Erik Knop (c) 2009 Perforce Software, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id$
#
#
import sys
import P4
from P4Triggers import P4Trigger
class ChangeTypeTrigger(P4Trigger):
def __init__( self, **kargs):
kargs['charset'] = 'none'
kargs['api_level'] = 62
P4Trigger.__init__(self, **kargs)
# need to reset the args in case a p4config file overwrote them
for (k,v) in kargs.iteritems():
setattr( self.p4, k, v)
USER_MESSAGE = """
Your submission has been rejected because the following file
changed its file type to +S
file = %s
type = %s
"""
def setUp( self ):
info = self.p4.run_info()[0]
if "unicode" in info and info["unicode"] == "enabled":
self.p4.charset = "utf8"
self.p4.exception_level = 1 # ignore WARNINGS like "no such file"
self.p4.prog = "ChangeTypeTrigger"
def validate( self ):
for file in self.change.files:
rev = file.revisions[0]
if not (rev.action == "edit"):
continue
if 'S' in rev.type:
self.message( self.USER_MESSAGE % ( file.depotFile, rev.type) )
return False
return True
# main routine.
# If called from the command line, go in here
if __name__ == "__main__":
kargs = {}
try:
for arg in sys.argv[2:]:
(key,value) = arg.split("=")
kargs[key] = value
except:
print "Error, expecting arguments in form key=value. Bailing out ..."
sys.exit(0)
ct = ChangeTypeTrigger( **kargs )
sys.exit( ct.parseChange( sys.argv[1] ) )
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #3 | 8288 | Sven Erik Knop | Fixed indentation. | ||
| #2 | 8272 | Sven Erik Knop |
changed filetype to +x for easier invocation. Also accidently submitted .project file open from the JournalReader. Should check open files first. |
||
| #1 | 7425 | Sven Erik Knop |
Added ChangeTypeCheckTrigger.py. This trigger prevents the change of a file type to +S (temporary , purging previous revisions). Usage is identical to the CheckCaseTrigger, for example with this trigger line: typeChangePreventer change-submit //depot/... "python ChangeTypeCheckTrigger.py %change% port=1666 user=admin" |