|
# Copyright 2016 Brad van der Laan |
|
# |
|
# 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. |
|
|
|
import sys |
|
import subprocess |
|
import shlex |
|
|
|
def print_help_message(): |
|
print("===============================================") |
|
print(" Create SVN Author Transform File For Git") |
|
print(" Version 1.0.0") |
|
print("===============================================") |
|
print("This script will retrieve all the SVN authors") |
|
print("for the given SVN repository and produce a transform") |
|
print("file which can be used to convert the SVN authors") |
|
print("to proper Git authors when converting from SVN to Git.") |
|
print("") |
|
print("This python script wrapper was created by me but the") |
|
print("bash script was taken from John Albin") |
|
print(" http://john.albin.net/git/convert-subversion-to-git") |
|
print("") |
|
print("Example:") |
|
print(" python createSVNAuthorTransform.py svn://myRepo") |
|
print("OR") |
|
print(" python createSVNAuthorTransform.py svn://myRepo author-transform.txt") |
|
print("") |
|
print("The first example will output to author-transform.txt by default the second") |
|
print("example lets you specify where to save the list of SVN authors.") |
|
|
|
|
|
if __name__ == "__main__": |
|
if len(sys.argv) > 1: |
|
svnRepoUrl = sys.argv[1] |
|
outputFileName = "authors-transform.txt" |
|
|
|
if len(sys.argv) == 3: |
|
outputFileName = sys.argv[2] |
|
|
|
print("================================") |
|
print("Generating SVN Author Transform File") |
|
print("SVN Repository: ", svnRepoUrl) |
|
print("Transform File: ", outputFileName) |
|
|
|
firstCommand = "svn log -q " + svnRepoUrl |
|
firstArgs = shlex.split(firstCommand) |
|
|
|
secondCommand = "awk -F \"'|'\" '/^r/ {sub(\"^ \", \"\", $2); sub(\" $\", \"\", $2); print $2\" = \"$2\" <\"$2\">\"}'" |
|
secondArgs = shlex.split(secondCommand) |
|
|
|
getSVNAuthors = subprocess.Popen(firstArgs, stdout=subprocess.PIPE) |
|
filterSVNAuthors = subprocess.Popen(secondArgs, stdin=getSVNAuthors.stdout, stdout=subprocess.PIPE) |
|
getSVNAuthors.stdout.close() |
|
output,err = filterSVNAuthors.communicate() |
|
|
|
unique_list_of_authors = set(output.decode("utf-8").split('\n')) |
|
with open(outputFileName, 'wb', 0) as outfile: |
|
for line in unique_list_of_authors: |
|
outfile.write((line + '\n').encode("utf-8")) |
|
print("================================") |
|
else: |
|
print_help_message() |