Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Petal Hero
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
Petal Hero
Commits
ae14a2cf
Verified
Commit
ae14a2cf
authored
1 year ago
by
dos
Browse files
Options
Downloads
Patches
Plain Diff
Download to .part files and rename after completion
parent
7aad7438
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
download.py
+24
-4
24 additions, 4 deletions
download.py
with
24 additions
and
4 deletions
download.py
+
24
−
4
View file @
ae14a2cf
...
@@ -38,6 +38,8 @@ def download_thread(self):
...
@@ -38,6 +38,8 @@ def download_thread(self):
if
not
os
.
path
.
exists
(
rootpath
):
if
not
os
.
path
.
exists
(
rootpath
):
os
.
mkdir
(
rootpath
)
os
.
mkdir
(
rootpath
)
downloaded
=
[]
while
self
.
file_list
and
not
self
.
cancel
:
while
self
.
file_list
and
not
self
.
cancel
:
self
.
current_song
=
self
.
file_list
.
pop
(
0
)
self
.
current_song
=
self
.
file_list
.
pop
(
0
)
self
.
file_no
+=
1
self
.
file_no
+=
1
...
@@ -69,9 +71,19 @@ def download_thread(self):
...
@@ -69,9 +71,19 @@ def download_thread(self):
req
.
close
()
req
.
close
()
self
.
file_progress
=
1.0
self
.
file_progress
=
1.0
continue
continue
else
:
os
.
unlink
(
file_name
)
if
os
.
path
.
exists
(
file_name
+
"
.part
"
):
stat
=
os
.
stat
(
file_name
+
"
.part
"
)
if
stat
[
6
]
==
total_size
:
req
.
close
()
self
.
file_progress
=
1.0
downloaded
.
append
(
file_name
)
continue
rec_size
=
0
rec_size
=
0
with
open
(
file_name
,
"
wb
"
)
as
f
:
with
open
(
file_name
+
"
.part
"
,
"
wb
"
)
as
f
:
try
:
try
:
while
True
:
while
True
:
new_data
=
req
.
raw
.
read
(
1024
*
32
)
new_data
=
req
.
raw
.
read
(
1024
*
32
)
...
@@ -81,6 +93,7 @@ def download_thread(self):
...
@@ -81,6 +93,7 @@ def download_thread(self):
if
self
.
cancel
:
if
self
.
cancel
:
raise
Exception
(
"
Cancelled
"
)
raise
Exception
(
"
Cancelled
"
)
if
not
new_data
:
if
not
new_data
:
downloaded
.
append
(
file_name
)
break
break
except
Exception
as
e
:
except
Exception
as
e
:
os
.
unlink
(
file_name
)
os
.
unlink
(
file_name
)
...
@@ -92,12 +105,19 @@ def download_thread(self):
...
@@ -92,12 +105,19 @@ def download_thread(self):
self
.
error
=
True
self
.
error
=
True
utils
.
emit
(
"
downloaderror
"
)
utils
.
emit
(
"
downloaderror
"
)
break
break
if
not
self
.
error
:
if
not
self
.
error
:
try
:
try
:
for
filename
in
downloaded
:
os
.
rename
(
filename
+
"
.part
"
,
filename
)
if
self
.
app
:
if
self
.
app
:
self
.
app
.
select
=
select
.
SelectView
(
self
.
app
)
self
.
app
.
select
=
select
.
SelectView
(
self
.
app
)
except
Exception
as
e
:
except
Exception
as
e
:
sys
.
print_exception
(
e
)
sys
.
print_exception
(
e
)
self
.
error
=
True
utils
.
emit
(
"
downloaderror
"
)
if
not
self
.
error
:
self
.
finished
=
True
self
.
finished
=
True
utils
.
emit
(
"
downloadfinished
"
)
utils
.
emit
(
"
downloadfinished
"
)
download_lock
.
release
()
download_lock
.
release
()
...
...
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