Skip to content

Commit eade994

Browse files
committed
Support more endpoints with project info + CLI integration
1 parent d2d8eb9 commit eade994

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

mergin/cli.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
pip puts these tools).
88
"""
99

10+
import json
1011
import os
1112
import sys
1213
import traceback
@@ -15,6 +16,7 @@
1516
from mergin import (
1617
ClientError,
1718
MerginClient,
19+
MerginProject,
1820
InvalidProject,
1921
LoginError,
2022
)
@@ -292,6 +294,69 @@ def pull():
292294
_print_unhandled_exception()
293295

294296

297+
@cli.command()
298+
@click.argument('version')
299+
def show_version(version):
300+
""" Displays information about a single version of a project """
301+
302+
c = _init_client()
303+
if c is None:
304+
return
305+
directory = os.getcwd()
306+
307+
mp = MerginProject(directory)
308+
project_path = mp.metadata["name"]
309+
310+
version_info_dict = c.project_version_info(project_path, version)[0]
311+
print("Project: " + version_info_dict['project']['namespace'] + "/" + version_info_dict['project']['name'])
312+
print("Version: " + version_info_dict['name'] + " by " + version_info_dict['author'])
313+
print("Time: " + version_info_dict['created'])
314+
pretty_diff(version_info_dict['changes'])
315+
316+
317+
@cli.command()
318+
@click.argument('path')
319+
def show_file_history(path):
320+
""" Displays information about a single version of a project """
321+
322+
c = _init_client()
323+
if c is None:
324+
return
325+
directory = os.getcwd()
326+
327+
mp = MerginProject(directory)
328+
project_path = mp.metadata["name"]
329+
330+
info_dict = c.project_file_history_info(project_path, path)
331+
history_dict = info_dict['history']
332+
333+
print("File history: " + info_dict['path'])
334+
print("-----")
335+
for version, version_data in history_dict.items():
336+
diff_info = ''
337+
if 'diff' in version_data:
338+
diff_info = "diff ({} bytes)".format(version_data['diff']['size'])
339+
print(" {:5} {:10} {}".format(version, version_data['change'], diff_info))
340+
341+
342+
@cli.command()
343+
@click.argument('path')
344+
@click.argument('version')
345+
def show_file_changeset(path, version):
346+
""" Displays information about a single version of a project """
347+
348+
c = _init_client()
349+
if c is None:
350+
return
351+
directory = os.getcwd()
352+
353+
mp = MerginProject(directory)
354+
project_path = mp.metadata["name"]
355+
356+
info_dict = c.project_file_changeset_info(project_path, path, version)
357+
print(json.dumps(info_dict, indent=2))
358+
359+
295360
@cli.command()
296361
@click.argument('directory', required=False)
297362
def modtime(directory):

mergin/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,21 @@ def project_status(self, directory):
414414
push_changes_summary = mp.get_list_of_push_changes(push_changes)
415415

416416
return pull_changes, push_changes, push_changes_summary
417+
418+
def project_version_info(self, project_path, version):
419+
""" Returns JSON with detailed information about a single project version"""
420+
params = {'version_id': version}
421+
resp = self.get("/v1/project/version/{}".format(project_path), params)
422+
return json.load(resp)
423+
424+
def project_file_history_info(self, project_path, file_path):
425+
""" Returns JSON with full history of a single file within a project """
426+
params = {'path': file_path}
427+
resp = self.get("/v1/resource/history/{}".format(project_path), params)
428+
return json.load(resp)
429+
430+
def project_file_changeset_info(self, project_path, file_path, version):
431+
""" Returns JSON with changeset details of a particular version of a file within a project """
432+
params = {'path': file_path}
433+
resp = self.get("/v1/resource/changesets/{}/{}".format(project_path, version), params)
434+
return json.load(resp)

0 commit comments

Comments
 (0)