Skip to content

Instantly share code, notes, and snippets.

@pmolodo
Last active October 18, 2019 21:22
Show Gist options
  • Save pmolodo/2670625d8614154003d901dd5ff188b5 to your computer and use it in GitHub Desktop.
Save pmolodo/2670625d8614154003d901dd5ff188b5 to your computer and use it in GitHub Desktop.
Scripts for helping with merging issues for Maya-USD and "old" Pixar and Animal Logic Repos
# change to git root dir
cd "$(git rev-parse --show-toplevel)"
# Some commit reference points:
# 19a1e755c258c9ac0d7495fa0add62508ff377a1 - plugins/AL_USDMaya (initial import of pixar from submodule)
# 825ca13dd77af84872a063f146dee1799e8be25c - plugins/AL_USDMaya (some removals)
# 141bab7eba1d380868e822a51f8c8f85e1c0b66f - plugins/AL_USDMaya (identical contents as above)
# e5e10a28d0ba0535e83675399a5d15314fb79ec9 - plugin/al (renamed dir)
# Removed in 825ca13dd77af84872a063f146dee1799e8be25c
# D plugins/AL_USDMaya/.gitignore
# D plugins/AL_USDMaya/AL_USDMaya_Corporate_CLA.pdf
# D plugins/AL_USDMaya/AL_USDMaya_Individual_CLA.pdf
# D plugins/AL_USDMaya/CHANGELOG.md
# D plugins/AL_USDMaya/NOTICE.txt
# D plugins/AL_USDMaya/PULL_REQUEST_TEMPLATE.md
# D plugins/AL_USDMaya/build_docker_centos6.sh
# D plugins/AL_USDMaya/build_docker_centos7.sh
# D plugins/AL_USDMaya/build_lib.sh
# D plugins/AL_USDMaya/cmake/defaults/CXXHelpers.cmake
# D plugins/AL_USDMaya/cmake/defaults/Version.cmake
# D plugins/AL_USDMaya/cmake/defaults/msvcdefaults.cmake
# D plugins/AL_USDMaya/cmake/modules/FindMaya.cmake
# D plugins/AL_USDMaya/cmake/modules/FindUFE.cmake
# D plugins/AL_USDMaya/cmake/modules/FindUSD.cmake
# D plugins/AL_USDMaya/docker/Dockerfile_centos6
# D plugins/AL_USDMaya/docker/Dockerfile_centos7
# D plugins/AL_USDMaya/docker/README.md
# D plugins/AL_USDMaya/docker/build_alusdmaya.sh
# D plugins/AL_USDMaya/setup_environment.sh
# This function will take a "stock" AnimalLogic AL_USDMaya repo, and rename /
# delete files and folders to make it "line up" with their locations in maya-usd
function renameALRepo ()
{
# Get in line with e5e10a28d0ba0535e83675399a5d15314fb79ec9
# We move in two steps because the AL repo originally has a dir called
# "plugin", which we still want to move into plugin - ie,
# plugin => plugin/al/plugin
# By doing in two stages, it makes sure it doesn't treat this initial
# 'plugin' dir special
mkdir -p temp
git mv -k $(ls -A) temp
mkdir -p plugin
git mv temp plugin/al
git rm -f plugin/al/.gitignore
git rm -f plugin/al/AL_USDMaya_Corporate_CLA.pdf
git rm -f plugin/al/AL_USDMaya_Individual_CLA.pdf
git rm -f plugin/al/CHANGELOG.md
git rm -f plugin/al/NOTICE.txt
git rm -f plugin/al/PULL_REQUEST_TEMPLATE.md
git rm -f plugin/al/build_docker_centos6.sh
git rm -f plugin/al/build_docker_centos7.sh
git rm -f plugin/al/build_lib.sh
git rm -f plugin/al/setup_environment.sh
git rm -rf plugin/al/docker/
git mv plugin/al/cmake cmake
python replace_lic.py --al
}
##############################
# branch: renamed_0_31_1
##############################
# Make a branch that's IDENTICAL to stock AL 0.31.1, except with directory
# renames/ file moves / deletions to get files into the same place as in the
# master branch of Maya-USD
#
# This branch is a useful reference point, and will be used to make a diff /
# patch file which will handy when doing merges.
git checkout -B renamed_0_31_1 0.31.1
renameALRepo
git commit -a -m "Renamed / deleted files from AL 0.31.1 to match maya-usd layout"
##############################
# branch: renamed_al_develop
##############################
# Make a branch that's IDENTICAL to AL's latest develop
# (3cdea62c31b1be60aa02138e4b54bb13f7e80ee1), except with directory renames/
# file moves / deletions to get files into the same place as in the master
# branch of Maya-USD
#
# This branch is a useful reference point, and will be used to make a diff /
# patch file which will handy when doing merges.
git checkout -B renamed_al_develop origin/al/develop
renameALRepo
git commit -a -m "Renamed / deleted files from AL dev (3cdea62c) to match maya-usd layout"
###############
# Make a patch that gives all changes between renamed_0_31_1 and renamed_al_develop
# ...this will be used when resolving merge conflicts
git diff renamed_0_31_1 renamed_al_develop > ../al_0311_develop.diff
###############
# Now that we have our helper diff, merge pixar-usd dev into latest maya-usd master
git checkout dev
# attempt the merge - this will give a lot of merge conflicts...
git merge origin/al/develop
# These files were removed / we don't care about:
git rm -f CHANGELOG.md
# These were new files, that we're moving into their proper places:
git mv docs/cameraProxy.md plugin/al/docs/cameraProxy.md
git mv lib/AL_USDMaya/AL/usdmaya/cmds/ListTranslators.cpp plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ListTranslators.cpp
git mv lib/AL_USDMaya/AL/usdmaya/cmds/SyncFileIOGui.cpp plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/SyncFileIOGui.cpp
git mv lib/AL_USDMaya/AL/usdmaya/cmds/SyncFileIOGui.h plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/SyncFileIOGui.h
git mv lib/AL_USDMaya/AL/usdmaya/nodes/ProxyUsdGeomCamera.cpp plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyUsdGeomCamera.cpp
git mv lib/AL_USDMaya/AL/usdmaya/nodes/ProxyUsdGeomCamera.h plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyUsdGeomCamera.h
git mv mayautils/AL/maya/tests/mayaplugintest/utils/PluginTranslatorOptionsTest.cpp plugin/al/mayautils/AL/maya/tests/mayaplugintest/utils/PluginTranslatorOptionsTest.cpp
git mv mayautils/AL/maya/utils/PluginTranslatorOptions.cpp plugin/al/mayautils/AL/maya/utils/PluginTranslatorOptions.cpp
git mv mayautils/AL/maya/utils/PluginTranslatorOptions.h plugin/al/mayautils/AL/maya/utils/PluginTranslatorOptions.h
git mv plugin/AL_USDMayaTestPlugin/AL/usdmaya/fileio/import_instances.cpp plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/fileio/import_instances.cpp
git mv plugin/AL_USDMayaTestPlugin/AL/usdmaya/fileio/test_activeInActiveTranslators.cpp plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/fileio/test_activeInActiveTranslators.cpp
git mv plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyUsdGeomCamera.cpp plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ProxyUsdGeomCamera.cpp
git mv plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_DiffGeom.cpp plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/test_DiffGeom.cpp
git mv translators/CommonTranslatorOptions.cpp plugin/al/translators/CommonTranslatorOptions.cpp
git mv translators/CommonTranslatorOptions.h plugin/al/translators/CommonTranslatorOptions.h
git add lib/AL_USDMaya/AL/usdmaya/cmds/ListTranslators.h
git mv lib/AL_USDMaya/AL/usdmaya/cmds/ListTranslators.h plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ListTranslators.h
git add mayautils/AL/maya/utils/Utils.cpp
git mv mayautils/AL/maya/utils/Utils.cpp plugin/al/mayautils/AL/maya/utils/Utils.cpp
# both deleted:
git rm lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeSelectCommands.cpp
git rm lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeSelectCommands.h
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeSelectCommands.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/cmds/ProxyShapeSelectCommands.h
# newly deleted:
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/DrivenTransformsData.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/DrivenTransformsData.h
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/CameraTranslator.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/MeshTranslator.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/translators/NurbsCurveTranslator.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/DrivenTransforms.cpp
git rm plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/proxy/DrivenTransforms.h
git rm plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/proxy/test_DrivenTransforms.cpp
# When I inspected these, determined we didn't care about any of the changes in
# these files between renamed_0_31_1 and renamed_al_develop - so just checking out
# old version
git checkout dev -- CMakeLists.txt
function showALDiff ()
{
git difftool -y renamed_0_31_1 renamed_al_develop -- "$1" &
}
# Manually merged these:
git mergetool cmake/modules/FindUFE.cmake
git mergetool plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeUI.cpp
git mergetool plugin/al/mayautils/AL/maya/event/MayaEventManager.cpp
git mergetool plugin/al/mayautils/AL/maya/utils/MenuBuilder.h
git mergetool plugin/al/mayautils/AL/maya/utils/NodeHelper.cpp
git mergetool plugin/al/usdmayautils/AL/usdmaya/utils/DgNodeHelper.cpp
set -e
if [[ -z "$1" ]]; then
echo "usage: $0 REMOTE"
echo "First argument must be the git remote that the pixar dev branch can be found on"
exit 1
fi
pxr_remote="$1"
if ! git rev-parse --verify -q $pxr_remote/dev > /dev/null ; then
echo "Given remote '$pxr_remote' did not have a dev branch"
echo "(ie, '$pxr_remote/dev' did not exist)"
exit 1
fi
# change to git root dir
cd "$(git rev-parse --show-toplevel)"
# Some commit reference points:
# 4b46bfd3b5ea96c709547e830bb645d60c21fa29 - plugins/USD (initial import of pixar from submodule)
# 825ca13dd77af84872a063f146dee1799e8be25c - plugins/PXR_USDMaya (renamed dir)
# 141bab7eba1d380868e822a51f8c8f85e1c0b66f - plugins/PXR_USDMaya (identical contents as above)
# e5e10a28d0ba0535e83675399a5d15314fb79ec9 - plugin/pxr (renamed dir)
dev_mergebase=$(git merge-base $pxr_remote/dev dev)
pixar_dev_commit=$(git show -s --format="%H" dev)
# This function will take a "stock" pixar USD repo, and rename / delete files
# and folders to make it "line up" with their locations in maya-usd
function renamePixarRepo ()
{
cd "$(git rev-parse --show-toplevel)"
# move everything in the root to plugin/pxr
rm -rf plugin/pxr
mkdir -p plugin/pxr
git mv -k $(ls -A) plugin/pxr
# Move back some of the cmake stuff to the root
mkdir -p cmake
git mv plugin/pxr/cmake/defaults/ cmake/
git mv plugin/pxr/cmake/modules/ cmake/
# Remove a bunch of files / folders
git rm -f cmake/defaults/Packages.cmake
git rm -f cmake/modules/FindGLEW.cmake
git rm -f cmake/modules/FindPTex.cmake
git rm -f cmake/modules/FindRenderman.cmake
git rm -f --ignore-unmatch cmake/modules/FindDraco.cmake
git rm -f plugin/pxr/.appveyor.yml
git rm -f plugin/pxr/.gitignore
git rm -f plugin/pxr/.travis.yml
git rm -f plugin/pxr/BUILDING.md
git rm -f plugin/pxr/CHANGELOG.md
git rm -f plugin/pxr/CONTRIBUTING.md
git rm -f plugin/pxr/NOTICE.txt
git rm -f plugin/pxr/README.md
git rm -f plugin/pxr/USD_CLA_Corporate.pdf
git rm -f plugin/pxr/USD_CLA_Individual.pdf
git rm -f --ignore-unmatch VERSIONS.md
git rm -f plugin/pxr/cmake/macros/generateDocs.py
git rm -f plugin/pxr/pxr/CMakeLists.txt
git rm -f plugin/pxr/pxr/pxrConfig.cmake.in
git rm -rf plugin/pxr/.github/
git rm -rf plugin/pxr/build_scripts/
git rm -rf plugin/pxr/extras/
git rm -rf plugin/pxr/pxr/base/
git rm -rf plugin/pxr/pxr/imaging/
git rm -rf plugin/pxr/pxr/usd/
git rm -rf plugin/pxr/pxr/usdImaging/
git rm -rf plugin/pxr/third_party/houdini/
git rm -rf plugin/pxr/third_party/katana/
git rm -rf plugin/pxr/third_party/renderman-22/
git mv plugin/pxr/third_party/maya plugin/pxr/maya
delete_replace_lic=0
if [[ ! -f replace_lic.py ]]; then
delete_replace_lic=1
git checkout dev -- replace_lic.py
fi
python replace_lic.py --pxr
if (( $delete_replace_lic )); then
rm replace_lic.py
fi
}
##############################
# branch: renamed_mergebase
##############################
# Make a branch that's IDENTICAL to stock 19.05, except with directory renames/
# file moves / deletions to get files into the same place as in the master
# branch of Maya-USD
#
# This branch is a useful reference point, and will be used to make a diff /
# patch file which will handy when doing merges.
echo "Checking out last-merged pixar-dev commit ($dev_mergebase)"
git checkout -B renamed_mergebase $dev_mergebase
echo "...renaming files to match maya-usd layout..."
renamePixarRepo
git commit -a -m "Renamed / deleted files from previously-merged dev to match maya-usd layout"
echo "...done renaming files"
##############################
# branch: renamed_pxr_dev
##############################
# Make a branch that's IDENTICAL to pixar's latest usd dev
# (b29152c2896b1b4d03fddbd9c3dcaad133d2c495), except with directory renames/
# file moves / deletions to get files into the same place as in the master
# branch of Maya-USD
#
# This branch is a useful reference point, and will be used to make a diff /
# patch file which will handy when doing merges.
echo "Checking out latest pixar-dev commit ($pixar_dev_commit)"
git checkout -B renamed_pxr_dev $pxr_remote/dev
renamePixarRepo
echo "...renaming files to match maya-usd layout..."
git commit -a -m "Renamed / deleted files from pixar dev to match maya-usd layout"
echo "...done renaming files"
###############
# Make a patch that gives all changes between renamed_v1905 and renamed_pxr_dev
# ...this will be used when resolving merge conflicts
git diff renamed_mergebase renamed_pxr_dev > ../pixar_dev.diff
echo "Created diff of new changes to merge in"
###############
# Now that we have our helper diff, merge pixar-usd dev into latest maya-usd master
git checkout dev
# attempt the merge - this will give a lot of merge conflicts...
echo "Attempting merge..."
set +e
if git merge $pxr_remote/dev; then
echo 'merge succeeded! Unbelieveable!'
else
echo 'merge failed, as expected...'
fi
echo "Removing files that aren't used by maya-usd"
# These files were removed / we don't care about:
git rm -f cmake/defaults/Packages.cmake
git rm -f cmake/modules/FindGLEW.cmake
git rm -f cmake/modules/FindPTex.cmake
git rm -f cmake/modules/FindRenderman.cmake
git rm -f cmake/modules/FindDraco.cmake
git rm -f .appveyor.yml
git rm -f .travis.yml
git rm -f BUILDING.md
git rm -f CHANGELOG.md
git rm -f CONTRIBUTING.md
git rm -f NOTICE.txt
git rm -f USD_CLA_Corporate.pdf
git rm -f USD_CLA_Individual.pdf
git rm -f VERSIONS.md
git rm -f cmake/macros/generateDocs.py
git rm -f pxr/CMakeLists.txt
git rm -f pxr/pxrConfig.cmake.in
git rm -rf .github/
git rm -rf build_scripts/
git rm -rf extras/
git rm -rf pxr/base/
git rm -rf pxr/imaging/
git rm -rf pxr/usd/
git rm -rf pxr/usdImaging/
git rm -rf third_party/houdini/
git rm -rf third_party/katana/
git rm -rf third_party/renderman-22
set -e
echo "...done removing files."
# for license, decided to just use the Pixar one unaltered... this is the
# LICENSE.txt that stood at the root of the USD project. Had been removing
# new license bits that didn't apply to the maya plugin... but there were
# already many bits that didn't apply to maya, and having a few more shouldn't
# make a difference... and going forward, will be easier to simply take their
# LICENSE.txt unaltered (moved to plugin/pxr/LICENSE.txt)
git show $pxr_remote/dev:LICENSE.txt > plugin/pxr/LICENSE.txt
git add plugin/pxr/LICENSE.txt
echo "Remaining conflicts to be resolved:"
echo "==========================================================="
git status
echo "==========================================================="
echo "(See the commented out section of the script for tips)"
# Ok, this ends the section of stuff that can be run automated. The rest of this
# is commented out, and can be copy / pasted into a terminal, or just used for
# for reference.
# Basically, you need to go through the added / deleted / merge-conflict files,
# making sure everything seems to be in the right place. The lines below have
# sections covering ways of handling various issues - the trickiest being when
# a rename was not detected, and our diff needs to be applied. Most of the other
# issues can be resolved with normal git tricks...
################################################################################
# New Files
################################################################################
# These were new files, that we're moving into their proper places:
# git mv third_party/maya/lib/pxrUsdMayaGL/testenv plugin/pxr/maya/lib/pxrUsdMayaGL
# git mv third_party/maya/lib/usdMaya/testenv/UsdReferenceAssemblyChangeRepresentationsTest/* plugin/pxr/maya/lib/usdMaya/testenv/UsdReferenceAssemblyChangeRepresentationsTest
# rm -rf third_party/maya/lib/usdMaya/testenv/UsdReferenceAssemblyChangeRepresentationsTest
# git mv third_party/maya/lib/usdMaya/testenv/UsdExportAssemblyEditsTest plugin/pxr/maya/lib/usdMaya/testenv
# git mv third_party/maya/lib/usdMaya/testenv/testUsdExportAssemblyEdits.py plugin/pxr/maya/lib/usdMaya/testenv/testUsdExportAssemblyEdits.py
# git mv third_party/maya/plugin/pxrUsdTranslators/strokeWriter.* plugin/pxr/maya/plugin/pxrUsdTranslators
# mkdir -p plugin/pxr/maya/plugin/pxrUsdTranslators/testenv/StrokeExportTest
# git mv third_party/maya/plugin/pxrUsdTranslators/testenv/StrokeExportTest/StrokeExportTest.ma plugin/pxr/maya/plugin/pxrUsdTranslators/testenv/StrokeExportTest/StrokeExportTest.ma
# git mv third_party/maya/plugin/pxrUsdTranslators/testenv/testPxrUsdTranslatorsStroke.py plugin/pxr/maya/plugin/pxrUsdTranslators/testenv/testPxrUsdTranslatorsStroke.py
################################################################################
# Changes we don't want
################################################################################
# # When I inspected these, determined we didn't care about any of the changes in
# # these files between renamed_v1905 and renamed_pxr_dev - so just checking out
# # old version
# git checkout dev -- cmake/defaults/Options.cmake
################################################################################
# Bad rename detection - mapped to wrong file (ie, in AL)
################################################################################
# these are conflicts presumably due to bad rename detection
# git checkout dev -- plugin/al/lib/AL_USDMaya/Doxyfile
# git checkout dev -- plugin/al/schemas/AL/usd/schemas/mayatest/ExamplePolyCubeNode.h
################################################################################
# Bad rename detection - didn't detect a rename
################################################################################
# # Most of the rest of these seem to be files whose rename wasn't properly
# # recorded by git - they're marked as modifications to deleted files. Solve by
# # using the patch we made earlier.
function applyPixarRootDiff ()
{
pxrPath="$1"
adPath=plugin/pxr/"$1"
git apply ../pixar_1905_dev.diff --include="$adPath"
result="$?"
if (( $result == 0 )); then
echo "success!"
git add "$adPath"
git rm "$pxrPath"
else
echo
echo '!!!!!!!!!!!'
echo 'failure!'
echo '!!!!!!!!!!!'
fi
}
function applyPixarMayaDiff ()
{
pxrPath="$1"
adPath=$(echo "$pxrPath" | sed -e 's~third_party/maya~plugin/pxr/maya~')
git apply ../pixar_1905_dev.diff --include="$adPath"
result="$?"
if (( $result == 0 )); then
echo "success!"
git add "$adPath"
git rm "$pxrPath"
else
echo
echo '!!!!!!!!!!!'
echo 'failure!'
echo '!!!!!!!!!!!'
fi
}
# applyPixarRootDiff cmake/macros/Private.cmake
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/batchRenderer.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/batchRenderer.h
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/hdImagingShapeDrawOverride.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/hdImagingShapeUI.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/hdRenderer.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/instancerShapeAdapter.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/proxyDrawOverride.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/proxyShapeDelegate.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/proxyShapeUI.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/sceneDelegate.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/sceneDelegate.h
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/shapeAdapter.cpp
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/shapeAdapter.h
# applyPixarMayaDiff third_party/maya/lib/pxrUsdMayaGL/usdProxyShapeAdapter.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/CMakeLists.txt
# applyPixarMayaDiff third_party/maya/lib/usdMaya/editUtil.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/editUtil.h
# applyPixarMayaDiff third_party/maya/lib/usdMaya/hdImagingShape.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/hdImagingShape.h
# applyPixarMayaDiff third_party/maya/lib/usdMaya/readJob.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/referenceAssembly.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/shadingModeImporter.h
# applyPixarMayaDiff third_party/maya/lib/usdMaya/shadingModePxrRis.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/shadingModeUseRegistry.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdExportPackage.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdExportRfMLight.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdExportShadingModePxrRis.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdImportRfMLight.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdImportShadingModePxrRis.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdMayaGetVariantSetSelections.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdMayaXformStack.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/testenv/testUsdReferenceAssemblyChangeRepresentations.py
# applyPixarMayaDiff third_party/maya/lib/usdMaya/translatorModelAssembly.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/translatorRfMLight.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/translatorUtil.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/translatorUtil.h
# applyPixarMayaDiff third_party/maya/lib/usdMaya/translatorXformable.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/util.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/util.h
# applyPixarMayaDiff third_party/maya/lib/usdMaya/wrapEditUtil.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/writeJob.cpp
# applyPixarMayaDiff third_party/maya/lib/usdMaya/writeJobContext.cpp
# applyPixarMayaDiff third_party/maya/plugin/pxrUsdTranslators/CMakeLists.txt
# applyPixarMayaDiff third_party/maya/plugin/pxrUsdTranslators/fileTextureWriter.cpp
# applyPixarMayaDiff third_party/maya/plugin/pxrUsdTranslators/lightReader.cpp
# applyPixarMayaDiff third_party/maya/plugin/pxrUsdTranslators/lightWriter.cpp
#!/usr/bin/env python
'''Find / replace all files that have the "old" pixar-style apache license with
the new autodesk-style apache license'''
from __future__ import print_function
import argparse
import inspect
import os
THIS_FILE = os.path.normpath(os.path.abspath(inspect.getsourcefile(lambda: None)))
parser = argparse.ArgumentParser(description=__doc__)
mode_group = parser.add_mutually_exclusive_group()
mode_group.add_argument('--mode', choices=['pxr', 'al', 'both'], default='both',
help="Which repo we're trying to replace lics for")
mode_group.add_argument('--al', help='Replace al lics',
action='store_const', const='al', dest='mode')
mode_group.add_argument('--pxr', help='Replace pixar lics',
action='store_const', const='pxr', dest='mode')
parser.add_argument('--reverse', action='store_true',
help=("Replace lics in reverse, removing new and inserting old. "
"Can only be used for one repo at a time (mode 'pxr' or mode 'al', "
"but not mode 'both'"))
args = parser.parse_args()
old_pxr_cpp_lic = """// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License."""
old_pxr_py_lic = """#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
"""
old_al_py_lic = """#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
new_cpp_lic = """// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License."""
new_py_lic = """#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
old_al_cpp_lic_line = """// you may not use this file except in compliance with the License.//"""
new_cpp_lic_line = """// you may not use this file except in compliance with the License."""
old_al_py_lic_line = """# you may not use this file except in compliance with the License.//"""
new_py_lic_line = """# you may not use this file except in compliance with the License."""
if args.mode == 'pxr':
replacement_pairs = [
(old_pxr_cpp_lic, new_cpp_lic),
(old_pxr_py_lic, new_py_lic),
]
elif args.mode == 'al':
replacement_pairs = [
(old_al_cpp_lic_line, new_cpp_lic_line),
(old_al_py_lic, new_py_lic),
(old_pxr_py_lic, new_py_lic),
(old_al_py_lic_line, new_py_lic_line),
]
elif args.mode == 'both':
if args.reverse:
raise ValueError("--reverse cannot be used with mode 'both'")
replacement_pairs = [
(old_pxr_cpp_lic, new_cpp_lic),
(old_pxr_py_lic, new_py_lic),
(old_al_cpp_lic_line, new_cpp_lic_line),
(old_al_py_lic, new_py_lic),
(old_al_py_lic_line, new_py_lic_line),
]
else:
raise ValueError("Unrecognized mode: {}".format(args.mode))
if args.reverse:
replacement_pairs = [(pair[1], pair[0]) for pair in replacement_pairs]
for dirpath, dirnames, filenames in os.walk('.'):
for filename in filenames:
filepath = os.path.normpath(os.path.abspath(os.path.join(dirpath, filename)))
if filepath == THIS_FILE:
continue
with open(filepath, 'rb') as f:
text = f.read()
altered = False
new_text = text
for old_lic, new_lic in replacement_pairs:
if old_lic in new_text:
new_text = new_text.replace(old_lic, new_lic)
altered = True
if altered:
with open(filepath, 'wb') as f:
f.write(new_text)
print("Replaced license in: {}".format(filepath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment