Skip to content
Permalink
Browse files

Update dropbox.py with shmodel, proxy, and throttle features.

  • Loading branch information...
lachesis authored and raveit65 committed Mar 13, 2015
1 parent a2ccaaf commit d3261c14f40745ce39772e58009a6e0988f53911
Showing with 149 additions and 2 deletions.
  1. +149 −2 caja-dropbox.in
@@ -995,10 +995,10 @@ This is an alias for filestatus -l
@command
@requires_dropbox_running
def puburl(args):
u"""get public url of a file in your dropbox
u"""get public url of a file in your dropbox's public folder
dropbox puburl FILE
Prints out a public url for FILE.
Prints out a public url for FILE (which must be in your public folder).
"""
if len(args) != 1:
console_print(puburl.__doc__,linebreak=False)
@@ -1017,6 +1017,153 @@ Prints out a public url for FILE.
except DropboxCommand.CouldntConnectError, e:
console_print(u"Dropbox isn't running!")

@command
@requires_dropbox_running
def sharelink(args):
u"""get a shared link for a file in your dropbox
dropbox sharelink FILE
Prints out a shared link for FILE.
"""
if len(args) != 1:
console_print(sharelink.__doc__, linebreak=False)
return

try:
with closing(DropboxCommand()) as dc:
try:
path = unicode_abspath(args[0].decode(sys.getfilesystemencoding()))
link = dc.get_shared_link(path=path).get('link', [u'No link'])[0]
console_print(link)
except DropboxCommand.CommandError, e:
console_print(u"Couldn't get shared link: " + str(e))
except DropboxCommand.BadConnectionError, e:
console_print(u"Dropbox isn't responding!")
except DropboxCommand.EOFError:
console_print(u"Dropbox daemon stopped.")
except DropboxCommand.CouldntConnectError, e:
console_print(u"Dropbox isn't running!")

@command
@requires_dropbox_running
def proxy(args):
u"""set proxy settings for Dropbox
dropbox proxy MODE [TYPE] [HOST] [PORT] [USERNAME] [PASSWORD]
Set proxy settings for Dropbox.
MODE - one of "none", "auto", "manual"
TYPE - one of "http", "socks4", "socks5" (only valid with "manual" mode)
HOST - proxy hostname (only valid with "manual" mode)
PORT - proxy port (only valid with "manual" mode)
USERNAME - (optional) proxy username (only valid with "manual" mode)
PASSWORD - (optional) proxy password (only valid with "manual" mode)
"""
mode = None
type_ = None
if len(args) >= 1:
mode = args[0].decode(sys.getfilesystemencoding()).lower()
if len(args) >= 2:
type_ = args[1].decode(sys.getfilesystemencoding()).lower()

if (len(args) == 0 or
mode not in [u'none', u'auto', u'manual'] or
(mode == 'manual' and len(args) not in (4, 6)) or
(mode != 'manual' and len(args) != 1) or
(mode == 'manual' and type_ not in [u'http', u'socks4', u'socks5'])):
# Print help
console_print(proxy.__doc__, linebreak=False)
return

ARGS = ['mode', 'type', 'host', 'port', 'username', 'password']

# Load the args into a dictionary
kwargs = dict(zip(ARGS, [a.decode(sys.getfilesystemencoding()) for a in args]))

# Re-set these two because they were coerced to lower case
kwargs['mode'] = mode
if type_:
kwargs['type'] = type_

try:
with closing(DropboxCommand()) as dc:
try:
dc.set_proxy_settings(**kwargs)
console_print(u'set')
except DropboxCommand.CommandError, e:
console_print(u"Couldn't set proxy: " + str(e))
except DropboxCommand.BadConnectionError, e:
console_print(u"Dropbox isn't responding!")
except DropboxCommand.EOFError:
console_print(u"Dropbox daemon stopped.")
except DropboxCommand.CouldntConnectError, e:
console_print(u"Dropbox isn't running!")

@command
@requires_dropbox_running
def throttle(args):
u"""set bandwidth limits for Dropbox
dropbox throttle DOWNLOAD UPLOAD
Set bandwidth limits for file sync.
DOWNLOAD - either "unlimited" or a manual limit in KB/s
UPLOAD - one of "unlimited", "auto", or a manual limit in KB/s
"""
if len(args) != 2:
console_print(throttle.__doc__, linebreak=False)
return

downlimit = args[0].decode(sys.getfilesystemencoding()).lower()
uplimit = args[1].decode(sys.getfilesystemencoding()).lower()

download_limit = None
download_mode = None
if downlimit == u'unlimited':
download_mode = downlimit
else:
try:
download_limit = int(downlimit)
download_mode = u'manual'
except ValueError:
console_print(throttle.__doc__, linebreak=False)
return

upload_limit = None
upload_mode = None
if uplimit in [u'unlimited', u'auto']:
upload_mode = uplimit
else:
try:
upload_limit = int(uplimit)
upload_mode = u'manual'
except ValueError:
console_print(throttle.__doc__, linebreak=False)
return

kwargs = {
u'download_mode': download_mode,
u'upload_mode': upload_mode,
}
if download_limit:
kwargs[u'download_limit'] = unicode(download_limit)
if upload_limit:
kwargs[u'upload_limit'] = unicode(upload_limit)

try:
with closing(DropboxCommand()) as dc:
try:
dc.set_bandwidth_limits(**kwargs)
console_print(u'set')
except DropboxCommand.CommandError, e:
console_print(u"Couldn't set bandwidth limits: " + str(e))
except DropboxCommand.BadConnectionError, e:
console_print(u"Dropbox isn't responding!")
except DropboxCommand.EOFError:
console_print(u"Dropbox daemon stopped.")
except DropboxCommand.CouldntConnectError, e:
console_print(u"Dropbox isn't running!")

@command
@requires_dropbox_running
def status(args):

0 comments on commit d3261c1

Please sign in to comment.
You can’t perform that action at this time.