Skip to content

Instantly share code, notes, and snippets.

@moonblade
Created December 29, 2017 12:51
Show Gist options
  • Save moonblade/484be2e6944545adfd6768b99ee55333 to your computer and use it in GitHub Desktop.
Save moonblade/484be2e6944545adfd6768b99ee55333 to your computer and use it in GitHub Desktop.
import webbrowser
import subprocess
import os, shutil
from pygit2 import Repository
import win32api
import requests
import filecmp
import globalConstants
servicePack = globalConstants.currentAdminConsoleWorkspace
cvsTag = {
"SP10" : "REL_11_0_0_B80_SP10_BRANCH",
"SP11" : "REL_11_0_0_BRANCH",
"SP11lazy" : "REL_11_0_0_BRANCH",
"2017_12_27" : "REL_11_0_0_BRANCH",
}
cvsIndividual = False
deleteExisting = True
base = "D:\\adminConsole\\"
directory = base + servicePack
archiveLocation = base + "archive\\"+servicePack+"\\"
networkBase = "\\\\MKOLAKKAT\\adminConsole\\archive\\"+servicePack+"\\"
tagsToRemove = ["CVS", ".#", ".cache-loader", ".gitignore", "generated", "_"]
beyondComparePath = "C:\\Program Files\\Beyond Compare 4\\Bcompare.exe"
openFilesForView = True
binaryFinderPostUrl = "http://latestweb.commvault.com/binfinder/search.jsp"
version = '11.0 MAIN BRANCH'
windows = "windows"
unix = "unix"
def getTag(tag):
if tag in cvsTag:
return cvsTag[tag]
return "REL_11_0_0_BRANCH"
def message(mes):
win32api.MessageBox(0, mes, 'alert')
def clean(string):
retString = ''.join(line + '\n' for line in string.split('\n') if len(line)>0 and not any(tag in line for tag in tagsToRemove))
return retString
def getBinaries(s, os):
first = "<span class='result-header'>Matches were found in these <u>"+os+"</u> binaries:</span><br/>"
last = "<br/><hr/>"
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end].replace("<br/>","\n")
except ValueError:
return ""
if not os.path.exists(archiveLocation):
os.makedirs(archiveLocation)
# check if current branch has form associated with it
os.chdir(directory)
currentBranch = Repository('.').head.shorthand
if currentBranch[0]=='f':
formNumber = currentBranch[1:]
archivePath = archiveLocation + formNumber + "\\"
filesChangedFileName = archivePath + "filesChanged.txt"
binariesRequired = archivePath + "binariesRequired.txt"
networkFileName = archivePath + "networkPath.txt"
networkPath = networkBase + formNumber
if deleteExisting:
if os.path.exists(archivePath):
shutil.rmtree(archivePath)
if not os.path.exists(archivePath):
os.makedirs(archivePath)
print("\n\nForm : " + formNumber)
print("Path : " + archivePath)
# get diff files and remove unneccessary ones
fileNames = subprocess.check_output("git diff master --name-only")
fileNames = clean(fileNames)
tempFile = open(filesChangedFileName, 'w')
tempFile.write(fileNames)
tempFile.close();
subprocess.Popen(['C:\Program Files\Sublime Text 3\subl.exe','-w',filesChangedFileName]).wait()
if (openFilesForView):
with open(filesChangedFileName, "r") as tempFile:
fileNames=''.join(line for line in tempFile)
# download files from cvs
os.chdir(archivePath)
if cvsIndividual:
for fileName in fileNames.split('\n'):
cvsCommand = 'cvs co -r '+getTag(servicePack)+' ' + fileName
os.system(cvsCommand)
else:
cvsCommand = 'cvs co -r '+getTag(servicePack)+' ' + fileNames.replace('\n',' ')
os.system(cvsCommand)
# open beyond compare for all files and copy my changes
os.chdir(directory)
fileNames=fileNames.replace("/","\\")
for fileName in fileNames.split('\n'):
if len(fileName)>0 and not filecmp.cmp(archivePath+fileName, fileName):
subprocess.Popen([beyondComparePath, archivePath + fileName, fileName])
print("BC4 " + fileName)
print("Copied " + fileName)
pathFile = open(networkFileName, 'w')
pathFile.write(networkPath)
pathFile.close();
subprocess.Popen(['C:\Program Files\Sublime Text 3\subl.exe',filesChangedFileName])
subprocess.Popen(['C:\Program Files\Sublime Text 3\subl.exe',networkFileName])
# get binaries required
req = requests.post(binaryFinderPostUrl, data={'version': version, 'search' : fileNames})
if(req.status_code==200):
binariesRequiredFile = open(binariesRequired, "w")
binariesRequiredFile.write(windows + "\n")
binariesRequiredFile.write(getBinaries(req.text,windows))
binariesRequiredFile.write("\n\n")
binariesRequiredFile.write(unix + "\n")
binariesRequiredFile.write(getBinaries(req.text,unix))
binariesRequiredFile.close()
subprocess.Popen(['C:\Program Files\Sublime Text 3\subl.exe',binariesRequired])
else:
message('Edit branch name to be "f<form number>"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment