use tor from platform package

This commit is contained in:
j 2016-02-23 12:35:52 +05:30
parent 04a1c6b951
commit 0e44e319c4

View file

@ -74,14 +74,16 @@ DirReqStatistics 0
self.installing = False
tor = get_tor()
if tor:
if 'TorBrowser' in tor and sys.platform.startswith('linux'):
if sys.platform.startswith('linux') and (
'TorBrowser' in tor or tor.startswith(os.path.dirname(settings.base_dir))
):
env = {
'LD_LIBRARY_PATH': os.path.dirname(tor)
}
else:
env = None
cmd = [tor, '--defaults-torrc', defaults, '-f', torrc, 'DataDirectory', tor_data]
cmd += self.geoip(tor)
cmd += get_geoip(tor)
cwd = os.path.dirname(tor)
while self.running:
if sys.platform == 'win32':
@ -99,17 +101,6 @@ DirReqStatistics 0
time.sleep(0.5)
self.p = None
def geoip(self, tor):
geo = []
tordir = os.path.dirname(os.path.dirname(tor))
gepipfile = os.path.join(tordir, 'Data', 'Tor', 'geoip')
gepipv6file = os.path.join(tordir, 'Data', 'Tor', 'geoip6')
if os.path.exists(gepipfile):
geo += ['GeoIPFile', gepipfile]
if os.path.exists(gepipv6file):
geo += ['GeoIPv6File', gepipv6file]
return geo
def kill(self):
self.running = False
if self.p:
@ -281,13 +272,16 @@ def torbrowser_url(sys_platform=None):
def get_tor():
if sys.platform == 'darwin':
for path in (
os.path.join(settings.base_dir, '..', 'platform_darwin64', 'tor', 'tor'),
'/Applications/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 = []
paths = [
os.path.join(settings.base_dir, '..', 'platform_win32', 'tor', 'tor.exe')
]
exe = os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe')
for prefix in (
os.path.join(os.path.expanduser('~'), 'Desktop'),
@ -299,7 +293,14 @@ def get_tor():
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
return os.path.normpath(path)
elif sys.platform.startswith('linux'):
for path in (
os.path.join(settings.base_dir, '..', 'platform_linux64', 'tor', 'tor'),
os.path.join(settings.base_dir, '..', 'platform_linux32', 'tor', 'tor'),
):
if os.path.isfile(path) and os.access(path, os.X_OK):
return os.path.normpath(path)
start = os.path.expanduser('~/.local/share/applications/start-tor-browser.desktop')
if os.path.exists(start):
with open(start) as fd:
@ -318,6 +319,22 @@ def get_tor():
return local_tor
return distutils.spawn.find_executable('tor')
def get_geoip(tor):
geo = []
for tordir in (
os.path.normpath(os.path.join(settings.base_dir, '..', 'platform', 'tor')),
os.path.join(os.path.dirname(os.path.dirname(tor)), 'Data', 'Tor')
):
gepipfile = os.path.join(tordir, 'geoip')
gepipv6file = os.path.join(tordir, 'geoip6')
if os.path.exists(gepipfile):
geo += ['GeoIPFile', gepipfile]
if os.path.exists(gepipv6file):
geo += ['GeoIPv6File', gepipv6file]
if geo:
break
return geo
def install_tor():
import tarfile
import update