"""
Copyright (c) Perforce Software, Inc., 1997-2010. 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.
User contributed content on the Perforce Public Depot is not supported by Perforce,
although it may be supported by its author. This applies to all contributions
even those submitted by Perforce employees.
"""
"""
This script will run 'p4 resolve' on any files in the current
workspace that need resolving. For each file, it will
archive the merge output file, then skip the resolve.
Example usage scenario:
Assume there are two files open for integration in the workspace,
that have yet to be resolved. The files are foo.c and foo.h, and
each will have a conflict when resolved. Run
this script in the workspace:
python savemerge.py
The expected result is that the output directory now contains files
named foo.c and foo.h. The files in the output directory are the
merged output files created during the resolve, and will contain
the conflict markers. The files in the workspace are still open
for integration and still need to be resolved.
Caveats:
1. Currently the connection information is hard-coded in the script.
It could easily be removed, in which case the script would rely on
the environment in the working directory.
2. The script will overwrite files in the output directory.
3. The output directory is hard-coded to '/tmp'.
"""
import P4
import os
from shutil import copy
from os.path import basename
# To-do: provide a better archive directory than /tmp
class MyResolver(P4.Resolver):
def resolve(self, mergeData):
dst = "/tmp/" + basename(mergeData.your_name)
copy(mergeData.result_path, dst)
return "s"
p4 = P4.P4()
P4Exception = P4.P4Exception
# Although we provide explicit connection information here,
# a P4Python script can also inherit connection settings
# from the environment (including P4CONFIG files).
p4.port = "localhost:1666"
p4.user = "bruno"
p4.client = "bruno_ws"
try:
p4.connect()
p4.run_resolve ( resolver=MyResolver() );
p4.disconnect()
except P4Exception:
for e in p4.errors:
print e