Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipper
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
MECRED
Zipper
Merge requests
!1
Issue
#1
: ADD check if there any files to zip
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#1
: ADD check if there any files to zip
issue-1/check-zip-empty
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Richard Fernando Heise Ferreira
requested to merge
issue-1/check-zip-empty
into
master
10 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
becf65b0
1 commit,
10 months ago
1 file
+
17
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
app/proxy.py
+
17
−
3
Options
@@ -57,17 +57,31 @@ def create_zip(files, collection_id):
@app.route
(
'
/<collection_id>
'
,
methods
=
[
'
GET
'
])
def
download_zip
(
collection_id
):
try
:
if
os
.
path
.
exists
(
f
"
colecao_
{
collection_id
}
.zip
"
):
zip_path
=
os
.
path
.
abspath
(
f
"
colecao_
{
collection_id
}
.zip
"
)
zip_filename
=
f
"
colecao_
{
collection_id
}
.zip
"
if
os
.
path
.
exists
(
zip_filename
):
# Check if zip file is empty
with
ZipFile
(
zip_filename
,
'
r
'
)
as
zip
:
if
not
zip
.
namelist
():
# If namelist() returns an empty list, the zip is empty
return
"
Zip is empty
"
,
200
# Zip file exists and is not empty, send it
zip_path
=
os
.
path
.
abspath
(
zip_filename
)
return
send_file
(
zip_path
,
as_attachment
=
True
),
200
ids
=
get_collection_ids
(
collection_id
)
downloaded_files
=
download_files
(
ids
)
# Check if downloaded_files is empty
if
not
downloaded_files
:
return
"
No files to zip
"
,
200
create_zip
(
downloaded_files
,
collection_id
)
zip_path
=
os
.
path
.
abspath
(
f
"
colecao_
{
collection_id
}
.zip
"
)
zip_path
=
os
.
path
.
abspath
(
zip_filename
)
response
=
send_file
(
zip_path
,
as_attachment
=
True
)
return
response
,
200
except
Exception
as
e
:
return
str
(
e
),
500
if
__name__
==
"
__main__
"
:
app
.
run
(
port
=
3333
)
Loading