2009-10-05 Chris Toshok <toshok@ximian.com>
[moon.git] / test / saveMasters.py
blob2d5ba6922dcf0c30488c92bf3cf9f5e1a25a0153
1 #!/usr/bin/python
3 ##################
4 # Important: This script is to be run from trunk/moon/test in WINDOWS
5 # This script grabs all the rendered pngs and tifs created by Silverlight
6 # and renames them as masters for Moonlight testing
7 ###############
10 import sys,os
11 import getopt
13 def usage():
14 print "\nUsage: saveMasters.py [--missing, --regen]\n"
16 def main():
18 # saveMasters.py --missing, --regen
20 regen = False
21 missing = False
23 try:
24 shortopts = 'hmr'
25 longopts = ['help','missing','regen']
26 opts, args = getopt.getopt(sys.argv[1:],shortopts, longopts)
27 except getopt.GetoptError, err:
28 print str(err)
29 sys.exit(1)
32 for o, a in opts:
33 if o in ('-h','--help'):
34 usage()
35 return
36 if o in ('-m','--missing'):
37 missing = True
38 if o in ('-r','--regen'):
39 regen = True
41 if not (missing or regen):
42 usage()
43 sys.exit(1)
45 files = os.listdir(os.path.join(os.getcwd(),'xaml'))
47 new_masters_count = 0
48 new_masters = []
50 for curfile in files:
51 newfile = ''
52 testname = curfile[:-9]
53 if curfile.endswith('.xaml.png'):
54 newfile = curfile[:-9] + 'Master.png'
56 if curfile.endswith('.xaml.tif'):
57 newfile = curfile[:-9] + 'Master.tif'
59 if newfile != '':
60 curpath = os.path.join('xaml',curfile)
61 newpath = os.path.join('harness','masters',newfile)
63 if regen:
64 if os.path.exists(newpath):
65 print 'Deleting master for %s' % testname
66 os.remove(newpath)
67 new_masters.append(testname)
68 #print 'Moving %s to %s' % (curpath, newpath)
69 os.rename(curpath, newpath)
71 else: # missing only - not regen
72 if os.path.exists(newpath):
73 pass
74 #print 'Master exists at %s' % newpath
75 else:
76 new_masters.append(testname)
77 #new_masters_count += 1
78 #print 'Moving %s to %s' % (curpath, newpath)
79 os.rename(curpath, newpath)
81 print "\n%s new masters found" % len(new_masters)
82 for testname in new_masters:
83 print "\t%s" % testname
86 if __name__ == '__main__':
87 main()