b=393410 r=robcee - python script that uses the browser's own -CreateProfile command-line flag to create new profiles and set prefs for automated testing
authorccooper@deadsquid.com
Tue, 11 Dec 2007 13:43:56 -0800
changeset 8923 fd427a88908216cd11cc4c60cb9a81eef5d928f2
parent 8922 0355856ad7d6f43968e9e6c557088edab98c8d27
child 8924 3b2d3e548f32310ec2b2a04c63df1536d3a44c94
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs393410
milestone1.9b3pre
b=393410 r=robcee - python script that uses the browser's own -CreateProfile command-line flag to create new profiles and set prefs for automated testing
testing/tools/profiles/createTestingProfile.py
new file mode 100644
--- /dev/null
+++ b/testing/tools/profiles/createTestingProfile.py
@@ -0,0 +1,103 @@
+import getopt
+import os
+import re
+import shutil
+from subprocess import Popen,PIPE
+import sys
+
+# If you are adding prefs that require string values (rather than true/false),
+# be sure to wrap the string value in quotes, e.g.:
+# 'browser.active_color': '"#EE0000"',
+userPrefs = {
+    'browser.chrome.favicons': 'false',
+    'browser.chrome.site_icons': 'false',
+    'browser.dom.window.dump.enabled': 'true',
+    'browser.sessionstore.enabled': 'false',
+    'browser.sessionstore.resume_from_crash': 'false',
+    'browser.shell.checkDefaultBrowser': 'false',
+    'dom.allow_scripts_to_close_windows': 'true',
+    'dom.disable_open_during_load': 'false',
+    'dom.disable_window_flip': 'false',
+    'dom.disable_window_move_resize': 'false',
+    'layout.fire_onload_after_image_background_loads': 'true',
+    'javascript.options.showInConsole': 'true',
+    'privacy.popups.firstTime': 'false'
+}
+
+def usage():
+    print "python " + sys.argv[0] + " --binary=binary_location [--profileName=default] [--clobber] [--help]" 
+
+def runCreateProfile(binary,profileName):
+    cmd = binary + " -CreateProfile " + profileName
+    p = Popen(cmd, 
+              shell=True, 
+              stdin=PIPE, 
+              stdout=PIPE, 
+              stderr=PIPE)
+    for line in p.stderr:
+        m = re.search('Success: created profile .* at \'([^\']+)\'',
+                      line)
+        if m:
+            return m.group(1)
+    return ""
+
+def populatePrefs(profileLocation):
+    try:
+        f = open(profileLocation, 'w')
+    except IOError:
+        print "Couldn't write to " + profileLocation
+        sys.exit(2)
+    f.write("/* Generated by buildbot */\n\n")
+    for key in userPrefs.keys():
+        f.write('user_pref("' + key + '", ' + userPrefs[key] + ");\n")
+    f.close()
+    print "Wrote testing preferences to %s" % profileLocation
+
+def main(argv):
+    try:
+        opts, args = getopt.getopt(argv, 
+                                   "hb:p:cd", 
+                                   ["help", 
+                                    "binary=", 
+                                    "profileName=",
+                                    "clobber"])
+    except getopt.GetoptError:
+	usage()
+        sys.exit(2)
+
+    binary = ""
+    profileName = "default"
+    clobber=0
+    for o,a in opts:
+        if o in ("-h", "--help"):
+            usage()
+            sys.exit()
+        if o in ("-b","--binary"):
+            binary=a
+        if o in ("-p","--profileName"):
+            profileName=a
+        if o in ("-c","--clobber"):
+            clobber=1
+    if binary=="" or not os.path.exists(binary):
+	print binary + " XXX3\n";
+	usage()
+        sys.exit(2)
+
+    profileLocation = runCreateProfile(binary,profileName)
+    if not profileLocation or not os.path.exists(profileLocation):
+        print "Couldn't find profile location"
+        sys.exit(2)
+    # Delete the existing profile directory if clobber is requested.
+    # -CreateProfile will re-create it in the right place.
+    if clobber:
+        dirname = os.path.dirname(profileLocation)
+        shutil.rmtree(dirname)
+        profileLocation = runCreateProfile(binary,profileName)
+        if not profileLocation or not os.path.exists(profileLocation):
+            print "Couldn't find profile location on second pass"
+            sys.exit(2)
+
+    populatePrefs(profileLocation)
+
+if __name__ == "__main__":
+    main(sys.argv[1:])