Skip to content

Commit 68b84c1

Browse files
committed
Introduce:
- models.py for some classes without specific location - clenup of non-necssary functions from previous version - refactor of pull handling using PullActions
1 parent 001c83d commit 68b84c1

File tree

8 files changed

+413
-342
lines changed

8 files changed

+413
-342
lines changed

mergin/client.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import typing
1818
import warnings
1919

20+
from mergin.models import ProjectDelta, ProjectDeltaItemDiff, ProjectDeltaItem
21+
2022
from .common import (
2123
ClientError,
2224
LoginError,
@@ -735,7 +737,7 @@ def project_info_v2(self, project_id: str, files_at_version=None):
735737
resp = self.get(f"/v2/projects/{project_id}", params)
736738
return json.load(resp)
737739

738-
def get_project_delta(self, project_id: str, since: str, to: typing.Optional[str] = None):
740+
def get_project_delta(self, project_id: str, since: str, to: typing.Optional[str] = None) -> ProjectDelta:
739741
"""
740742
Fetch info about project delta since given version.
741743
@@ -751,7 +753,28 @@ def get_project_delta(self, project_id: str, since: str, to: typing.Optional[str
751753
if to:
752754
params["to"] = to
753755
resp = self.get(f"/v2/projects/{project_id}/delta", params)
754-
return json.load(resp)
756+
resp_parsed = json.load(resp)
757+
return ProjectDelta(
758+
to_version=resp_parsed.get("to_version"),
759+
items=[
760+
ProjectDeltaItem(
761+
path=item["path"],
762+
size=item.get("size"),
763+
checksum=item.get("checksum"),
764+
version=item.get("version"),
765+
change=item.get("change"),
766+
diffs=(
767+
[
768+
ProjectDeltaItemDiff(
769+
id=diff.get("id"),
770+
)
771+
for diff in item.get("diffs", [])
772+
]
773+
),
774+
)
775+
for item in resp_parsed.get("items", [])
776+
],
777+
)
755778

756779
def paginated_project_versions(self, project_path, page, per_page=100, descending=False):
757780
"""
@@ -1091,7 +1114,7 @@ def project_status(self, directory):
10911114
mp = MerginProject(directory)
10921115
server_info = self.project_info(mp.project_full_name(), since=mp.version())
10931116

1094-
pull_changes = mp.get_pull_changes(server_info["files"])
1117+
pull_changes = mp.get_pull_delta(server_info["files"])
10951118

10961119
push_changes = mp.get_push_changes()
10971120
push_changes_summary = mp.get_list_of_push_changes(push_changes)

mergin/client_pull.py

Lines changed: 89 additions & 105 deletions
Large diffs are not rendered by default.

mergin/common.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,8 @@ class DeltaChangeType(Enum):
105105
UPDATE_DIFF = "update_diff"
106106

107107

108-
@dataclass
109-
class ProjectDeltaItem:
110-
change: DeltaChangeType
111-
path: str
112-
version: str
113-
size: int
114-
checksum: str
115-
diffs: List[Dict[str, Any]] = field(default_factory=list)
116-
117-
def __post_init__(self):
118-
self.change = DeltaChangeType(self.change)
108+
class PullActionType(Enum):
109+
COPY = "copy"
110+
COPY_CONFLICT = "copy_conflict"
111+
APPLY_DIFF = "apply_diff"
112+
DELETE = "delete"

0 commit comments

Comments
 (0)