Skip to content

Commit 20c2a26

Browse files
authored
Merge pull request #2 from opengisch/path_starts_with
Fix hidden username requirement and rename 'subdir' parameter to 'path-starts-with'
2 parents 022d1a8 + a42df61 commit 20c2a26

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ Download QFieldCloud project files.
115115
qfieldcloud-cli download-files [OPTIONS] PROJECT_ID LOCAL_DIR
116116
117117
Options:
118-
--subdir TEXT Do not download the whole project, but only
119-
the subdirectory passed.
118+
--path-starts-with TEXT Do not download the whole project, but only
119+
the files which path starts with the string.
120120
121121
--exit-on-error / --no-exit-on-error
122122
If any project file download fails stop

src/bin/qfieldcloud-cli

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ def login(ctx, username, password) -> None:
117117
help="Includes the public project in the list. Default: False",
118118
)
119119
@click.pass_context
120-
def list_projects(ctx, username, include_public):
120+
def list_projects(ctx, include_public):
121121
"""List QFieldCloud projects."""
122122
projects = ctx.obj["client"].list_projects(
123-
username=username,
124123
include_public=include_public,
125124
)
126125

@@ -157,18 +156,18 @@ def list_files(ctx, project_id):
157156
@click.argument("project_id")
158157
@click.argument("local_dir")
159158
@click.option(
160-
"--subdir",
161-
help="Do not download the whole project, but only the subdirectory passed.",
159+
"--path-starts-with",
160+
help="Do not download the whole project, but only the files which path starts with the string.",
162161
)
163162
@click.option(
164163
"--exit-on-error/--no-exit-on-error",
165164
help="If any project file download fails stop downloading the rest. Default: False",
166165
)
167166
@click.pass_context
168-
def download_files(ctx, project_id, local_dir, subdir, exit_on_error):
167+
def download_files(ctx, project_id, local_dir, path_starts_with, exit_on_error):
169168
"""Download QFieldCloud project files."""
170169
files = ctx.obj["client"].download_files(
171-
project_id, local_dir, subdir, exit_on_error
170+
project_id, local_dir, path_starts_with, exit_on_error
172171
)
173172

174173
if ctx.obj["format_json"]:

src/qfieldcloud_sdk/sdk.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def list_projects(
5555
"GET",
5656
"projects",
5757
params={
58-
"username": username or "",
5958
"include-public": "1" if include_public else "0",
6059
},
6160
)
@@ -70,15 +69,15 @@ def download_files(
7069
self,
7170
project_id: str,
7271
local_dir: str,
73-
subdir: str = None,
72+
path_starts_with: str = None,
7473
continue_on_error: bool = False,
7574
) -> List[Dict]:
76-
"""Download the specified project files into the destination dir
75+
"""Download the specified project files into the destination dir.
7776
7877
Args:
7978
project_id: id of the project to be downloaded
8079
local_dir: destination directory where the files will be downloaded
81-
subdir: if specified, download only files that are withing that subdirectory, otherwise download all
80+
path_starts_with: if specified, download only files that are within that path starts with, otherwise download all
8281
"""
8382

8483
files = self.list_files(project_id)
@@ -88,13 +87,17 @@ def download_files(
8887
file["status"] = DownloadStatus.PENDING
8988
file["status_reason"] = ""
9089

90+
files_to_download = []
91+
9192
for file in files:
9293
local_file = Path(f'{local_dir}/{file["name"]}')
9394
resp = None
9495

95-
if subdir and not file["name"].startswith(subdir):
96+
if path_starts_with and not file["name"].startswith(path_starts_with):
9697
continue
9798

99+
files_to_download.append(file)
100+
98101
try:
99102
resp = self._request(
100103
"GET",
@@ -126,7 +129,7 @@ def download_files(
126129
f.write(chunk)
127130
files_count += 1
128131

129-
return files
132+
return files_to_download
130133

131134
def _request(
132135
self,

0 commit comments

Comments
 (0)