tor versions can be N.N and N.N.N, install expert bundle on win32

This commit is contained in:
j 2016-01-31 14:07:14 +05:30
parent 5bbb5849cb
commit a55773f4d5

View file

@ -5,6 +5,7 @@ import subprocess
import time
from threading import Thread
import distutils
import zipfile
import ox
import stem
@ -207,31 +208,41 @@ class Tor(object):
def is_online(self):
return self.connected and self.controller.is_alive() and utils.can_connect_dns()
def torbrowser_url():
def torbrowser_url(sys_platform=None):
import re
from ox.cache import read_url
if not sys_platform:
sys_platform = sys.platform
base_url = 'https://dist.torproject.org/torbrowser/'
r = re.compile('href="(\d\.\d\.\d/)"')
current = sorted(r.findall(read_url(base_url, timeout=3*24*60*60).decode()))[-1]
data = read_url(base_url, timeout=3*24*60*60).decode()
versions = []
for r in (
re.compile('href="(\d\.\d\.\d/)"'),
re.compile('href="(\d\.\d/)"'),
):
versions += r.findall(data)
current = sorted(versions)[-1]
url = base_url + current
if sys.platform.startswith('linux'):
language = '.*?en'
if sys_platform.startswith('linux'):
import platform
if platform.architecture()[0] == '64bit':
osname = 'linux64'
else:
osname = 'linux32'
ext = 'xz'
elif sys.platform == 'darwin':
elif sys_platform == 'darwin':
osname = 'osx64'
ext = 'dmg'
elif sys.platform == 'win32':
osname = 'install'
ext = 'exe'
elif sys_platform == 'win32':
language = ''
osname = ''
ext = 'zip'
else:
logger.debug('no way to get torbrowser url for %s', sys.platform)
return None
r = re.compile('href="(.*?{osname}.*?en.*?{ext})"'.format(osname=osname,ext=ext))
r = re.compile('href="(.*?{osname}{language}.*?{ext})"'.format(osname=osname,language=language,ext=ext))
torbrowser = sorted(r.findall(read_url(url).decode()))[-1]
url += torbrowser
return url
@ -240,10 +251,24 @@ def get_tor():
if sys.platform == 'darwin':
for path in (
'/Applications/TorBrowser.app/TorBrowser/Tor/tor',
os.path.join(settings.base_dir, 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor')
os.path.join(settings.base_dir, '..', 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor')
):
if os.path.isfile(path) and os.access(path, os.X_OK):
return path
elif sys.platform == 'win32':
paths = []
exe = os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe')
for prefix in (
os.path.join(os.path.expanduser('~'), 'Desktop'),
os.path.join('C:', 'Program Files'),
os.path.join('C:', 'Program Files (x86)'),
):
path = os.path.join(prefix, exe)
paths.append(path)
paths.append(os.path.join(settings.base_dir, '..', 'tor', 'Tor', 'tor.exe'))
for path in paths:
if os.path.isfile(path) and os.access(path, os.X_OK):
return path
start = os.path.expanduser('~/.local/share/applications/start-tor-browser.desktop')
if os.path.exists(start):
with open(start) as fd:
@ -306,5 +331,15 @@ def install_tor():
os.unlink(dmg)
except:
logger.debug('tor installation failed', exc_info=True)
elif sys.platform == 'win32':
try:
ox.makedirs(target)
zipf = os.path.join(target, os.path.basename(url))
update.get(url, zipf)
f = zipfile.ZipFile(zipf)
f.extractall(target)
os.unlink(zipf)
except:
logger.debug('tor installation failed', exc_info=True)
else:
logger.debug('no way to install TorBrowser on %s so far', sys.platform)