Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
IDATT2900-072
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Mattias Agentoft Eggen
IDATT2900-072
Commits
3342665b
Commit
3342665b
authored
3 years ago
by
williamforbrigd
Browse files
Options
Downloads
Patches
Plain Diff
boom boom boom implemented threads
parent
ac1d71ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bbcli/commands/contents.py
+21
-9
21 additions, 9 deletions
bbcli/commands/contents.py
with
21 additions
and
9 deletions
bbcli/commands/contents.py
+
21
−
9
View file @
3342665b
...
...
@@ -8,6 +8,7 @@ from bbcli.views import contents_view
import
time
import
click
import
webbrowser
import
threading
from
bbcli
import
check_response
from
bbcli.entities.Node
import
Node
...
...
@@ -54,13 +55,22 @@ def web_link_options(function):
'
launch_in_new_window
'
,
is_flag
=
True
)(
function
)
return
function
def
list_contents_thread
(
ctx
,
course_id
,
worklist
,
folder_ids
,
root
,
folders
):
if
folders
==
True
:
get_folders
(
ctx
,
course_id
,
worklist
,
folder_ids
)
else
:
get_children
(
ctx
,
course_id
,
worklist
,
folder_ids
)
root_node
=
root
.
preorder
(
root
)
contents_view
.
list_tree
(
folder_ids
,
root_node
,
only_folders
=
folders
)
@click.command
(
name
=
'
list
'
)
@click.argument
(
'
course_id
'
)
@click.option
(
'
-f
'
,
'
--folders
'
,
required
=
False
,
is_flag
=
True
,
help
=
'
Specify this if you want to only list folders.
'
)
@click.option
(
'
-t
'
,
'
--threads
'
,
required
=
False
,
is_flag
=
True
,
help
=
'
Specify this if you want to run with threads
'
)
@click.pass_context
@exception_handler
def
list_contents
(
ctx
,
course_id
:
str
,
folders
:
bool
=
False
):
def
list_contents
(
ctx
,
course_id
:
str
,
folders
:
bool
=
False
,
threads
:
bool
=
True
):
'''
Get the contents
\n
Folders are blue and have an id
\n
...
...
@@ -71,23 +81,25 @@ def list_contents(ctx, course_id: str, folders: bool = False):
response
=
contents_service
.
list_contents
(
ctx
.
obj
[
'
SESSION
'
],
course_id
)
data
=
response
.
json
()[
'
results
'
]
folder_ids
=
dict
()
if
folders
==
True
:
if
threads
==
False
:
for
node
in
data
:
root
=
Node
(
node
)
worklist
=
[
root
]
folder_ids
[
node
[
'
title
'
]]
=
node
[
'
id
'
]
get_folders
(
ctx
,
course_id
,
worklist
,
folder_ids
)
root_node
=
root
.
preorder
(
root
)
contents_view
.
list_tree
(
folder_ids
,
root_node
,
only_folders
=
True
)
list_contents_thread
(
ctx
,
course_id
,
worklist
,
folder_ids
,
root
,
folders
)
else
:
threads
=
[]
for
node
in
data
:
root
=
Node
(
node
)
worklist
=
[
root
]
folder_ids
[
node
[
'
title
'
]]
=
node
[
'
id
'
]
get_children
(
ctx
,
course_id
,
worklist
,
folder_ids
)
root_node
=
root
.
preorder
(
root
)
contents_view
.
list_tree
(
folder_ids
,
root_node
)
args
=
[
ctx
,
course_id
,
worklist
,
folder_ids
,
root
,
folders
]
t
=
threading
.
Thread
(
target
=
list_contents_thread
,
args
=
args
)
t
.
start
()
threads
.
append
(
t
)
[
t
.
join
()
for
t
in
threads
]
end
=
time
.
time
()
print
(
f
'
\n
download time:
{
end
-
start
}
seconds
'
)
...
...
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