svn bulk update projects on your local from one branch to other

Many a times we have to switch projects from one svn branch to other in our workspaces. With handful of projects it is easy to do in your editor or to use command line.

However if the number if projects is bigger, it become monotnous boring and cumbersome.

Following is the simple Python program to help with your svn switches.

Usage of program is very simple.

Save the folowing program and execute it with python 3.x.

Rest of the course is simple and interactive.


import sys
import subprocess

PROJECT_DIR=""
SVN_BRANCH_OLD=""
SVN_BRANCH_NEW=""

if (len(sys.argv) < 3 or len(sys.agrv) > 3):
    sys.stdout.write("\033[0;32m")
    print ("Three arguments are required. First is parent directory where all projects reside.")
    print ("Second is name of current branch. Only provide the part of URL that has changed")
    print ("Third is name of the branch, to which ou want to change. Only provide the part of URL that need to be changed")
    sys.stdout.write("\033[0;0m")

    print("\n")
    PROJECT_DIR = raw_input("Provide path of directory where all projects reside : ")
    SVN_BRANCH_OLD = raw_input("Provide the current branch to which the projects belong : ")
    SVN_BRANCH_NEW = raw_input("Provide the branch name to which you want to change : ")
else :
    PROJECT_DIR = sys.argv[0]
    SVN_BRANCH_OLD = sys.argv[1]
    SVN_BRANCH_NEW = sys.argv[2]

import os

if (os.path.isdir(PROJECT_DIR) == False):
    print("Provided Path is not a directory. Program exiting, cannot proceed!")
    sys.exit()

for x in next(os.walk(PROJECT_DIR))[1]:
    project = os.path.join(PROJECT_DIR,x)
    for y in next(os.walk(project))[1]:
        if y == '.svn':
            this_branch = subprocess.check_output('svn info '+project+'| egrep \"^URL:\"', shell=True)
            this_branch = this_branch[5:].rstrip("\n\r")
            if SVN_BRANCH_OLD in this_branch:
                switch_to_branch = this_branch.replace(SVN_BRANCH_OLD,SVN_BRANCH_NEW)
                print("switching project: "+project+", to branch: "+ switch_to_branch)
                subprocess.call('svn switch '+switch_to_branch + " "+ project, shell=True)
            else:
                print(this_branch +" does not contain path : "+SVN_BRANCH_OLD+". Skipping project : "+x)

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java