Skip to content

Split push for blocking and non-blocking #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ Commands:
share Fetch permissions to project
share-add Add permissions to [users] to project
share-remove Remove [users] permissions from project
show-file-changeset Displays information about project changes.
show-file-history Displays information about a single version of a...
show-version Displays information about a single version of a...
show-file-changeset Display information about project changes.
show-file-history Display information about a single version of a...
show-version Display information about a single version of a...
status Show all changes in project files - upstream and...
```

Expand All @@ -99,7 +99,7 @@ To download a specific version of a project:
$ mergin --username john download --version v42 john/project1 ~/mergin/project1
```

To download a sepecific version of a single file:
To download a specific version of a single file:

1. First you need to download the project:
```
Expand Down
32 changes: 17 additions & 15 deletions mergin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,25 +412,27 @@ def push(ctx):
return
directory = os.getcwd()
try:
job = push_project_async(mc, directory)
if job is not None: # if job is none, we don't upload any files, and the transaction is finished already
with click.progressbar(length=job.total_size) as bar:
last_transferred_size = 0
while push_project_is_running(job):
time.sleep(1 / 10) # 100ms
new_transferred_size = job.transferred_size
bar.update(new_transferred_size - last_transferred_size) # the update() needs increment only
last_transferred_size = new_transferred_size
push_project_finalize(job)
click.echo("Done")
jobs = push_project_async(mc, directory)
for job in jobs:
if job is not None: # if job is none, we don't upload any files, and the transaction is finished already
with click.progressbar(length=job.total_size) as bar:
last_transferred_size = 0
while push_project_is_running(job):
time.sleep(1 / 10) # 100ms
new_transferred_size = job.transferred_size
bar.update(new_transferred_size - last_transferred_size) # the update() needs increment only
last_transferred_size = new_transferred_size
push_project_finalize(job)
click.echo("Done")
except InvalidProject as e:
click.secho("Invalid project directory ({})".format(str(e)), fg="red")
except ClientError as e:
click.secho("Error: " + str(e), fg="red")
return
except KeyboardInterrupt:
click.secho("Cancelling...")
push_project_cancel(job)
for job in jobs:
push_project_cancel(job)
except Exception as e:
_print_unhandled_exception()

Expand Down Expand Up @@ -473,7 +475,7 @@ def pull(ctx):
@click.argument("version")
@click.pass_context
def show_version(ctx, version):
"""Displays information about a single version of a project. `version` is 'v1', 'v2', etc."""
"""Display information about a single version of a project. `version` is 'v1', 'v2', etc."""
mc = ctx.obj["client"]
if mc is None:
return
Expand All @@ -492,7 +494,7 @@ def show_version(ctx, version):
@click.argument("path")
@click.pass_context
def show_file_history(ctx, path):
"""Displays information about a single version of a project."""
"""Display information about a single version of a project."""
mc = ctx.obj["client"]
if mc is None:
return
Expand All @@ -516,7 +518,7 @@ def show_file_history(ctx, path):
@click.argument("version")
@click.pass_context
def show_file_changeset(ctx, path, version):
"""Displays information about project changes."""
"""Display information about project changes."""
mc = ctx.obj["client"]
if mc is None:
return
Expand Down
14 changes: 8 additions & 6 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
plugin_version=None,
proxy_config=None,
):
self.url = url if url is not None else MerginClient.default_url()
self.url = (url if url is not None else MerginClient.default_url()).rstrip("/") + "/"
self._auth_params = None
self._auth_session = None
self._user_info = None
Expand Down Expand Up @@ -473,7 +473,8 @@ def create_project(self, project_name, is_public=False, namespace=None):

def create_project_and_push(self, project_name, directory, is_public=False, namespace=None):
"""
Convenience method to create project and push the initial version right after that.
Convenience method to create project and push the the files right after that.
Creates two versions when directory contains blocking and non-blocking changes.

:param project_name: Project's full name (<namespace>/<name>)
:type project_name: String
Expand Down Expand Up @@ -896,11 +897,12 @@ def push_project(self, directory):
:param directory: Project's directory
:type directory: String
"""
job = push_project_async(self, directory)
if job is None:
jobs = push_project_async(self, directory)
if not jobs:
return # there is nothing to push (or we only deleted some files)
push_project_wait(job)
push_project_finalize(job)
for job in jobs:
push_project_wait(job)
push_project_finalize(job)

def pull_project(self, directory):
"""
Expand Down
Loading
Loading