Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TC LI schemas definitions
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
LI - Lawful Interception
TC LI schemas definitions
Commits
9bb1545a
Commit
9bb1545a
authored
1 year ago
by
canterburym
Browse files
Options
Downloads
Patches
Plain Diff
Adding code to generate attachments post-meeting
parent
33eb9211
No related branches found
No related tags found
2 merge requests
!75
CI/CD creates attachments
,
!74
Adding code to generate attachments post-meeting
Pipeline
#14184
passed
1 year ago
Stage: preflight
Stage: check
Stage: build
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
create_attachments.py
+60
-0
60 additions, 0 deletions
create_attachments.py
with
60 additions
and
0 deletions
create_attachments.py
0 → 100644
+
60
−
0
View file @
9bb1545a
from
io
import
BytesIO
from
pathlib
import
Path
import
logging
import
zipfile
# For ETSI portal attachments, a single zip archive is created which
# contains:
# - All files in the top-level spec directory
# - A zipfile for each subdirectory, which contains all the files in that subdirectory
# This second step is recursive, so each zip file contains only files and other zipfiles, never subdirectories
# For an explanation as to *why* this is the case, speak to your ETSI technical officer.
#
# Example: Assuming the files for the portal attachment are of the following form:
#
# (contents of directory)
# - top_level_file.ext
# - subdirectory_1
# - subdirectory_1_file.ext
# - subdirectory_2
# - subdirectory_2_file.ext
# - TS 102 232-1
#
# ...then the correct form for ETSI portal attachments is as follows
#
# ts_xxxxxx_vxxyyzzp0.zip
# which contains:
# - top_level_file.ext
# - subdirectory_1.zip
# (which contains)
# - subdirectory_1_file.ext
# - subdirectory_2.zip
# (which contains)
# - subdirectory_2_file.ext
def
recursively_zip_directory
(
directory
:
Path
,
zipname
:
str
,
recursion
=
0
):
logging
.
info
(
f
"
{
''
:{
recursion
*
4
}}
Packaging contents of
{
directory
}
into
{
zipname
}
"
)
buffer
=
BytesIO
()
zip
=
zipfile
.
ZipFile
(
buffer
,
"
a
"
)
for
f
in
directory
.
iterdir
():
if
f
.
is_file
():
logging
.
info
(
f
"
{
''
:{
recursion
*
4
}}
Adding file:
{
f
}
"
)
zip
.
write
(
f
,
f
.
name
)
elif
f
.
is_dir
():
zipname
=
f
.
with_suffix
(
"
.zip
"
).
name
logging
.
info
(
f
"
{
''
:{
recursion
*
4
}}
Adding archive:
{
f
}
"
)
recurse_buffer
=
recursively_zip_directory
(
f
,
zipname
,
recursion
+
1
)
zip
.
writestr
(
zipname
,
recurse_buffer
.
getvalue
())
return
buffer
if
__name__
==
"
__main__
"
:
logging
.
info
(
"
Creating attachments...
"
)
for
directory
in
Path
(
"
.
"
).
glob
(
"
1*
"
):
zip_name
=
f
"
ts_
{
directory
.
name
}
vXXYYZZp0.zip
"
zip_buffer
=
recursively_zip_directory
(
directory
,
zip_name
)
with
open
(
zip_name
,
"
wb
"
)
as
f
:
f
.
write
(
zip_buffer
.
getvalue
())
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