Added missing fxinstall file. Added 64-bit support for nightly downloads.
authorMark Cote <mcote@mozilla.com>
Thu, 29 Sep 2011 13:10:15 -0400
changeset 74 56a6c907e9e60f04767babd1825c45a185e516d9
parent 73 f62ed3cc3b08592a22bf803d4702405de0ef63e6
child 75 74380b40e37ab283752df7d6700b58825b8a103e
push id72
push usermcote@mozilla.com
push dateThu, 29 Sep 2011 17:10:23 +0000
Added missing fxinstall file. Added 64-bit support for nightly downloads.
client/fxinstall.py
client/speedtests.py
new file mode 100644
--- /dev/null
+++ b/client/fxinstall.py
@@ -0,0 +1,75 @@
+import ftplib
+import re
+import sys
+import zipfile
+
+# taken from one of the comments at
+#   http://code.activestate.com/recipes/285264-natural-string-sorting/
+def keynat(string):
+    r'''A natural sort helper function for sort() and sorted()
+    without using regular expression.
+
+    >>> items = ('Z', 'a', '10', '1', '9')
+    >>> sorted(items)
+    ['1', '10', '9', 'Z', 'a']
+    >>> sorted(items, key=keynat)
+    ['1', '9', '10', 'Z', 'a']
+    '''
+    r = []
+    for c in string:
+        try:
+            c = int(c)
+            try: r[-1] = r[-1] * 10 + c
+            except: r.append(c)
+        except:
+            r.append(c)
+    return r
+
+
+class FirefoxInstaller(object):
+    
+    WIN32ZIP_RE = re.compile('firefox-.*.en-US.win32.zip')
+    WIN64ZIP_RE = re.compile('firefox-.*.en-US.win64-x86_64.zip')
+
+    def __init__(self, install_path, win64=False):
+        self.install_path = install_path
+        self.win64 = win64
+        self.zip_files = []
+
+    def get_install(self):
+        filename = self.get_zip()
+        if filename:
+            self.install(filename)
+        return bool(filename)
+
+    def dir_cb(self, line):
+        if self.win64:
+            m = FirefoxInstaller.WIN64ZIP_RE.search(line)
+        else:
+            m = FirefoxInstaller.WIN32ZIP_RE.search(line)
+        if m:
+            self.zip_files.append(m.group(0))
+
+    def get_zip(self):
+        self.zip_files = []
+        filename = ''
+        ftp = ftplib.FTP('ftp.mozilla.org')
+        ftp.login()
+        ftp.cwd('/pub/mozilla.org/firefox/nightly/latest-trunk/')
+        ftp.dir(self.dir_cb)
+        if self.zip_files:
+            # use natural sorting since 10 > 9
+            self.zip_files.sort(key=keynat)
+            filename = self.zip_files[-1]
+            ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
+        ftp.quit()
+        return filename
+    
+    def install(self, filename):
+        zip = zipfile.ZipFile(filename, 'r')
+        zip.extractall(self.install_path)
+
+
+if __name__ == '__main__':
+    fxins = FirefoxInstaller(None)
+    fxins.get_install()
--- a/client/speedtests.py
+++ b/client/speedtests.py
@@ -24,16 +24,17 @@ if platform.system() == 'Windows':
 import fxinstall
 import results
 
 class Config(object):
     DEFAULT_CONF_FILE = 'speedtests.conf'
     
     def __init__(self):
         self.cfg = None
+        self.sixtyfour_bit = False
         self.local_port = 8111
         self.server_html_url = 'http://brasstacks.mozilla.com/speedtests'
         self.server_api_url = 'http://brasstacks.mozilla.com/speedtests/api'
         self.cfg = None
         self.local_test_base_path = '/speedtests'
 
     @property
     def local_test_base_url(self):
@@ -44,16 +45,21 @@ class Config(object):
 
     def read(self, testmode=False, noresults=False, conf_file=None):
         self.testmode = testmode
         self.noresults = noresults
         if not conf_file:
             conf_file = Config.DEFAULT_CONF_FILE
         self.cfg = ConfigParser.ConfigParser()
         self.cfg.read(conf_file)
+
+        try:
+            self.sixtyfour_bit = self.cfg.getboolean('speedtests', '64bit')
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+            pass
         
         try:
             self.local_port = self.cfg.getint('speedtests', 'local_port')
         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
             pass
         
         try:
             self.server_html_url = self.cfg.get('speedtests', 'test_base_url').rstrip('/')
@@ -259,17 +265,17 @@ class LatestFxBrowserController(BrowserC
         cmd = os.path.join(os.getenv('USERPROFILE'), LatestFxBrowserController.INSTALL_SUBDIR, 'firefox', 'firefox.exe')
         super(LatestFxBrowserController, self).__init__(os_name, browser_name, profiles, cmd)
 
     def init_browser(self):
         if self.os_name == 'windows':
             user_profile = os.getenv('USERPROFILE')
             install_path = os.path.join(user_profile, LatestFxBrowserController.INSTALL_SUBDIR)
             shutil.rmtree(install_path, ignore_errors=True)
-            fxins = fxinstall.FirefoxInstaller(install_path)
+            fxins = fxinstall.FirefoxInstaller(install_path, config.sixtyfour_bit)
             print 'Getting firefox nightly...'
             if not fxins.get_install():
                 print 'Failed to get firefox nightly.'
         
     def launch(self, url=None):
         if self.os_name == 'windows':
             return super(LatestFxBrowserController, self).launch(url)