You are on page 1of 2

import cgitb

cgitb.enable()
import sys
import os
import shutil

def main():

################################## if a newly added file or testcase baseline need


to be updated. This will make the new folder hierarchy as required and then copy
the baseline ############################
########################################################## The entire newly formed
directory will be formed and copied in the baseline folder
############################################################

(filepath, filename) = os.path.split(sys.argv[2])


if not os.path.exists(filepath):
src = sys.argv[1]
dst = sys.argv[2]
a=-1
b=0
skip_list = []

while not os.path.exists(dst):


(c,d) = os.path.split(dst)
dst = c
(x,y) = os.path.split(dst)

while d != y:
(c,d) = os.path.split(src)
skip_list.append(d)
src = c
a+=1

newsrc = os.path.join( src,skip_list[a])


newsrc = os.path.join( newsrc,skip_list[a-1])

newdst = os.path.join(dst,skip_list[a-1])

try:
shutil.copytree(newsrc,newdst)
except EnvironmentError:
print "content-type: text/html\n"
print "<h1>Error happened in copying . Baseline not updated</h1>"
else:
print "content-type: text/html\n"
print "<h1>Baseline has been updated successfully</h1>"

######################################################## if older existing


baselines need to be updated ###################################################
else:
dst = sys.argv[2]
#listing all files in the result directory
files = os.listdir(sys.argv[3])
#base_prev_modtime = os.stat(dst).st_mtime

# running a loop for each of the file to check whether it's a .pdf or .ps
for file in files:
(Name,exten) = os.path.splitext(file)
if ( exten == ".pdf"):
path1 = sys.argv[3] + os.sep + file
(filepath1, filename1) = os.path.split(dst)
(shortname, extension) = os.path.splitext(filename1)
(filepath2, filename2) = os.path.split(dst)
if(extension==".ps"):
shutil.copy2(path1,filepath2)
if(extension==".pdf"):
shutil.copy2(path1,filepath2)

#base_prev_modtime = os.stat(dst).st_mtime

if(0):
print "content-type: text/html\n"
print "<h1>Error happened in copying. Baseline not updated</h1>"
else:
print "content-type: text/html\n"
print "<h1>Baseline has been updated successfully</h1>"

if __name__ == "__main__":
main()

You might also like