Test bustage fix by using specific event listener.
[wine-gecko.git] / testing / tools / profiles / createTestingProfile.py
blob3a8482ecbecd4cef5633e3e86f3dc26809faf372
1 import getopt
2 import os
3 import re
4 import shutil
5 from subprocess import Popen,PIPE
6 import sys
8 # If you are adding prefs that require string values (rather than true/false),
9 # be sure to wrap the string value in quotes, e.g.:
10 # 'browser.active_color': '"#EE0000"',
11 userPrefs = {
12 'browser.chrome.favicons': 'false',
13 'browser.chrome.site_icons': 'false',
14 'browser.dom.window.dump.enabled': 'true',
15 'browser.sessionstore.resume_from_crash': 'false',
16 'browser.shell.checkDefaultBrowser': 'false',
17 'browser.tabs.warnOnClose': 'false',
18 'browser.warnOnQuit': 'false',
19 'dom.allow_scripts_to_close_windows': 'true',
20 'dom.disable_open_during_load': 'false',
21 'dom.disable_window_flip': 'false',
22 'dom.disable_window_move_resize': 'false',
23 'layout.fire_onload_after_image_background_loads': 'true',
24 'javascript.options.showInConsole': 'true',
25 'privacy.popups.firstTime': 'false',
26 'layout.debug.enable_data_xbl': 'true',
27 'shell.checkDefaultClient': 'false',
28 'browser.EULA.override': 'true'
31 def usage():
32 print "python " + sys.argv[0] + " --binary=binary_location [--profileName=default] [--clobber] [--help]"
34 def runCreateProfile(binary,profileName):
35 cmd = binary + " -CreateProfile " + profileName
36 p = Popen(cmd,
37 shell=True,
38 stdin=PIPE,
39 stdout=PIPE,
40 stderr=PIPE)
41 for line in p.stderr:
42 m = re.search('Success: created profile .* at \'([^\']+)\'',
43 line)
44 if m:
45 return m.group(1)
46 return ""
48 def populatePrefs(profileLocation):
49 try:
50 f = open(profileLocation, 'w')
51 except IOError:
52 print "Couldn't write to " + profileLocation
53 sys.exit(2)
54 f.write("/* Generated by buildbot */\n\n")
55 for key in userPrefs.keys():
56 f.write('user_pref("' + key + '", ' + userPrefs[key] + ");\n")
57 f.close()
58 print "Wrote testing preferences to %s" % profileLocation
60 def main(argv):
61 try:
62 opts, args = getopt.getopt(argv,
63 "hb:p:cd",
64 ["help",
65 "binary=",
66 "profileName=",
67 "clobber"])
68 except getopt.GetoptError:
69 usage()
70 sys.exit(2)
72 binary = ""
73 profileName = "default"
74 clobber=0
75 for o,a in opts:
76 if o in ("-h", "--help"):
77 usage()
78 sys.exit()
79 if o in ("-b","--binary"):
80 binary=a
81 if o in ("-p","--profileName"):
82 profileName=a
83 if o in ("-c","--clobber"):
84 clobber=1
85 if binary=="" or not os.path.exists(binary):
86 usage()
87 sys.exit(2)
89 profileLocation = runCreateProfile(binary,profileName)
90 if not profileLocation or not os.path.exists(profileLocation):
91 print "Couldn't find profile location"
92 sys.exit(2)
93 # Delete the existing profile directory if clobber is requested.
94 # -CreateProfile will re-create it in the right place.
95 if clobber:
96 dirname = os.path.dirname(profileLocation)
97 shutil.rmtree(dirname)
98 profileLocation = runCreateProfile(binary,profileName)
99 if not profileLocation or not os.path.exists(profileLocation):
100 print "Couldn't find profile location on second pass"
101 sys.exit(2)
103 populatePrefs(profileLocation)
105 if __name__ == "__main__":
106 main(sys.argv[1:])