]> git.lizzy.rs Git - torbrowser-launcher.git/commitdiff
Fix flake8 style issues
authorMicah Lee <micah@micahflee.com>
Fri, 23 Mar 2018 20:36:37 +0000 (13:36 -0700)
committerMicah Lee <micah@micahflee.com>
Fri, 23 Mar 2018 20:36:37 +0000 (13:36 -0700)
torbrowser_launcher/__init__.py
torbrowser_launcher/common.py
torbrowser_launcher/launcher.py
torbrowser_launcher/settings.py

index 0f99d05f570c3993d59f68174ffdd97d797ed450..b507da040483ab26263ce85b615d21f26133db59 100644 (file)
@@ -71,13 +71,14 @@ def main():
 
     if settings:
         # Settings mode
-        gui = Settings(common, app)
+        Settings(common, app)
 
     else:
         # Launcher mode
-        gui = Launcher(common, app, url_list)
+        Launcher(common, app, url_list)
 
     sys.exit(app.exec_())
 
+
 if __name__ == "__main__":
     main()
index abf86280442d6e3575fe5a7bf93227d616713491..4f579eed01375863ed54e69e6c91435b230a8909 100644 (file)
@@ -34,16 +34,11 @@ import locale
 import pickle
 import json
 import re
-
-try:
-    import gpg
-    gpgme_support = True
-except ImportError:
-    gpgme_support = False
+import gettext
+import gpg
 
 SHARE = os.getenv('TBL_SHARE', sys.prefix+'/share/torbrowser-launcher')
 
-import gettext
 gettext.install('torbrowser-launcher')
 
 # We're looking for output which:
@@ -71,13 +66,6 @@ class Common(object):
         self.mkdir(self.paths['tbb']['dir'])
         self.init_gnupg()
 
-        # allow buttons to have icons
-        try:
-            gtk_settings = gtk.settings_get_default()
-            gtk_settings.props.gtk_button_images = True
-        except:
-            pass
-
     # discover the architecture and language
     def discover_arch_lang(self):
         # figure out the architecture
@@ -129,17 +117,17 @@ class Common(object):
                 language = 'en-US'
             else:
                 language = self.language
-            tarball_filename = 'tor-browser-'+arch+'-'+tbb_version+'_'+language+'.tar.xz'
+            tarball_filename = 'tor-browser-' + arch + '-' + tbb_version + '_' + language + '.tar.xz'
 
             # tarball
-            self.paths['tarball_url'] = '{0}torbrowser/'+tbb_version+'/'+tarball_filename
-            self.paths['tarball_file'] = tbb_cache+'/download/'+tarball_filename
+            self.paths['tarball_url'] = '{0}torbrowser/' + tbb_version + '/' + tarball_filename
+            self.paths['tarball_file'] = tbb_cache + '/download/' + tarball_filename
             self.paths['tarball_filename'] = tarball_filename
 
             # sig
-            self.paths['sig_url'] = '{0}torbrowser/'+tbb_version+'/'+tarball_filename+'.asc'
-            self.paths['sig_file'] = tbb_cache+'/download/'+tarball_filename+'.asc'
-            self.paths['sig_filename'] = tarball_filename+'.asc'
+            self.paths['sig_url'] = '{0}torbrowser/' + tbb_version + '/' + tarball_filename + '.asc'
+            self.paths['sig_file'] = tbb_cache + '/download/' + tarball_filename + '.asc'
+            self.paths['sig_filename'] = tarball_filename + '.asc'
         else:
             self.paths = {
                 'dirs': {
@@ -156,18 +144,20 @@ class Common(object):
                     'tor_browser_developers': os.path.join(SHARE, 'tor-browser-developers.asc')
                 },
                 'mirrors_txt': [os.path.join(SHARE, 'mirrors.txt'),
-                                tbb_config+'/mirrors.txt'],
-                'download_dir': tbb_cache+'/download',
-                'gnupg_homedir': tbb_local+'/gnupg_homedir',
-                'settings_file': tbb_config+'/settings.json',
-                'settings_file_pickle': tbb_config+'/settings',
+                                tbb_config + '/mirrors.txt'],
+                'download_dir': tbb_cache + '/download',
+                'gnupg_homedir': tbb_local + '/gnupg_homedir',
+                'settings_file': tbb_config + '/settings.json',
+                'settings_file_pickle': tbb_config + '/settings',
                 'version_check_url': 'https://aus1.torproject.org/torbrowser/update_3/release/Linux_x86_64-gcc3/x/en-US',
-                'version_check_file': tbb_cache+'/download/release.xml',
+                'version_check_file': tbb_cache + '/download/release.xml',
                 'tbb': {
-                    'changelog': tbb_local+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/Browser/TorBrowser/Docs/ChangeLog.txt',
-                    'dir': tbb_local+'/tbb/'+self.architecture,
-                    'dir_tbb': tbb_local+'/tbb/'+self.architecture+'/tor-browser_'+self.language,
-                    'start': tbb_local+'/tbb/'+self.architecture+'/tor-browser_'+self.language+'/start-tor-browser.desktop',
+                    'changelog': tbb_local + '/tbb/' + self.architecture + '/tor-browser_' +
+                                 self.language + '/Browser/TorBrowser/Docs/ChangeLog.txt',
+                    'dir': tbb_local + '/tbb/' + self.architecture,
+                    'dir_tbb': tbb_local + '/tbb/' + self.architecture + '/tor-browser_' + self.language,
+                    'start': tbb_local + '/tbb/' + self.architecture + '/tor-browser_' +
+                             self.language + '/start-tor-browser.desktop'
                 },
             }
 
@@ -233,38 +223,20 @@ class Common(object):
         :returns: ``True`` if the key is now within the keyring (or was
             previously and hasn't changed). ``False`` otherwise.
         """
-        if gpgme_support:
-            with gpg.Context() as c:
-                c.set_engine_info(gpg.constants.protocol.OpenPGP, home_dir=self.paths['gnupg_homedir'])
-
-                impkey = self.paths['signing_keys'][key]
-                try:
-                    c.op_import(gpg.Data(file=impkey))
-                except:
-                    return False
+        with gpg.Context() as c:
+            c.set_engine_info(gpg.constants.protocol.OpenPGP, home_dir=self.paths['gnupg_homedir'])
+
+            impkey = self.paths['signing_keys'][key]
+            try:
+                c.op_import(gpg.Data(file=impkey))
+            except:
+                return False
+            else:
+                result = c.op_import_result()
+                if result and self.fingerprints[key] in result.imports[0].fpr:
+                    return True
                 else:
-                    result = c.op_import_result()
-                    if result and self.fingerprints[key] in result.imports[0].fpr:
-                        return True
-                    else:
-                        return False
-        else:
-            success = False
-
-            p = subprocess.Popen(['/usr/bin/gpg', '--status-fd', '2',
-                                  '--homedir', self.paths['gnupg_homedir'],
-                                  '--import', self.paths['signing_keys'][key]],
-                                 stderr=subprocess.PIPE)
-            p.wait()
-
-            for output in p.stderr.readlines():
-                match = gnupg_import_ok_pattern.match(output)
-                if match:
-                    if match.group().find(self.fingerprints[key]) >= 0:
-                        success = True
-                        break
-
-            return success
+                    return False
 
     # import gpg keys
     def import_keys(self):
@@ -273,7 +245,7 @@ class Common(object):
         :returns: ``True`` if all keys were successfully imported; ``False``
             otherwise.
         """
-        keys = ['tor_browser_developers',]
+        keys = ['tor_browser_developers', ]
         all_imports_succeeded = True
 
         for key in keys:
index c058b70ddba18820186ed64db72971da0f8c24a6..37fff94489c255fd8b97c21e2da737a83a0b66f8 100644 (file)
@@ -29,15 +29,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 import os
 import subprocess
 import time
-import json
 import tarfile
-import hashlib
 import lzma
-import threading
 import re
-import unicodedata
 import requests
-import socks
 import gpg
 import xml.etree.ElementTree as ET
 
@@ -86,18 +81,19 @@ class Launcher(QtWidgets.QMainWindow):
             if not self.common.settings['installed']:
                 download_message = _("Downloading and installing Tor Browser for the first time.")
             elif not self.check_min_version():
-                download_message = _("Your version of Tor Browser is out-of-date. Downloading and installing the newest version.")
+                download_message = _("Your version of Tor Browser is out-of-date. "
+                                     "Downloading and installing the newest version.")
 
             # Download and install
             print(download_message)
             self.set_state('task', download_message,
-                         ['download_version_check',
-                          'set_version',
-                          'download_sig',
-                          'download_tarball',
-                          'verify',
-                          'extract',
-                          'run'])
+                           ['download_version_check',
+                            'set_version',
+                            'download_sig',
+                            'download_tarball',
+                            'verify',
+                            'extract',
+                            'run'])
 
             if self.common.settings['download_over_tor']:
                 print(_('Downloading over Tor'))
@@ -364,7 +360,7 @@ class Launcher(QtWidgets.QMainWindow):
             sigerror = 'SIGNATURE VERIFICATION FAILED!\n\nError Code: {0}\n\nYou might be under attack, there might' \
                        ' be a network\nproblem, or you may be missing a recently added\nTor Browser verification key.' \
                        '\nClick Start to refresh the keyring and try again. If the message persists report the above' \
-                       ' error code here:\nhttps://github.com/micahflee/torbrowser-launcher/issues'.format(sigerror)
+                       ' error code here:\nhttps://github.com/micahflee/torbrowser-launcher/issues'.format(message)
 
             self.set_state('task', sigerror, ['start_over'], False)
             self.update()
@@ -386,7 +382,11 @@ class Launcher(QtWidgets.QMainWindow):
             self.run_task()
 
         def error(message):
-            self.set_state('task', _("Tor Browser Launcher doesn't understand the file format of {0}".format(self.common.paths['tarball_file'])), ['start_over'], False)
+            self.set_state(
+                'task',
+                _("Tor Browser Launcher doesn't understand the file format of {0}".format(self.common.paths['tarball_file'])),
+                ['start_over'], False
+            )
             self.update()
 
         t = ExtractThread(self.common)
@@ -501,13 +501,18 @@ class DownloadThread(QtCore.QThread):
                     if self.common.settings['mirror'] != self.common.default_mirror:
                         message = (_("Download Error:") +
                                    " {0}\n\n" + _("You are currently using a non-default mirror") +
-                                   ":\n{1}\n\n" + _("Would you like to switch back to the default?")).format(r.status_code, self.common.settings['mirror'])
+                                   ":\n{1}\n\n" + _("Would you like to switch back to the default?")).format(
+                                       r.status_code, self.common.settings['mirror']
+                                   )
                         self.download_error.emit('error_try_default_mirror', message)
 
                     # Should we switch to English?
                     elif self.common.language != 'en-US' and not self.common.settings['force_en-US']:
                         message = (_("Download Error:") +
-                                   " {0}\n\n" + _("Would you like to try the English version of Tor Browser instead?")).format(r.status_code)
+                                   " {0}\n\n" +
+                                   _("Would you like to try the English version of Tor Browser instead?")).format(
+                                       r.status_code
+                                   )
                         self.download_error.emit('error_try_forcing_english', message)
 
                     else:
@@ -526,21 +531,24 @@ class DownloadThread(QtCore.QThread):
                     self.progress_update.emit(total_bytes, bytes_so_far)
 
             except requests.exceptions.SSLError:
+                message = _('Invalid SSL certificate for:\n{0}\n\nYou may be under attack.').format(self.url.decode())
                 if not self.common.settings['download_over_tor']:
-                    message = _('Invalid SSL certificate for:\n{0}\n\nYou may be under attack.').format(self.url.decode()) + "\n\n" + _('Try the download again using Tor?')
+                    message += "\n\n" + _('Try the download again using Tor?')
                     self.download_error.emit('error_try_tor', message)
                 else:
-                    message = _('Invalid SSL certificate for:\n{0}\n\nYou may be under attack.'.format(self.url.decode()))
                     self.download_error.emit('error', message)
                 return
 
             except requests.exceptions.ConnectionError:
                 # Connection error
                 if self.common.settings['download_over_tor']:
-                    message = _("Error starting download:\n\n{0}\n\nTrying to download over Tor. Are you sure Tor is configured correctly and running?").format(self.url.decode())
+                    message = _("Error starting download:\n\n{0}\n\nTrying to download over Tor. "
+                                "Are you sure Tor is configured correctly and running?").format(self.url.decode())
                     self.download_error.emit('error', message)
                 else:
-                    message = _("Error starting download:\n\n{0}\n\nAre you connected to the internet?").format(self.url.decode())
+                    message = _("Error starting download:\n\n{0}\n\nAre you connected to the internet?").format(
+                        self.url.decode()
+                    )
                     self.download_error.emit('error', message)
 
                 return
index 5b8ec58401bdc8fa6a612d2b9e1454e3d74b47f1..e344b1113fe88c6b72aa985c73dc9bd1135515ed 100644 (file)
@@ -31,6 +31,7 @@ import shutil
 
 from PyQt5 import QtCore, QtWidgets, QtGui
 
+
 class Settings(QtWidgets.QMainWindow):
     """
     Settings window.