Skip to content

Commit 9adb76e

Browse files
authored
Merge pull request #33 from lutraconsulting/#25-Warning-when-no-free-space-left
#25 warning when no free space left
2 parents 7a97d17 + 3d791d9 commit 9adb76e

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

Pipfile.lock

Lines changed: 33 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mergin/client.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class ClientError(Exception):
5252
class SyncError(Exception):
5353
pass
5454

55-
5655
class MerginProject:
5756
""" Base class for Mergin local projects.
5857
@@ -811,6 +810,19 @@ def download_project(self, project_path, directory, parallel=True):
811810
"files": project_info["files"]
812811
}
813812

813+
def enough_storage_available(self, data):
814+
user_name = self._user_info["username"]
815+
resp = self.get('/v1/user/' + user_name)
816+
info = json.load(resp)
817+
free_space = int(info["storage_limit"]) - int(info["disk_usage"])
818+
upload_files_sizes =[f["size"] for f in data["updated"] + data["added"]]
819+
size_to_upload = sum(upload_files_sizes)
820+
821+
if size_to_upload > free_space:
822+
return False, free_space
823+
824+
return True, free_space
825+
814826
def push_project(self, directory, parallel=True):
815827
"""
816828
Upload local changes to the repository.
@@ -829,6 +841,11 @@ def push_project(self, directory, parallel=True):
829841
raise ClientError("Update your local repository")
830842

831843
changes = mp.get_push_changes()
844+
enough_free_space, freespace = self.enough_storage_available(changes)
845+
if not enough_free_space:
846+
freespace = int(freespace/(1024*1024))
847+
raise SyncError("Storage limit has been reached. Only " + str(freespace) + "MB left")
848+
832849
if not sum(len(v) for v in changes.values()):
833850
return
834851
# drop internal info from being sent to server

0 commit comments

Comments
 (0)