Skip to content

Commit 809e3d3

Browse files
authored
Merge pull request #142 from MerginMaps/fix_list
list projects for more > 50
2 parents a99514a + 3efbb56 commit 809e3d3

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
venv*
12
__pycache__/
23
*.py[co]
34
*.egg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ python3 -m twine upload dist/mergin-client-x.y.z.tar.gz
162162

163163
### Installing deps
164164

165-
Python 3.7+ required. Create `mergin/deps` folder where [geodiff](https://github.com/lutraconsulting/geodiff) lib is supposed to be and install dependencies:
165+
Python 3.7+ required. Create `mergin/deps` folder where [geodiff](https://github.com/MerginMaps/geodiff) lib is supposed to be and install dependencies:
166166
```
167167
rm -r mergin/deps
168168
mkdir mergin/deps

mergin/cli.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,41 @@ def create(ctx, project, public, from_dir):
223223
help="What kind of projects (e.g. 'created' for just my projects,"
224224
"'shared' for projects shared with me. No flag means returns all public projects.",
225225
)
226+
@click.option(
227+
"--name",
228+
help="Filter projects with name like name",
229+
)
230+
@click.option(
231+
"--namespace",
232+
help="Filter projects with namespace like namespace",
233+
)
234+
@click.option(
235+
"--order_params",
236+
help="optional attributes for sorting the list. "
237+
"It should be a comma separated attribute names "
238+
"with _asc or _desc appended for sorting direction. "
239+
"For example: \"namespace_asc,disk_usage_desc\". "
240+
"Available attrs: namespace, name, created, updated, disk_usage, creator",
241+
)
226242
@click.pass_context
227-
def list_projects(ctx, flag):
243+
def list_projects(ctx, flag, name, namespace, order_params):
228244
"""List projects on the server."""
229245
filter_str = "(filter flag={})".format(flag) if flag is not None else "(all public)"
246+
230247
click.echo("List of projects {}:".format(filter_str))
248+
231249
mc = ctx.obj["client"]
232250
if mc is None:
233251
return
234-
resp = mc.paginated_projects_list(flag=flag)
235-
projects_list = resp["projects"]
252+
253+
projects_list = mc.projects_list(
254+
flag=flag,
255+
name=name,
256+
namespace=namespace,
257+
order_params=order_params
258+
)
259+
260+
click.echo("Fetched {} projects .".format(len(projects_list)))
236261
for project in projects_list:
237262
full_name = "{} / {}".format(project["namespace"], project["name"])
238263
click.echo(

mergin/client.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,11 @@ def paginated_projects_list(self, page=1, per_page=50, tags=None, user=None, fla
424424
projects = json.load(resp)
425425
return projects
426426

427-
def projects_list(self, tags=None, user=None, flag=None, q=None):
427+
def projects_list(self, tags=None, user=None, flag=None, name=None, namespace=None, order_params=None):
428428
"""
429-
Find all available Mergin Maps projects. It will always retrieve max 100 projects.
430-
Consider using the paginated_projects_list instead.
429+
Find all available Mergin Maps projects.
430+
431+
Calls paginated_projects_list for all pages. Can take significant time to fetch all pages.
431432
432433
:param tags: Filter projects by tags ('valid_qgis', 'mappin_use', input_use')
433434
:type tags: List
@@ -438,22 +439,40 @@ def projects_list(self, tags=None, user=None, flag=None, q=None):
438439
:param flag: Predefined filter flag ('created', 'shared')
439440
:type flag: String
440441
441-
:param q: Search query string
442-
:type q: String
442+
:param name: Filter projects with name like name
443+
:type name: String
444+
445+
:param namespace: Filter projects with namespace like namespace
446+
:type namespace: String
447+
448+
:param order_params: optional attributes for sorting the list. It should be a comma separated attribute names
449+
with _asc or _desc appended for sorting direction. For example: "namespace_asc,disk_usage_desc".
450+
Available attrs: namespace, name, created, updated, disk_usage, creator
451+
:type order_params: String
443452
444453
:rtype: List[Dict]
445454
"""
446-
params = {}
447-
if tags:
448-
params["tags"] = ",".join(tags)
449-
if user:
450-
params["user"] = user
451-
if flag:
452-
params["flag"] = flag
453-
if q:
454-
params["q"] = q
455-
resp = self.get("/v1/project", params)
456-
projects = json.load(resp)
455+
projects = []
456+
page_i = 1
457+
fetched_projects = 0
458+
while True:
459+
resp = self.paginated_projects_list(
460+
page=page_i,
461+
per_page=50,
462+
tags=tags,
463+
user=user,
464+
flag=flag,
465+
name=name,
466+
namespace=namespace,
467+
order_params=order_params
468+
)
469+
fetched_projects += len(resp["projects"])
470+
count = resp["count"]
471+
projects += resp["projects"]
472+
if fetched_projects < count:
473+
page_i += 1
474+
else:
475+
break
457476
return projects
458477

459478
def project_info(self, project_path, since=None, version=None):

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
platforms='any',
1919
install_requires=[
20-
'python-dateutil==2.6.0',
21-
'pygeodiff==1.0.5',
22-
'pytz==2019.3',
23-
'click',
20+
'python-dateutil==2.8.2',
21+
'pygeodiff==1.0.6',
22+
'pytz==2022.1',
23+
'click==8.1.3',
2424
],
2525

2626
entry_points={

0 commit comments

Comments
 (0)