[Pkg-privacy-commits] [torbrowser-launcher] 09/39: Replace twisted with requests. Downloads work, but does not handle errors or update the GUI
Roger Shimizu
rosh at debian.org
Tue Mar 27 15:41:51 UTC 2018
This is an automated email from the git hooks/post-receive script.
rosh pushed a commit to branch rosh/experimental
in repository torbrowser-launcher.
commit 39fd6a05d0e0d958f73462cd252f644f030e473b
Author: Micah Lee <micah at micahflee.com>
Date: Thu Mar 22 14:35:25 2018 -0700
Replace twisted with requests. Downloads work, but does not handle errors or update the GUI
---
BUILD.md | 10 +---
torbrowser_launcher/launcher.py | 108 +++++++++++++++-------------------------
2 files changed, 41 insertions(+), 77 deletions(-)
diff --git a/BUILD.md b/BUILD.md
index eaff7bc..79833cd 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -12,25 +12,19 @@ Then install dependencies, build a package, and install:
### Debian, Ubuntu, Linux Mint, etc.
```sh
-sudo apt-get install build-essential dh-python python-all python-stdeb python-gtk2 python-twisted python-lzma python-txsocksx gnupg fakeroot xz-utils tor
-# If you're running an OS that has python-gpg like Ubuntu 17.04+ or Debian 9+, install that too
-sudo apt install python-gpg
+sudo apt-get install build-essential dh-python python3-all python3-stdeb python3-qt5 python3-gpg python3-requests tor
./build_deb.sh
sudo dpkg -i deb_dist/torbrowser-launcher_*.deb
```
-Optionally you can install `python-pygame` if you want to play a modem sound while Tor Browser is launching.
-
### Red Hat, Fedora, CentOS, etc.
```sh
-sudo dnf install python-psutil python-twisted gnupg fakeroot rpm-build python-txsocksx tor pygtk2 python2-gpg
+sudo dnf install rpm-build python3-qt5 python3-gpg python3-requests tor
./build_rpm.sh
sudo yum install dist/torbrowser-launcher-*.rpm
```
-Optionally you can install `pygame` if you want to play a modem sound while Tor Browser is launching.
-
### Run without installing
Install the dependencies: sadly, not all of them are available in virtualenv, so you will need to install (some of) them system-wide.
diff --git a/torbrowser_launcher/launcher.py b/torbrowser_launcher/launcher.py
index 4e27228..e2ac46e 100644
--- a/torbrowser_launcher/launcher.py
+++ b/torbrowser_launcher/launcher.py
@@ -36,22 +36,10 @@ import lzma
import threading
import re
import unicodedata
-
-from twisted.internet import reactor
-from twisted.web.client import Agent, RedirectAgent, ResponseDone, ResponseFailed
-from twisted.web.http_headers import Headers
-from twisted.internet.protocol import Protocol
-from twisted.internet.error import DNSLookupError, ConnectionRefusedError
-
-try:
- import gpg
- gpgme_support = True
-except ImportError:
- gpgme_support = False
-
-import xml.etree.ElementTree as ET
-
+import requests
+import gpg
import OpenSSL
+import xml.etree.ElementTree as ET
from PyQt5 import QtCore, QtWidgets, QtGui
@@ -423,29 +411,28 @@ class Launcher(QtWidgets.QMainWindow):
self.progress_bar.setFormat(_('Downloading') + ' {0}, %p%'.format(name))
if self.common.settings['download_over_tor']:
- from twisted.internet.endpoints import clientFromString
- from txsocksx.http import SOCKS5Agent
-
- torendpoint = clientFromString(reactor, self.common.settings['tor_socks_address'])
-
- # default mirror gets certificate pinning, only for requests that use the mirror
- agent = SOCKS5Agent(reactor, proxyEndpoint=torendpoint)
- else:
- agent = Agent(reactor)
-
- # actually, agent needs to follow redirect
- agent = RedirectAgent(agent)
-
- # start the request
- d = agent.request('GET', mirror_url,
- Headers({'User-Agent': ['torbrowser-launcher']}),
- None)
+ # TODO: make requests work over SOCKS5 proxy
+ # this is the proxy to use: self.common.settings['tor_socks_address']
+ pass
- self.file_download = open(path, 'w')
- d.addCallback(self.response_received).addErrback(self.download_error)
+ with open(self.current_download_path, "wb") as f:
+ # Start the request
+ r = requests.get(mirror_url, headers={'User-Agent': 'torbrowser-launcher'}, stream=True)
+ total_length = r.headers.get('content-length')
- if not reactor.running:
- reactor.run()
+ if total_length is None: # no content length header
+ f.write(r.content)
+ else:
+ dl = 0
+ total_length = int(total_length)
+ for data in r.iter_content(chunk_size=4096):
+ dl += len(data)
+ f.write(data)
+ done = int(50 * dl / total_length)
+ print('{} / {}'.format(dl, total_length), end='\r')
+
+ # Download complete, next task
+ self.run_task()
def try_default_mirror(self, widget, data=None):
# change mirror to default and relaunch TBL
@@ -500,38 +487,23 @@ class Launcher(QtWidgets.QMainWindow):
self.set_state('task', sigerror, ['start_over'], False)
self.update()
- if gpgme_support:
- with gpg.Context() as c:
- c.set_engine_info(gpg.constants.protocol.OpenPGP, home_dir=self.common.paths['gnupg_homedir'])
-
- sig = gpg.Data(file=self.common.paths['sig_file'])
- signed = gpg.Data(file=self.common.paths['tarball_file'])
-
- try:
- c.verify(signature=sig, signed_data=signed)
- except gpg.errors.BadSignatures as e:
- result = str(e).split(": ")
- if result[1] == 'Bad signature':
- gui_raise_sigerror(self, str(e))
- elif result[1] == 'No public key':
- self.common.refresh_keyring(result[0])
- gui_raise_sigerror(self, str(e))
- else:
- self.run_task()
- else:
- FNULL = open(os.devnull, 'w')
- p = subprocess.Popen(['/usr/bin/gpg', '--homedir', self.common.paths['gnupg_homedir'], '--verify',
- self.common.paths['sig_file'], self.common.paths['tarball_file']], stdout=FNULL,
- stderr=subprocess.STDOUT)
- #self.pulse_until_process_exits(p)
- # TODO: reimplement this
- if p.returncode == 0:
- self.run_task()
+ with gpg.Context() as c:
+ c.set_engine_info(gpg.constants.protocol.OpenPGP, home_dir=self.common.paths['gnupg_homedir'])
+
+ sig = gpg.Data(file=self.common.paths['sig_file'])
+ signed = gpg.Data(file=self.common.paths['tarball_file'])
+
+ try:
+ c.verify(signature=sig, signed_data=signed)
+ except gpg.errors.BadSignatures as e:
+ result = str(e).split(": ")
+ if result[1] == 'Bad signature':
+ gui_raise_sigerror(self, str(e))
+ elif result[1] == 'No public key':
+ self.common.refresh_keyring(result[0])
+ gui_raise_sigerror(self, str(e))
else:
- self.common.refresh_keyring()
- gui_raise_sigerror(self, 'GENERIC_VERIFY_FAIL')
- if not reactor.running:
- reactor.run()
+ self.run_task()
def extract(self):
# initialize the progress bar
@@ -610,8 +582,6 @@ class Launcher(QtWidgets.QMainWindow):
os.remove(self.current_download_path)
delattr(self, 'current_download_path')
delattr(self, 'current_download_url')
- if reactor.running:
- reactor.stop()
super(Launcher, self).closeEvent(event)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/torbrowser-launcher.git
More information about the Pkg-privacy-commits
mailing list