Skip to content

Commit

Permalink
Merge pull request #816 from samschott/bandwidth-control
Browse files Browse the repository at this point in the history
Allow setting bandwidth limits
  • Loading branch information
samschott authored Feb 3, 2023
2 parents 1c0c554 + 23d0a97 commit 7c3029d
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 127 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Changed:

* Allow limiting the upload and download bandwidth used for syncing, either by setting
the config file values or by using the CLI `maestral bandwidth-limit up|down`.
* Speed up querying the sync status of folders.
* Added support for Python 3.12.

Expand Down
3 changes: 2 additions & 1 deletion src/maestral/cli/cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .core import OrderedGroup
from .cli_core import start, stop, gui, pause, resume, auth, sharelink
from .cli_info import status, filestatus, activity, history, ls, config_files
from .cli_settings import autostart, excluded, notify
from .cli_settings import autostart, excluded, notify, bandwidth_limit
from .cli_maintenance import (
move_dir,
rebuild_index,
Expand Down Expand Up @@ -48,6 +48,7 @@ def main() -> None:
main.add_command(autostart, section="Settings")
main.add_command(excluded, section="Settings")
main.add_command(notify, section="Settings")
main.add_command(bandwidth_limit, section="Settings")

main.add_command(move_dir, section="Maintenance")
main.add_command(rebuild_index, section="Maintenance")
Expand Down
44 changes: 44 additions & 0 deletions src/maestral/cli/cli_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,47 @@ def notify_snooze(m: Maestral, minutes: int) -> None:
ok(f"Notifications snoozed for {minutes} min. Set snooze to 0 to reset.")
else:
ok("Notifications enabled.")


@click.group(help="View and manage bandwidth limits. Changes take effect immediately.")
def bandwidth_limit() -> None:
pass


@bandwidth_limit.command(
name="up", help="Get / set bandwidth limit for uploads in MB/sec (0 = unlimited)."
)
@click.argument(
"mb_per_second",
required=False,
type=click.FLOAT,
)
@inject_proxy(fallback=True, existing_config=True)
def bandwidth_limit_up(m: Maestral, mb_per_second: float | None) -> None:
if mb_per_second is not None:
m.bandwidth_limit_up = mb_per_second * 10**6
speed_str = f"{mb_per_second} MB/sec" if mb_per_second > 0 else "unlimited"
ok(f"Upload bandwidth limit set to {speed_str}.")
else:
mb_per_second = m.bandwidth_limit_up / 10**6
echo(f"{mb_per_second} MB/sec" if mb_per_second > 0 else "unlimited")


@bandwidth_limit.command(
name="down",
help="Get / set bandwidth limit for downloads in MB/sec (0 = unlimited).",
)
@click.argument(
"mb_per_second",
required=False,
type=click.FLOAT,
)
@inject_proxy(fallback=True, existing_config=True)
def bandwidth_limit_down(m: Maestral, mb_per_second: float | None) -> None:
if mb_per_second is not None:
m.bandwidth_limit_down = mb_per_second * 10**6
speed_fmt = f"{mb_per_second} MB/sec" if mb_per_second > 0 else "unlimited"
ok(f"Download bandwidth limit set to {speed_fmt}.")
else:
mb_per_second = m.bandwidth_limit_down / 10**6
echo(f"{mb_per_second} MB/sec" if mb_per_second > 0 else "unlimited")
Loading

0 comments on commit 7c3029d

Please sign in to comment.