diff options
author | name <[email protected]> | 2015-03-13 13:03:15 -0700 |
---|---|---|
committer | raveit65 <[email protected]> | 2019-01-09 20:05:00 +0100 |
commit | d3261c14f40745ce39772e58009a6e0988f53911 (patch) | |
tree | dd9a9b23b6daa33f1cf01b473dc69eb3fdf54a2f /caja-dropbox.in | |
parent | a2ccaaf76d82811158cf411be2829aa906870a5e (diff) | |
download | caja-dropbox-d3261c14f40745ce39772e58009a6e0988f53911.tar.bz2 caja-dropbox-d3261c14f40745ce39772e58009a6e0988f53911.tar.xz |
Update dropbox.py with shmodel, proxy, and throttle features.
origin commit:
https://github.com/dropbox/nautilus-dropbox/commit/103743d
Diffstat (limited to 'caja-dropbox.in')
-rwxr-xr-x | caja-dropbox.in | 151 |
1 files changed, 149 insertions, 2 deletions
diff --git a/caja-dropbox.in b/caja-dropbox.in index 5026ab7..ba929b6 100755 --- a/caja-dropbox.in +++ b/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) @@ -1019,6 +1019,153 @@ Prints out a public url for FILE. @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): u"""get current status of the dropboxd dropbox status |