Skip to content

Commit

Permalink
Get stable version using torbrowser updater xml
Browse files Browse the repository at this point in the history
The RecommendedTBBVersions file contains current versions of Tor Browser
from all channels, including alpha or beta.

Instead of this, we can use xml file used by Tor Browser's updater in
the "release" channel:
https://dist.torproject.org/torbrowser/update_2/release/Linux_x86_64-gcc3/x/en-US
  • Loading branch information
boklm committed Nov 5, 2015
1 parent da48600 commit e07beac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
4 changes: 2 additions & 2 deletions torbrowser_launcher/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def build_paths(self, tbb_version=None):
'download_dir': tbb_cache+'/download',
'gnupg_homedir': tbb_local+'/gnupg_homedir',
'settings_file': tbb_config+'/settings',
'update_check_url': 'https://www.torproject.org/projects/torbrowser/RecommendedTBBVersions',
'update_check_file': tbb_cache+'/download/RecommendedTBBVersions',
'update_check_url': 'https://dist.torproject.org/torbrowser/update_2/release/Linux_x86_64-gcc3/x/en-US',
'update_check_file': tbb_cache+'/download/release.xml',
'tbb': {
'dir': tbb_local+'/tbb/'+self.architecture,
'dir_tbb': tbb_local+'/tbb/'+self.architecture+'/tor-browser_'+self.language,
Expand Down
37 changes: 10 additions & 27 deletions torbrowser_launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from twisted.internet.ssl import ClientContextFactory
from twisted.internet.error import DNSLookupError

import xml.etree.ElementTree as ET

import OpenSSL

import pygtk
Expand Down Expand Up @@ -488,38 +490,19 @@ def try_tor(self, widget, data=None):
subprocess.Popen([self.common.paths['tbl_bin']])
self.destroy(False)

def get_stable_version(self):
tree = ET.parse(self.common.paths['update_check_file'])
for up in tree.getroot():
if up.tag == 'update' and up.attrib['appVersion']:
return up.attrib['appVersion']
return None

def attempt_update(self):
# load the update check file
try:
versions = json.load(open(self.common.paths['update_check_file']))
latest = None

# filter linux versions
valid = []
for version in versions:
if '-Linux' in version:
valid.append(str(version))
valid.sort()
if len(valid):
versions = valid

if len(versions) == 1:
latest = versions.pop()
else:
stable = []
# remove alphas/betas
for version in versions:
if not re.search(r'a\d-Linux', version) and not re.search(r'b\d-Linux', version):
stable.append(version)
if len(stable):
latest = stable.pop()
else:
latest = versions.pop()

latest = self.get_stable_version()
if latest:
latest = str(latest)
if latest.endswith('-Linux'):
latest = latest.rstrip('-Linux')

self.common.settings['latest_version'] = latest
self.common.settings['last_update_check_timestamp'] = int(time.time())
Expand Down

0 comments on commit e07beac

Please sign in to comment.