[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12641: Add script which builds a package from PortableTor and Firef (in torpedo/trunk: . build-scripts)



Author: sjm217
Date: 2007-12-02 18:50:06 -0500 (Sun, 02 Dec 2007)
New Revision: 12641

Added:
   torpedo/trunk/build-scripts/
   torpedo/trunk/build-scripts/buildpackage.py
Log:
Add script which builds a package from PortableTor and FirefoxPortable

Added: torpedo/trunk/build-scripts/buildpackage.py
===================================================================
--- torpedo/trunk/build-scripts/buildpackage.py	                        (rev 0)
+++ torpedo/trunk/build-scripts/buildpackage.py	2007-12-02 23:50:06 UTC (rev 12641)
@@ -0,0 +1,121 @@
+#!/usr/bin/python
+
+##
+## Produce a Tor+Vidalia+Firefox bundle from PortableTor and FirefoxPortable
+## Steven J. Mudoch <http://www.cl.cam.ac.uk/users/sjm217/>
+## $Id:$
+##
+
+import os
+import shutil
+import subprocess
+import re
+
+## Additional preferences
+preferences = {
+        ## Connect direct to Tor
+        "network.proxy.socks": "127.0.0.1",
+        "network.proxy.socks_port": 9050,
+        "network.proxy.socks_remote_dns": True,
+        "network.proxy.type": 1,
+        
+        ## Disable disk cache
+        "browser.cache.disk.capacity": 0,
+        "browser.cache.disk.enable": False,
+        
+        ## Homepage
+        "browser.startup.homepage": "http://check.torproject.org/";,
+
+        ## Don't check as default
+        "browser.shell.checkDefaultBrowser": False,
+
+        ## Start up with actual browser start page
+        "browser.startup.homepage_override.mstone": "rv:1.8.1.10"
+}
+
+def to_js(val):
+        '''Convert a Python object to Javascript'''
+        if type(val)==str:
+                return '"%s"'%val
+        elif type(val)==bool:
+                if val:
+                        return "true"
+                else:
+                        return "false"
+        else:
+                return str(val)
+
+user_pref_re = re.compile(r'\s*user_pref\("([^"]+)"\s*,\s*("[^"]+"|[^)\s]+)\s*\)\s*;')
+def patch_preferences(origfile, newfile):
+        '''Patch a preferences file'''
+        if origfile == None:
+                origfile = []
+                
+        output = []
+
+        for line in origfile:
+                match = user_pref_re.match(line)
+                if not match:
+                        output.append(line)
+                else:
+                        key = match.group(1)
+                        val = match.group(2)
+                        val = preferences.get(key, val)
+                        if preferences.has_key(key):
+                                del preferences[key]
+                        output.append("user_pref(%s, %s);\n"%(to_js(key), to_js(val)))
+        for k, v in preferences.items():
+                output.append("user_pref(%s, %s);\n"%(to_js(k), to_js(v)))
+        
+        ## prefs.js must be sorted (and other requirements?)
+        output.sort()
+        for o in output:
+                newfile.write(o)
+
+## Output directory (will be overwritten)
+dest = "Tor Browser"
+
+## Extracted directories containing FirefoxPortable and PortableTor
+fp_src = "FirefoxPortable"
+tp_src = "PortableTor/PortableTor"
+
+## 7zip executable
+sevenzip = os.path.join("C:\\", "Program Files", "7-Zip", "7z.exe")
+
+## Make output directory
+try:
+    shutil.rmtree(dest)
+except:
+    pass
+
+os.mkdir(dest)
+
+## Copy over Firefox Portable
+shutil.copytree(fp_src, os.path.join(dest, "FirefoxPortable"))
+shutil.copytree(tp_src, os.path.join(dest, "PortableTor"))
+
+## Set config options
+#prefs_fn = os.path.join(dest, "FirefoxPortable", "App", "DefaultData", "profile", "prefs.js")
+prefs_fn = os.path.join(dest, "FirefoxPortable", "App", "DefaultData", "profile", "user.js")
+#oldprefs_fn = prefs_fn+".orig"
+#shutil.copyfile(prefs_fn, oldprefs_fn)
+
+infile = file(oldprefs_fn, "rt")
+outfile = file(prefs_fn, "wt")
+patch_preferences(infile, outfile)
+infile.close()
+outfile.close()
+
+## Remove Privoxy
+os.unlink(os.path.join(dest, "PortableTor","App","privoxy.exe"))
+shutil.rmtree(os.path.join(dest, "PortableTor","Docs","Privoxy"))
+shutil.rmtree(os.path.join(dest, "PortableTor","Data","Privoxy"))
+
+## Write launcher
+fh = file(os.path.join(dest, "Tor Browser.bat"), "wt")
+fh.write(r'start /b .\PortableTor\App\vidalia.exe --datadir ".\PortableTor\Data\Vidalia\"'+"\n")
+fh.write(r'start /b .\FirefoxPortable\FirefoxPortable.exe'+"\n")
+fh.close()
+
+## Compress it all
+subprocess.call([sevenzip, "a", "-sfx7z.sfx", "Tor Browser.exe", dest], shell=False)             


Property changes on: torpedo/trunk/build-scripts/buildpackage.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + id