Package: nautilus-dropbox
Version: 1.4.0-3
Severity: wishlist

Dear Maintainer,

Regardless of what version of the Dropbox daemon you already have
installed, re-installation of this package or running "dropbox update"
will result in the binaries being downloaded from the server
unnecessarily.  The pain this causes becomes even more insufferable when
the update script fails to work with your proxy settings.  See #696122.

The installed and available versions should be checked first, before any
downloading, to avoid wasting bandwidth.

I have attached my patch to fix this.

Carlos

-- System Information:
Debian Release: 7.0
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.2.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages nautilus-dropbox depends on:
ii  libatk1.0-0              2.4.0-2
ii  libc6                    2.13-37
ii  libcairo-gobject2        1.12.2-2
ii  libcairo2                1.12.2-2
ii  libgdk-pixbuf2.0-0       2.26.1-1
ii  libglib2.0-0             2.33.12+really2.32.4-3
ii  libgtk-3-0               3.4.2-4
ii  libnautilus-extension1a  3.4.2-1+build1
ii  libpango1.0-0            1.30.0-1
ii  policykit-1              0.105-1
ii  procps                   1:3.3.4-2
ii  python                   2.7.3-3
ii  python-gpgme             0.2-2
ii  python-gtk2              2.24.0-3

nautilus-dropbox recommends no packages.

Versions of packages nautilus-dropbox suggests:
ii  nautilus  3.4.2-1+build1

-- no debconf information
>From 5beef72fb20474f428b43e5dcd58c6a2817d7998 Mon Sep 17 00:00:00 2001
From: Carlos Maddela <madd...@labyrinth.net.au>
Date: Sun, 16 Dec 2012 01:06:27 +1100
Subject: prevent unnecessary download

Description: Prevent the unnecessary re-downloading of the dropbox
daemon, if the currently installed version is up-to-date.  A new
command, checkver, is now available as a consequence of this.
---
 dropbox.in |  146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 142 insertions(+), 4 deletions(-)

diff --git a/dropbox.in b/dropbox.in
index 32049cd..dc66850 100755
--- a/dropbox.in
+++ b/dropbox.in
@@ -45,6 +45,7 @@ except ImportError:
 
 from contextlib import closing, contextmanager
 from posixpath import curdir, sep, pardir, join, abspath, commonprefix
+from distutils.version import LooseVersion
 
 INFO = u"Dropbox is the easiest way to share and store your files online. Want to learn more? Head to"
 LINK = u"http://www.dropbox.com/";
@@ -258,9 +259,11 @@ def reset_url_opener():
 
 reset_url_opener()
 
+DOWNLOAD_URL = "http://www.dropbox.com/download?plat=%s"; % plat()
+
 class DownloadState(object):
     def __init__(self):
-        url = "http://www.dropbox.com/download?plat=%s"; % plat()
+        url = DOWNLOAD_URL
         try:
             self.socket = urllib2.urlopen(url)
             self.size = int(self.socket.info()['content-length'])
@@ -281,7 +284,7 @@ Could not determine the size of the file to download.\n""")
 
     def unpack(self):
         # download signature
-        signature = download_uri_to_buffer("http://www.dropbox.com/download?plat=%s&signature=1"; % plat())
+        signature = download_uri_to_buffer(DOWNLOAD_URL + "&signature=1")
 
         self.local_file.seek(0)
         if gpgme:
@@ -820,11 +823,146 @@ def columnize(list, display_list=None, display_width=None):
 @command
 def update(args):
     u"""download latest version of dropbox
-dropbox update
+dropbox update [-f]
 
 Downloads the latest version of dropbox.
+
+options:
+  -f --force    force download even if the latest version is already installed.
 """
-    download()
+    oparser = optparse.OptionParser()
+    oparser.add_option("-f", "--force", action="store_true", dest="forced")
+    (options, args) = oparser.parse_args(args)
+
+    dropbox_ver = DropboxVersion()
+    if options.forced or not dropbox_ver.is_current():
+        download()
+
+class HeadRequest(urllib2.Request):
+    def get_method(self):
+        return "HEAD"
+
+def get_redirected_url(url):
+    try:
+        request = HeadRequest(url)
+        response = urllib2.urlopen(request)
+        if response.getcode() != 200:
+            return None
+        return response.geturl()
+    except:
+        return None
+
+class DropboxVersion(object):
+    def __init__(self):
+        self.__installed_checked = False
+        self.__latest_checked = False
+        self.__latest_url_checked = False
+
+    def installed(self):
+        if not self.__installed_checked:
+            self.__check_installed()
+            self.__installed_checked = True
+        return self.__installed
+
+    def latest(self):
+        if not self.__latest_checked:
+            self.__check_latest()
+            self.__latest_checked = True
+        return self.__latest
+
+    def latest_url(self):
+        if not self.__latest_url_checked:
+            self.__check_latest_url()
+            self.__latest_url_checked = True
+        return self.__latest_url
+
+    def is_current(self):
+        pass
+        installed_ver = self.installed()
+        latest_ver = self.latest()
+        if installed_ver is None:
+            return False
+        elif latest_ver is None:
+            return True
+        else:
+            return (installed_ver == latest_ver)
+
+    def __check_installed(self):
+        try:
+            ver_filename = os.path.join(PARENT_DIR, ".dropbox-dist/VERSION")
+            with open(ver_filename, "r") as f:
+                self.__installed = LooseVersion(f.read())
+        except:
+            self.__installed = None
+
+    def __check_latest(self):
+        try:
+            url = self.latest_url()
+            self.__latest = LooseVersion(url.split("-")[-1].split(".tar")[0])
+        except:
+            self.__latest = None
+
+    def __check_latest_url(self):
+        self.__latest_url = get_redirected_url(DOWNLOAD_URL)
+
+@command
+def checkver(args):
+    u"""checks version details of dropbox
+dropbox checkver [-l] [-u]
+
+Checks version details of dropbox.
+Without any options, the currently installed version is printed.
+
+options:
+  -l --latest       prints out the latest available version.
+  -u --up-to-date   checks if the currently installed version is the latest.
+"""
+    oparser = optparse.OptionParser()
+    oparser.add_option("-l", "--latest", action="store_true", dest="latest")
+    oparser.add_option("-u", "--up-to-date", action="store_true",
+                       dest="uptodate_check")
+    (options, args) = oparser.parse_args(args)
+
+    dropbox_ver = DropboxVersion()
+    if options.uptodate_check:
+        if dropbox_ver.is_current():
+            ver = dropbox_ver.latest()
+            if ver is None:
+                console_print(u"""
+Cannot determine if currently installed version (%s) of the Dropbox
+syncing daemon is current.  Failed to retrieve the latest version.
+""" % str(dropbox_ver.installed()))
+            else:
+                console_print(u"""
+Currently installed version (%s) of the Dropbox syncing daemon
+is the latest and greatest!\n""" % str(ver))
+        else:
+            latest_ver = dropbox_ver.latest()
+            console_print(u"""
+An update of the Dropbox syncing daemon is available:
+
+Currently installed version: %s
+             Latest version: %s
+""" % (str(dropbox_ver.installed()),
+       latest_ver is None and "Unknown" or str(latest_ver)))
+    elif options.latest:
+        ver = dropbox_ver.latest()
+        if ver is None:
+            console_print(u"""
+Failed to get the version of the latest Dropbox syncing daemon.\n""")
+        else:
+            console_print(u"""
+The latest version of the Dropbox syncing daemon is %s.\n""" % (str(ver)))
+    else:
+        ver = dropbox_ver.installed()
+        if ver is None:
+            console_print(u"""
+No version of the Dropbox syncing daemon is currently installed.\n""")
+        else:
+            console_print(u"""
+Version %s of the Dropbox syncing daemon is currently installed.
+""" % (str(ver)))
+
 
 @command
 @requires_dropbox_running

Reply via email to