[Pkg-privacy-commits] [torbrowser-launcher] 28/476: back to python

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:21:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository torbrowser-launcher.

commit 022416d2cc446bcba50aa3b99b9bb6f301a3bb93
Author: Micah Lee <micahflee at riseup.net>
Date:   Thu Feb 14 18:18:17 2013 -0800

    back to python
---
 .gitignore                       |  51 +++-
 MANIFEST.in                      |   1 +
 Makefile.am                      |  17 --
 README                           |  31 ++-
 autogen.sh                       |  18 --
 build_and_install.sh             |  21 ++
 configure.ac                     |   5 -
 misc/torbrowser.desktop          |   9 +
 {icons => misc}/torbrowser32.xpm |   0
 {icons => misc}/torbrowser80.xpm |   0
 README => setup.py               |  36 ++-
 src/torbrowser-launcher          | 492 ---------------------------------------
 torbrowser-launcher              | 162 +++++++++++++
 torbrowser-launcher.desktop.in   |  12 -
 14 files changed, 271 insertions(+), 584 deletions(-)

diff --git a/.gitignore b/.gitignore
index 49df6ed..d9a800f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,13 +1,40 @@
-aclocal.m4
-autom4te.cache
-config.log
-config.status
-configure
-hello.desktop
-install-sh
-missing
-Makefile.in
-Makefile
-torbrowser-launcher.desktop
-*.tar.xz
+*.py[cod]
+
+# C extensions
+*.so
+
+# Packages
+*.egg
+*.egg-info
+dist
+deb_dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+lib
+lib64
+MANIFEST
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+nosetests.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+
+# vim
 *.swp
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..bfef1b4
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+include misc/*
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index decbcad..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-# The actual runnable program is set to the SCRIPTS primitive.
-# Prefix bin_ tells where to copy this
-bin_SCRIPTS = src/torbrowser-launcher
-
-# List of files to be distributed
-EXTRA_DIST=  \
-	$(bin_SCRIPTS)
-
-# The desktop files
-desktopdir = $(datadir)/applications
-desktop_DATA = \
-	torbrowser-launcher.desktop
-
-# The icons
-iconsdir = $(datadir)/icons
-icons_DATA = icons/torbrowser32.xpm icons/torbrowser80.xpm
-
diff --git a/README b/README
index 8541696..eb89f6e 100644
--- a/README
+++ b/README
@@ -7,19 +7,32 @@ When you first launch Tor Browser Launcher, it will download TBB from https://ww
 
 Tor Browser Launcher will get updated each time a new version of TBB is released. When you open Tor Browser after an update, it will download the newer version of TBB for you and extract it over your old TBB directory in ~/.torproject, so you will maintain your TBB bookmarks. 
 
-Build Instructions
-==================
+Building a Debian package
+=========================
 
-To build and install this program:
+You need to have stdeb installed. If you're using Debian or Ubuntu you can install it like this:
 
-./autogen.sh --prefix=$HOME/.local
-make install
+  sudo apt-get install python-stdeb
 
-To uninstall, type:
+Here are other things you might need:
 
-make uninstall
+  sudo apt-get install build-essential dpkg-dev debhelper devscripts fakeroot cdbs
 
-To create a tarball:
+First build a source distribution:
 
-make distcheck
+  python setup.py sdist
+
+Turn it into a Debian source package:
+
+  cd dist
+  py2dsc torbrowser-launcher-2.3.25-2-1.tar.gz
+
+Turn it into a Debian binary package:
+
+  cd deb_dist/torbrowser-launcher-2.3.25-2-1
+  dpkg-buildpackage -rfakeroot -uc -us
+
+Once you've made a .deb, you can install it like this:
+
+  sudo dpkg -i python-torbrowser-launcher_0.1_all.deb
 
diff --git a/autogen.sh b/autogen.sh
deleted file mode 100755
index cb2570e..0000000
--- a/autogen.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-
-set -e
-
-test -n "$srcdir" || srcdir=`dirname "$0"`
-test -n "$srcdir" || srcdir=.
-
-olddir=`pwd`
-cd "$srcdir"
-
-# This will run autoconf, automake, etc. for us
-autoreconf --force --install
-
-cd "$olddir"
-
-if test -z "$NOCONFIGURE"; then
-  "$srcdir"/configure "$@"
-fi
diff --git a/build_and_install.sh b/build_and_install.sh
new file mode 100755
index 0000000..c400dc0
--- /dev/null
+++ b/build_and_install.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# clean up from last time
+rm -rf ~/.torbrowser
+
+# build source dist
+python setup.py sdist
+
+# turn it into a debian source package
+cd dist
+py2dsc torbrowser-launcher-2.3.25-2-1.tar.gz
+
+# turn it into a debian binary package
+cd deb_dist/torbrowser-launcher-2.3.25-2-1
+dpkg-buildpackage -rfakeroot -uc -us
+
+# install it
+cd ..
+sudo dpkg -i python-torbrowser-launcher_2.3.25-2-1-1_all.deb
+cd ../..
+
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index 83b2da2..0000000
--- a/configure.ac
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file is processed by autoconf to create a configure script
-AC_INIT([Tor Browser Launcher], 1.0)
-AM_INIT_AUTOMAKE([1.10 no-define foreign dist-xz no-dist-gzip])
-AC_CONFIG_FILES([Makefile torbrowser-launcher.desktop])
-AC_OUTPUT
diff --git a/misc/torbrowser.desktop b/misc/torbrowser.desktop
new file mode 100644
index 0000000..ed40f2b
--- /dev/null
+++ b/misc/torbrowser.desktop
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Tor Browser
+Comment=Launch the Tor Browser Bundle
+Exec=/usr/bin/torbrowser-launcher
+Terminal=false
+Type=Application
+Icon=/usr/share/pixmaps/torbrowser80.xpm
+Categories=Internet;
diff --git a/icons/torbrowser32.xpm b/misc/torbrowser32.xpm
similarity index 100%
rename from icons/torbrowser32.xpm
rename to misc/torbrowser32.xpm
diff --git a/icons/torbrowser80.xpm b/misc/torbrowser80.xpm
similarity index 100%
rename from icons/torbrowser80.xpm
rename to misc/torbrowser80.xpm
diff --git a/README b/setup.py
similarity index 58%
copy from README
copy to setup.py
index 8541696..0f03c7c 100644
--- a/README
+++ b/setup.py
@@ -1,25 +1,23 @@
-Tor Browser Launcher
-====================
-
+from distutils.core import setup
+
+setup(name='torbrowser-launcher',
+      version='0.1',
+      author='Micah Lee',
+      author_email='micahflee at riseup.net',
+      url='https://www.github.com/micahflee/torbrowser-launcher',
+      platforms=['GNU/Linux'],
+      license='GPLv3',
+
+      description='A program to help you download, keep updated, and run the Tor Browser Bundle',
+      long_description="""
 Tor Browser Launcher is intended to make the Tor Browser Bundle (TBB) easier to maintain and use for GNU/Linux users. You install torbrowser-launcher from your distribution's package manager and it handles downloading the most recent version of TBB for you, in your language and for your architecture. It also adds a "Tor Browser" application launcher to your operating system's menu.
 
 When you first launch Tor Browser Launcher, it will download TBB from https://www.torproject.org/ and extract it in ~/.torproject, and then execute it. When you run it after that it will just execute TBB.
 
 Tor Browser Launcher will get updated each time a new version of TBB is released. When you open Tor Browser after an update, it will download the newer version of TBB for you and extract it over your old TBB directory in ~/.torproject, so you will maintain your TBB bookmarks. 
+""",
 
-Build Instructions
-==================
-
-To build and install this program:
-
-./autogen.sh --prefix=$HOME/.local
-make install
-
-To uninstall, type:
-
-make uninstall
-
-To create a tarball:
-
-make distcheck
-
+      scripts=['torbrowser-launcher'],
+      data_files=[('/usr/share/applications', ['misc/torbrowser.desktop']),
+                  ('/usr/share/pixmaps', ['misc/torbrowser32.xpm', 'misc/torbrowser80.xpm'])]
+      )
diff --git a/src/torbrowser-launcher b/src/torbrowser-launcher
deleted file mode 100755
index 8c127e3..0000000
--- a/src/torbrowser-launcher
+++ /dev/null
@@ -1,492 +0,0 @@
-#!/usr/bin/gjs
-
-const Gtk = imports.gi.Gtk;
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Soup = imports.gi.Soup;
-const Lang = imports.lang;
-
-const TorBrowserLauncher = new Lang.Class({
-  Name: 'Tor Borwser Launcher',
-
-  // create the application
-  _init: function(current_tbb_version) {
-    let that = this;
-
-    // initialize the app
-    this._current_tbb_version = current_tbb_version;
-    this._discover_arch_lang();
-    this._build_paths();
-    this._mkdirs();
-    
-    let launch_gui = true;
-
-    // is TBB already installed?
-    if(this._file_executable(this._paths.file.start)) {
-
-      // does the version file exist?
-      if(this._file_exists(this._paths.file.version)) {
-
-        let installed_tbb_version = this._read_version_file();
-        if(installed_tbb_version) {
-          if(installed_tbb_version == this._current_tbb_version) {
-            // current version is tbb is installed, launch it
-            that._exec([that._paths.file.start]);
-            launch_gui = false;
-          } else if(installed_tbb_version < that._current_tbb_version) {
-            // there is a tbb upgrade available
-            that._set_gui('task',
-              "Your Tor Browser Launcher is out of date. Click Start to download the\n"+
-              "following files from https://www.torproject.org:\n\n"+
-              that._paths.filename.tarball+"\n"+
-              that._paths.filename.tarball_sig+"\n",
-              ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run']);
-          } else {
-            // for some reason the installed tbb is newer than the current version?
-            that._set_gui('error', 
-              "Something is wrong. The version of Tor Browser Bundle\n"+
-              "you have installed is newer than the current version?");
-          }
-        } else {
-          // error reading version from file
-          that._set_gui('error', 
-            "Tor Browser Launcher couldn't read this file:\n\n"+this._paths.dir.version);
-        };
-      
-      } else {
-        // if tbb is installed but the version file doesn't exist, something is wrong
-        this._set_gui('error', 
-          "Something is wrong. You have the Tor Browser Bundle\n"+
-          "installed, but the version file is missing.");
-      }
-    } else {
-
-      // save the current version to the file
-      this._write_version_file(this._current_tbb_version);
-
-      // is the tarball and sig already downloaded?
-      if(this._file_exists(this._paths.file.tarball) &&
-        this._file_exists(this._paths.file.tarball_sig)) {
-
-        // verify it's signature
-        this._verify(function(err){
-          if(err) {
-            // signature verification failed
-            this._set_gui('error', 
-              "Something is wrong. The Tor Browser Bundle that you\n"+
-              "were about to install does not have a valid signature.\n"+
-              "Deleting this directory and try again:\n\n"+
-              this._paths.dir.download);
-
-          } else {
-            
-            // start the gui with extract
-            this._set_gui('task', 
-              "You already have Tor Browser Bundle downloaded, but\n"+
-              "it isn't installed yet.", 
-              ['extract', 'run']);
-
-          }
-        });
-
-      } else {
-
-        // first run
-        this._set_gui('task',
-          "The first time you run the Tor Browser Launcher you need to download\n"+
-          "the Tor Browser Bundle. Click start to download it now from the\n"+
-          "following files from https://www.torproject.org/:\n\n"+
-          this._paths.filename.tarball+"\n"+
-          this._paths.filename.tarball_sig+"\n",
-          ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run']);
-      }
-    }
-
-    if(launch_gui) {
-      // start an http session to make http requests
-      this._httpSession = new Soup.SessionAsync();
-      Soup.Session.prototype.add_feature.call(this._httpSession, new Soup.ProxyResolverDefault());
-
-      // create the application
-      this.application = new Gtk.Application();
-
-      // connect 'activate' and 'startup' signals to the callback functions
-      this.application.connect('activate', Lang.bind(this, function(){
-        this._window.present();
-      }));
-      this.application.connect('startup', Lang.bind(this, function(){
-        this._build_ui();
-      }));
-
-      // run the application
-      this.application.run(ARGV);
-    }
-  },
-
-  // discover the architecture and language
-  _discover_arch_lang: function(){
-    // get the architecture
-    let [res, out] = this._exec(['arch']);
-    this._architecture = (''+out).replace(/\s+/g, '');
-
-    // figure out the language
-    let available_languages = { 'en-US': true, 'ar': true, 'de': true, 'es-ES': true, 'fa': true, 'fr': true, 'it': true, 'ko': true, 'nl': true, 'pl': true, 'pt-PT': true, 'ru': true, 'vi': true, 'zh-CN': true};
-    this._language = GLib.getenv('LANG').split('.')[0].replace('_', '-');
-    if(!available_languages[this._language]) {
-      this._language = this._language.split('-')[0];
-      if(!available_languages[this._language]) {
-        for(let i in available_languages) {
-          if(this._language.substring(0, 2) == available_languages[i]) {
-            this._language = available_languages[i];
-          }
-        }
-      }
-    }
-    // if language isn't available, default to english
-    if(!available_languages[this._language]) {
-      this._language = 'en-US';
-    }
-  },
-
-  // build all relevant paths
-  _build_paths: function(){
-    let tbb_data = GLib.getenv('HOME')+'/.torbrowser';
-    let tarball_filename = 'tor-browser-gnu-linux-'+this._architecture+'-'+this._current_tbb_version+'-dev-'+this._language+'.tar.gz';
-    this._paths = {
-      dir: {
-        data: tbb_data,
-        download: tbb_data+'/download',
-        tbb: tbb_data+'/tbb/'+this._architecture
-      },
-      file: {
-        version: tbb_data+'/version',
-        start: tbb_data+'/tbb/'+this._architecture+'/tor-browser_'+this._language+'/start-tor-browser',
-        tarball: tbb_data+'/download/'+tarball_filename,
-        tarball_sig: tbb_data+'/download/'+tarball_filename+'.asc'
-      },
-      url: {
-        tarball: 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename,
-        tarball_sig: 'https://www.torproject.org/dist/torbrowser/linux/'+tarball_filename+'.asc'
-        //tarball: 'http://localhost/'+tarball_filename,
-        //tarball_sig: 'http://localhost/'+tarball_filename+'.asc'
-      },
-      filename: {
-        tarball: tarball_filename,
-        tarball_sig: tarball_filename+'.asc'
-      }
-    };
-  },
-
-  // create directories that don't exist
-  _mkdirs: function(){
-    if(!this._file_exists(this._paths.dir.download)) {
-      GLib.mkdir_with_parents(this._paths.dir.download, 0x1c0); // 0x1c0 is 0700
-    }
-    if(!this._file_exists(this._paths.dir.tbb)) {
-      GLib.mkdir_with_parents(this._paths.dir.tbb, 0x1c0);
-    }
-  },
-
-  // build the application's UI
-  _build_ui: function() {
-    let that = this;
-
-    // create the application window
-    this._window = new Gtk.ApplicationWindow({
-      application: this.application,
-      window_position: Gtk.WindowPosition.CENTER,
-      border_width: 10,
-      title: "Tor Browser Launcher"
-    });
-
-    // create the Grid
-    this._grid = new Gtk.Grid ({
-      row_spacing: 10,
-      column_spacing: 20
-    });
-
-    switch(this._gui) {
-      case 'error':
-        // labels
-        this._label1 = new Gtk.Label({ label: this._gui_message });
-        this._label2 = new Gtk.Label({ 
-          label: 
-            "You can fix the problem by deleting:\n"+
-            this._paths.dir.data+"\n\n"+
-            "However, you will lose all your bookmarks and other\n"+
-            "Tor Browser preferences."
-        });
-
-        // exit button
-        this._button_exit = new Gtk.Button({ label: "Exit" });
-        this._button_exit.connect('clicked', Lang.bind(this, function(){
-          this._window.destroy();
-        }));
-
-        // attach everything to the grid
-        this._grid.attach(this._label1, 0, 0, 1, 1);
-        this._grid.attach(this._label2, 0, 1, 1, 1);
-        this._grid.attach(this._button_exit, 0, 2, 1, 1);
-        break;
-
-      case 'task':
-        // the label
-        this._label = new Gtk.Label({ label: this._gui_message });
-
-        // progress bar
-        this._progress_bar = new Gtk.ProgressBar({
-          orientation: Gtk.Orientation.HORIZONTAL
-        });
-
-        // download buttons
-        this._button_start = new Gtk.Button({ label: "Start" });
-        this._button_start.connect('clicked', Lang.bind(this, function(){
-          // disable the start button
-          this._button_start.set_sensitive(false);
-
-          // make an array of functions to call in order
-          let task_functions = [];
-          for(let i = 0; i < this._gui_tasks.length; i++) {
-            
-            switch(this._gui_tasks[i]){
-              case 'download_tarball':
-                task_functions.push(function(done){
-                  print('Downloading '+that._paths.filename.tarball);
-                  that._download_file(that._paths.filename.tarball, that._paths.url.tarball, that._paths.file.tarball, function(err){
-                    if(err) {
-                      done(err);
-                      return;
-                    }
-                    done();
-                  });
-                });
-                break;
-              case 'download_tarball_sig':
-                task_functions.push(function(done){
-                  print('Downloading '+that._paths.filename.tarball_sig);
-                  that._download_file(that._paths.filename.tarball_sig, that._paths.url.tarball_sig, that._paths.file.tarball_sig, function(err){
-                    if(err) {
-                      done(err);
-                      return;
-                    }
-                    done();
-                  });
-                });
-                break;
-              case 'verify':
-                task_functions.push(function(done){
-                  print('Verifying signature');
-                  that._verify(function(){
-                    done();
-                  });
-                });
-                break;
-
-              case 'extract':
-                task_functions.push(function(done){
-                  print('Extracting tarball');
-                  that._extract(function(){
-                    done();
-                  });
-                });
-                break;
-              case 'run':
-                task_functions.push(function(done){
-                  print('Executing');
-                  if(!that._exec([that._paths.file.start])) {
-                    print('Failed to execute '+that._paths.file.start);
-                    that._statusbar.label = 'Failed to execute '+that._paths.file.start;
-                    that._button_start.set_sensitive(true);
-                  };
-                  done();
-                });
-                break;
-            }
-            
-          }
-
-          // call them in order
-          let i = 0;
-          function series(done){
-            if(i == task_functions.length) {
-              done();
-              return;
-            }
-
-            task_functions[i](function(err){
-              if(err) {
-                // there was an error in the series
-                // handle it by making the start button clickable again
-                that._button_start.set_sensitive(true);
-              } else {
-                i++;
-                series(done);
-              }
-            });
-          };
-          series(function(){
-            // all tasks have been executed, so exit
-            that._window.destroy();
-          });
-
-        }));
-
-        // exit button
-        this._button_exit = new Gtk.Button({ label: "Exit" });
-        this._button_exit.connect('clicked', Lang.bind(this, function(){
-          this._window.destroy();
-        }));
-
-        // status bar
-        this._statusbar = new Gtk.Label({ });
-
-        // attach everything to the grid
-        this._grid.attach(this._label, 0, 0, 2, 1);
-        this._grid.attach(this._progress_bar, 0, 1, 2, 1);
-        this._grid.attach(this._button_start,  0, 2, 1, 1);
-        this._grid.attach(this._button_exit, 1, 2, 1, 1);
-        this._grid.attach(this._statusbar, 0, 3, 2, 1);
-        break;
-    }
-
-    // add the grid to the window
-    this._window.add(this._grid);
-    this._window.show_all();
-  },
-
-  // there are different GUIs that might appear, this sets which one we want
-  _set_gui: function(gui, message, tasks){
-    this._gui = gui;
-    this._gui_message = message;
-    this._gui_tasks = tasks ? tasks : [];
-  },
-
-  // download a file, while updating the progress bar
-  // callback is function(err)
-  _download_file: function(name, url, path, callback){
-    let that = this;
-    this._statusbar.set_label('Downloading '+name);
-
-    function file_size(bytes) {
-      if(bytes < 1024) {
-        return ''+bytes+' bytes';
-      }
-      let kb = bytes / 1024;
-      kb = Math.floor(kb);
-      if(kb < 1024) {
-        return ''+kb+'kb';
-      }
-      let mb = kb / 1024;
-      mb = Math.floor(mb * 100) / 100;
-      return ''+mb+'mb';
-    }
-
-    let total_size;
-    let bytes_so_far = 0;
-
-    // open the file
-    var f = Gio.file_new_for_path(String(path));
-    var data_out = new Gio.DataOutputStream({base_stream:f.replace(null, false, Gio.FileCreateFlags.NONE, null)});
-
-    // create an http message
-    let request = Soup.Message.new('GET', url);
-
-    // grab the content-length from the headers
-    request.connect('got_headers', Lang.bind(this, function(message){
-      total_size = message.response_headers.get_content_length()
-    }));
-    
-    // update progress bar with each chunk
-    request.connect('got_chunk', Lang.bind(this, function(message, chunk){
-      // write chunk to file
-      let data = chunk.get_data();
-      for(let i=0; i<chunk.length; i++) {
-        data_out.put_byte(data[i], null);
-      }
-
-      bytes_so_far += chunk.length;
-
-      if(total_size) {
-        let fraction = bytes_so_far / total_size;
-        let percent = Math.floor(fraction * 100);
-        this._progress_bar.set_fraction(fraction);
-        this._statusbar.set_label("Downloading "+name+": "+percent+"% ("+file_size(bytes_so_far)+" / "+file_size(total_size)+")");
-      }
-    }));
-
-    this._httpSession.queue_message(request, function(_httpSession, message) {
-      // close the file
-      data_out.close(null);
-
-      if(message.status_code !== 200) {
-        that._statusbar.set_label('Downloading '+name+' failed: '+message.status_code);
-        callback(true);
-        return;
-      }
-      that._progress_bar.set_fraction(1);
-      that._statusbar.set_label('Downloading '+name+' finished');
-      callback();
-    });
-  },
-  
-  // verify the signature on the tarball
-  // callback is function(err)
-  _verify: function(callback){
-    // todo: verify signature
-    callback();
-  },
-
-  // extract tbb over the old version, while updating the progress bar
-  // callback is function(err)
-  _extract: function(callback){
-    let [res, out] = this._exec(['tar', '-xf', this._paths.file.tarball, '-C', this._paths.dir.tbb]);
-    callback();
-  },
-
-  // read the version file
-  // callback is function(err, version)
-  _read_version_file: function(){
-    let f = GLib.file_get_contents(this._paths.file.version);
-    if(f && f[1]) {
-      let version = f[1].replace(/\s+/g, ' ');
-      return version;
-    } else {
-      return false;
-    }
-  },
-
-  // write the version to the version file
-  _write_version_file: function(version){
-    // make sure version is a string
-    version = ''+version;
-    try {
-      GLib.file_set_contents(this._paths.file.version, version, version.length);
-      return true;
-    } catch(err) {
-      return err;
-    }
-  },
-
-  // some wrapper functions, to make things less verbose
-  _file_exists: function(filename){
-    return GLib.file_test(filename, GLib.FileTest.EXISTS);
-  },
-  _file_executable: function(filename){
-    return GLib.file_test(filename, GLib.FileTest.IS_EXECUTABLE);
-  },
-  _exec: function(args){
-    try {
-      return GLib.spawn_sync(null, args, null, GLib.SpawnFlags.SEARCH_PATH, null);
-    } catch(err) {
-      return false;
-    }
-  }
-});
-
-print('Tor Browser Launcher');
-print('https://github.com/micahflee/torbrowser-launcher');
-
-// run the application
-let current_tbb_version = '2.3.25-2';
-let app = new TorBrowserLauncher(current_tbb_version);
-
diff --git a/torbrowser-launcher b/torbrowser-launcher
new file mode 100755
index 0000000..2b6d38c
--- /dev/null
+++ b/torbrowser-launcher
@@ -0,0 +1,162 @@
+#!/usr/bin/env python
+
+import os, sys, subprocess, locale, urllib2, gobject
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+def download_chunk(base):
+  # download 10kb a time
+  chunk = base.dl_response.read(10240)
+  base.dl_bytes_so_far += len(chunk)
+  base.tarball_file.write(chunk)
+
+  if not chunk:
+    base.tarball_file.close()
+    return False
+
+  percent = float(base.dl_bytes_so_far) / base.dl_total_size
+  base.progressbar.set_fraction(percent)
+  percent = round(percent*100, 2)
+  base.progressbar.set_text("Downloaded %d" % (percent) + '%')
+  
+  sys.stdout.write("Downloaded %d of %d bytes (%0.2f%%)\r" % (base.dl_bytes_so_far, base.dl_total_size, percent))
+
+  if base.dl_bytes_so_far >= base.dl_total_size:
+    sys.stdout.write('\n')
+
+  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
+
+    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 __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.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+    self.window.set_title("Tor Browser Launcher - First Run")
+    self.window.set_border_width(10)
+    
+    self.window.connect("delete_event", self.delete_event)
+    self.window.connect("destroy", self.destroy)
+
+    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.set_line_wrap(True)
+    self.box.pack_start(self.label, True, True, 0)
+    self.label.show()
+
+    self.progressbar = gtk.ProgressBar(adjustment=None)
+    self.progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
+    self.box.pack_start(self.progressbar, True, True, 0)
+
+    self.button_box = gtk.HButtonBox()
+    self.button_box.set_layout(gtk.BUTTONBOX_SPREAD)
+    self.box.pack_start(self.button_box, True, True, 0)
+    self.button_box.show()
+
+    self.download = gtk.Button("Download")
+    self.download.connect("clicked", self.start_download, None)
+    self.button_box.add(self.download)
+    self.download.show()
+
+    self.exit = gtk.Button("Exit")
+    self.exit.connect("clicked", self.destroy, None)
+    self.button_box.add(self.exit)
+    self.exit.show()
+
+    self.box.show()
+    self.window.show();
+  
+  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')
+
+  # 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()
+
diff --git a/torbrowser-launcher.desktop.in b/torbrowser-launcher.desktop.in
deleted file mode 100644
index 177e7ca..0000000
--- a/torbrowser-launcher.desktop.in
+++ /dev/null
@@ -1,12 +0,0 @@
-[Desktop Entry]
-Version=1.0
-Encoding=UTF-8
-Name=Tor Browser
-Comment=Launch the Tor Browser Bundle
-Exec=@prefix@/bin/torbrowser-launcher
-Icon=application-default-icon
-Icon=@prefix@/share/icons/torbrowser80.xpm
-Terminal=false
-Type=Application
-StartupNotify=true
-Categories=Internet;

-- 
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