Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
neodarz
cli
Commits
f6a827cd
Verified
Commit
f6a827cd
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Fixed some pagination issues
parent
e9e60e76
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
funkwhale_cli/cli.py
+29
-34
29 additions, 34 deletions
funkwhale_cli/cli.py
funkwhale_cli/output.py
+1
-1
1 addition, 1 deletion
funkwhale_cli/output.py
tests/test_cli.py
+4
-0
4 additions, 0 deletions
tests/test_cli.py
with
34 additions
and
35 deletions
funkwhale_cli/cli.py
+
29
−
34
View file @
f6a827cd
...
...
@@ -188,7 +188,7 @@ def get_url_param(url, name):
def
get_pagination_data
(
payload
):
data
=
{
"
current_page
"
:
1
,
"
next_page
"
:
None
,
"
page_size
"
:
None
}
data
=
{
"
next_page
"
:
None
,
"
page_size
"
:
None
}
if
payload
.
get
(
"
next
"
):
next_page
=
get_url_param
(
payload
[
"
next
"
],
"
page
"
)
data
[
"
next_page
"
]
=
int
(
next_page
)
...
...
@@ -197,14 +197,15 @@ def get_pagination_data(payload):
data
[
"
page_size
"
]
=
len
(
payload
[
"
results
"
])
if
payload
.
get
(
"
previous
"
):
previous_page
=
get_url_param
(
payload
[
"
previous
"
],
"
page
"
)
or
1
data
[
"
current_page
"
]
=
int
(
previous_page
)
+
1
if
not
data
.
get
(
"
total_pages
"
):
data
[
"
total_pages
"
]
=
data
[
"
current_page
"
]
if
not
data
[
"
page_size
"
]:
previous_page
=
get_url_param
(
payload
[
"
previous
"
],
"
page
"
)
or
0
data
.
setdefault
(
'
current_page
'
,
int
(
previous_page
)
+
1
)
data
.
setdefault
(
'
total_pages
'
,
data
[
"
current_page
"
])
if
not
data
[
"
page_size
"
]
and
payload
[
"
count
"
]
-
len
(
payload
[
"
results
"
])
>
0
and
data
[
"
total_pages
"
]
>
1
:
data
[
"
page_size
"
]
=
int
(
payload
[
"
count
"
]
-
len
(
payload
[
"
results
"
]))
/
(
data
[
"
total_pages
"
]
-
1
)
data
.
setdefault
(
'
current_page
'
,
1
)
data
.
setdefault
(
'
total_pages
'
,
1
)
return
data
...
...
@@ -243,12 +244,15 @@ def get_ls_command(group, endpoint, output_conf):
)
)
pagination_data
=
get_pagination_data
(
payload
)
if
pagination_data
[
"
page_size
"
]:
start
=
(
int
(
(
pagination_data
[
"
current_page
"
]
-
1
)
*
pagination_data
[
"
page_size
"
]
)
+
1
)
else
:
start
=
1
end
=
min
(
start
+
len
(
payload
[
"
results
"
])
-
1
,
payload
[
"
count
"
])
click
.
echo
(
"
\n
Objects {start}-{end} on {total} (page {current_page}/{total_pages})
"
.
format
(
...
...
@@ -256,7 +260,7 @@ def get_ls_command(group, endpoint, output_conf):
end
=
end
,
total
=
payload
[
"
count
"
],
current_page
=
pagination_data
[
"
current_page
"
],
total_pages
=
pagination_data
[
"
total_pages
"
],
total_pages
=
pagination_data
[
"
total_pages
"
]
or
1
,
)
)
...
...
@@ -320,6 +324,19 @@ async def libraries_create(ctx, raw, name, visibility):
)
@cli.group
()
@click.pass_context
def
artists
(
ctx
):
pass
artists_ls
=
get_ls_command
(
artists
,
"
api/v1/artists/
"
,
output_conf
=
{
"
labels
"
:
[
"
ID
"
,
"
Name
"
,
"
Created
"
],
"
type
"
:
"
ARTIST
"
},
)
@cli.group
()
@click.pass_context
def
tracks
(
ctx
):
...
...
@@ -333,28 +350,6 @@ tracks_ls = get_ls_command(
)
@tracks.command
(
"
search
"
)
@click.argument
(
"
query
"
)
@click.option
(
"
--raw
"
,
is_flag
=
True
)
@click.pass_context
@async_command
async
def
track_search
(
ctx
,
raw
,
query
):
async
with
ctx
.
obj
[
"
remote
"
]:
result
=
await
ctx
.
obj
[
"
remote
"
].
request
(
"
get
"
,
"
api/v1/tracks/
"
,
params
=
{
"
q
"
:
query
}
)
result
.
raise_for_status
()
payload
=
await
result
.
json
()
if
raw
:
click
.
echo
(
json
.
dumps
(
payload
,
sort_keys
=
True
,
indent
=
4
))
else
:
click
.
echo
(
output
.
table
(
payload
[
"
results
"
],
[
"
ID
"
,
"
Title
"
,
"
Artist
"
,
"
Album
"
],
type
=
"
TRACK
"
)
)
async
def
get_track_download_url
(
id
,
remote
):
result
=
await
remote
.
request
(
"
get
"
,
"
api/v1/tracks/{}/
"
.
format
(
id
))
result
.
raise_for_status
()
...
...
This diff is collapsed.
Click to expand it.
funkwhale_cli/output.py
+
1
−
1
View file @
f6a827cd
...
...
@@ -16,13 +16,13 @@ FIELDS = {
"
Mimetype
"
:
{
"
field
"
:
"
mimetype
"
},
},
"
LIBRARY
"
:
{
"
Name
"
:
{
"
field
"
:
"
name
"
},
"
Visibility
"
:
{
"
field
"
:
"
privacy_level
"
},
"
Description
"
:
{
"
field
"
:
"
description
"
},
"
Uploads
"
:
{
"
field
"
:
"
uploads_count
"
},
},
"
*
"
:
{
"
Created
"
:
{
"
field
"
:
"
creation_date
"
},
"
Name
"
:
{
"
field
"
:
"
name
"
},
"
ID
"
:
{
"
field
"
:
"
id
"
,
"
truncate
"
:
0
},
"
UUID
"
:
{
"
field
"
:
"
uuid
"
,
"
truncate
"
:
0
},
},
...
...
This diff is collapsed.
Click to expand it.
tests/test_cli.py
+
4
−
0
View file @
f6a827cd
...
...
@@ -53,6 +53,10 @@ def test_delete_command(group, cli_ctx, session, responses):
{
"
previous
"
:
"
http://test/?page=6
"
,
"
count
"
:
13
,
"
results
"
:
[
1
]},
{
"
current_page
"
:
7
,
"
next_page
"
:
None
,
"
total_pages
"
:
7
,
"
page_size
"
:
2
},
),
(
{
"
previous
"
:
"
http://test/
"
,
"
count
"
:
4
,
"
results
"
:
[
1
,
2
,
3
,
4
]},
{
"
current_page
"
:
1
,
"
next_page
"
:
None
,
"
total_pages
"
:
1
,
"
page_size
"
:
None
},
),
],
)
def
test_get_pagination_data
(
input
,
output
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment