#!/usr/bin/python # # clienttrigger.py # # Copyright (c) 2008, 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: //guest/sven_erik_knop/P4Pythonlib/triggers/clienttrigger.py#1 $ # # This trigger updates a new client spec with some defaults. # It is meant as a template to create your own client default triggers. # # This script requires P4Python 2007.3 or later from the Perforce website. # # Called with formname, formfile and serverport and user # Link this up as a trigger with a trigger line like this: # # default-client form-out client "/home/triggers/clienttrigger.py %formname% %formfile% %serverport% %user% import P4 import sys clientname = sys.argv[1] clientfilename = sys.argv[2] serverport = sys.argv[3] user = sys.argv[4] p4 = P4.P4() p4.port = serverport p4.user = user p4.client = clientname p4.connect() # verify that the client does not exists already info = p4.run_info()[0] if info['clientName'] != "*unknown*": sys.exit(0) # read the formfile clientfile = open( clientfilename, "r" ) clientAsString = clientfile.read() clientfile.close() # parse the formfile client = p4.parse_client(clientAsString) # change the client content client['Options'] = client['Options'].replace('normdir', 'rmdir') # create the string again # and modify the formfile clientAsString = p4.format_client(client) clientfile = open ( clientfilename, "w" ) clientfile.write(clientAsString) clientfile.close() # and exit successfully p4.disconnect() sys.exit(0)
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 8218 | Sven Erik Knop | Use modern "with" statement to read and write files. | ||
#3 | 7372 | Sven Erik Knop |
Rollback Rename/move file(s). To folder "perforce" is needed. |
||
#2 | 7370 | Sven Erik Knop | Rename/move file(s) again - this time to the right location inside a perforce directory. | ||
#1 | 7367 | Sven Erik Knop | New locations for the Python triggers. | ||
//guest/sven_erik_knop/perforce/P4Pythonlib/triggers/clienttrigger.py | |||||
#1 | 7370 | Sven Erik Knop | Rename/move file(s) again - this time to the right location inside a perforce directory. | ||
# | Change | User | Description | Committed | |
#1 | 7367 | Sven Erik Knop | New locations for the Python triggers. | ||
//guest/sven_erik_knop/triggers/clienttrigger.py | |||||
#1 | 6413 | Sven Erik Knop |
Added some P4Python-based Perforce triggers. P4Triggers.py is the based class for change trigger in Python modelled on Tony Smith's Ruby trigger with the same name. CheckCaseTrigger.py is a trigger that ensures that no-one enters a file or directory with a name only differing by case from an existing file. This trigger is Unicode aware and uses Unicode-comparison of file names, so it can be used on nocase-Unicode based Perforce servers, which cannot catch the difference between, say, "�re" and "�re" at the moment. clienttrigger.py is a simple trigger that modifies the option "normdir" to "rmdir" for new client specs only. It is meant as a template to create more complex default settings like standard views. |