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