]> git.lizzy.rs Git - torbrowser-launcher.git/commitdiff
still a mess of python, but at least it runs
authorMicah Lee <micahflee@riseup.net>
Fri, 15 Feb 2013 02:26:58 +0000 (18:26 -0800)
committerMicah Lee <micahflee@riseup.net>
Fri, 15 Feb 2013 02:26:58 +0000 (18:26 -0800)
torbrowser-launcher

index 2b6d38c117816765d60300e164f1854ee91e7db8..3c44aad0d3e36d6e5dcff8ae22ee8fac3685e3ad 100755 (executable)
@@ -28,47 +28,58 @@ def download_chunk(base):
 
   return True
 
-class Base:
-  def delete_event(self, widget, event, data=None):
-    return False
-  
-  def destroy(self, widget, data=None):
-    if self.timer:
-      gobject.source_remove(self.timer)
-    self.timer = False
+class TorBrowserLauncher:
+  def __init__(self, current_tbb_version):
+    # figure out the architecture
+    architecture = subprocess.check_output(['arch']).strip('\n')
+
+    # figure out the language
+    available_languages = ['en-US', 'ar', 'de', 'es-ES', 'fa', 'fr', 'it', 'ko', 'nl', 'pl', 'pt-PT', 'ru', 'vi', 'zh-CN']
+    language = locale.getdefaultlocale()[0].replace('_', '-')
+    if language not in available_languages:
+      language = language.split('-')[0]
+      if language not in available_languages:
+        for l in available_languages:
+          if l[0:2] == language:
+            language = l
+    # if language isn't available, default to english
+    if language not in available_languages:
+      language = 'en-US'
+
+    # make sure local directory structure is setup
+    data_dir = os.getenv('HOME')+'/.torbrowser'
+    download_dir = data_dir+'/download'
+    tbb_dir = data_dir+'/tbb/'+architecture+'/'+language
+    if os.path.exists(download_dir) == False:
+      print 'making '+download_dir
+      os.makedirs(download_dir)
+    if os.path.exists(tbb_dir) == False:
+      print 'making '+tbb_dir
+      os.makedirs(tbb_dir)
+
+    # is TBB already installed?
+    tbb_start = tbb_dir+'/start-tor-browser'
+    if os.path.isfile(tbb_start):
+      print 'Launching '+tbb_start
+      subprocess.call([tbb_start])
 
-    gtk.main_quit()
-   
-  def start_download(self, widget, data=None):
-    print 'Starting to download '+self.tarball_url
+    else:
+      tarball_filename = 'tor-browser-gnu-linux-'+architecture+'-'+current_tbb_version+'-dev-'+language+'.tar.gz'
+      tarball_path = download_dir+'/'+tarball_filename
+      if os.path.exists(tarball_path):
+        # already downloaded
+        print 'Already downloaded'
+      else:
+        # launch downloader
+        #tarball_url = 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename
+        tarball_url = 'http://127.0.0.1/'+tarball_filename
 
-    # disable the download button
-    self.download.set_sensitive(False)
 
-    # initialize the progress bar
-    self.progressbar.set_fraction(0) 
-    self.progressbar.set_text('Downloaded 0%')
-    self.progressbar.show()
 
-    # start the download
-    self.dl_response = urllib2.urlopen(self.tarball_url);
-    
-    self.dl_total_size = self.dl_response.info().getheader('Content-Length').strip()
-    self.dl_total_size = int(self.dl_total_size)
-    self.dl_bytes_so_far = 0
 
-    # set a timer to download more chunks
-    self.timer = gobject.timeout_add(1, download_chunk, self)
-
-    # open a file to write to
-    self.tarball_file = open(self.tarball_path, 'w')
-      
-  def __init__(self, tbb_version, tarball_path, tarball_url):
     self.timer = False
 
-    self.tbb_version = tbb_version
-    self.tarball_path = tarball_path
-    self.tarball_url = tarball_url
+    self.current_tbb_version = current_tbb_version
 
     self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
     self.window.set_title("Tor Browser Launcher - First Run")
@@ -80,7 +91,7 @@ class Base:
     self.box = gtk.VBox(False, 20)
     self.window.add(self.box)
 
-    self.label = gtk.Label("The first time you run the Tor Browser Launcher you need to download the Tor Browser Bundle. Would you like to download it from the following URL now?\n\n"+self.tarball_url)
+    self.label = gtk.Label("The first time you run the Tor Browser Launcher you need to download the Tor Browser Bundle. Would you like to download it from the following URL now?")
     self.label.set_line_wrap(True)
     self.box.pack_start(self.label, True, True, 0)
     self.label.show()
@@ -107,56 +118,49 @@ class Base:
     self.box.show()
     self.window.show();
   
+  def delete_event(self, widget, event, data=None):
+    return False
+  
+  def destroy(self, widget, data=None):
+    if self.timer:
+      gobject.source_remove(self.timer)
+    self.timer = False
+
+    gtk.main_quit()
+   
+  def start_download(self, widget, data=None):
+    print 'Starting to download '+self.tarball_url
+
+    # disable the download button
+    self.download.set_sensitive(False)
+
+    # initialize the progress bar
+    self.progressbar.set_fraction(0) 
+    self.progressbar.set_text('Downloaded 0%')
+    self.progressbar.show()
+
+    # start the download
+    self.dl_response = urllib2.urlopen(self.tarball_url);
+    
+    self.dl_total_size = self.dl_response.info().getheader('Content-Length').strip()
+    self.dl_total_size = int(self.dl_total_size)
+    self.dl_bytes_so_far = 0
+
+    # set a timer to download more chunks
+    self.timer = gobject.timeout_add(1, download_chunk, self)
+
+    # open a file to write to
+    self.tarball_file = open(self.tarball_path, 'w')
+      
+
   def main(self):
     gtk.main()
 
 if __name__ == "__main__":
-  # current TBB version
-  tbb_version = '2.3.25-2'
-
-  # figure out the architecture
-  architecture = subprocess.check_output(['arch']).strip('\n')
+  print 'Tor Browser Launcher'
+  print 'https://github.com/micahflee/torbrowser-launcher'
 
-  # figure out the language
-  available_languages = ['en-US', 'ar', 'de', 'es-ES', 'fa', 'fr', 'it', 'ko', 'nl', 'pl', 'pt-PT', 'ru', 'vi', 'zh-CN']
-  language = locale.getdefaultlocale()[0].replace('_', '-')
-  if language not in available_languages:
-    language = language.split('-')[0]
-    if language not in available_languages:
-      for l in available_languages:
-        if l[0:2] == language:
-          language = l
-  # if language isn't available, default to english
-  if language not in available_languages:
-    language = 'en-US'
-
-  # make sure local directory structure is setup
-  data_dir = os.getenv('HOME')+'/.torbrowser'
-  download_dir = data_dir+'/download'
-  tbb_dir = data_dir+'/tbb/'+architecture+'/'+language
-  if os.path.exists(download_dir) == False:
-    print 'making '+download_dir
-    os.makedirs(download_dir)
-  if os.path.exists(tbb_dir) == False:
-    print 'making '+tbb_dir
-    os.makedirs(tbb_dir)
-
-  # is TBB already installed?
-  tbb_start = tbb_dir+'/start-tor-browser'
-  if os.path.isfile(tbb_start):
-    print 'Launching '+tbb_start
-    subprocess.call([tbb_start])
-
-  else:
-    tarball_filename = 'tor-browser-gnu-linux-'+architecture+'-'+tbb_version+'-dev-'+language+'.tar.gz'
-    tarball_path = download_dir+'/'+tarball_filename
-    if os.path.exists(tarball_path):
-      # already downloaded
-      print 'Already downloaded'
-    else:
-      # launch downloader
-      #tarball_url = 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename
-      tarball_url = 'http://127.0.0.1/'+tarball_filename
-      base = Base(tbb_version, tarball_path, tarball_url)
-      base.main()
+  current_tbb_version = '2.3.25-2'
+  app = TorBrowserLauncher(current_tbb_version)
+  app.main()