Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Firmware Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
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
firmware
FFS Firmware Downloader
Commits
95c9127c
Commit
95c9127c
authored
4 years ago
by
Nico
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
download-latest-firmware-build.py
+70
-0
70 additions, 0 deletions
download-latest-firmware-build.py
with
70 additions
and
0 deletions
download-latest-firmware-build.py
0 → 100755
+
70
−
0
View file @
95c9127c
#!/usr/bin/python3
from
pprint
import
pprint
import
requests
import
zipfile
import
tempfile
from
io
import
BytesIO
import
argparse
import
os.path
import
re
import
tempfile
GITLAB_API_BASE
=
"
https://gitlab.freifunk-stuttgart.de/api/v4
"
PROJECT_ID
=
1
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"
--pipeline-id
"
,
help
=
"
Pipeline ID to download. If omitted, download latest.
"
,
default
=
None
)
ap
.
add_argument
(
"
gluonzip
"
)
args
=
ap
.
parse_args
()
def
find_version_from_archive
(
archive_file_list
):
for
file
in
archive_file_list
:
if
file
.
filename
.
startswith
(
"
gluon/output/images
"
):
filename
=
os
.
path
.
basename
(
file
.
filename
)
version_regex
=
re
.
compile
(
r
'
gluon-ffs-(([0-9]+\.[0-9]+[+][0-9]{4}-[0-9]{2}-[0-9]{2})-g\.[a-f0-9]+-s\.[a-f0-9]+-)
'
)
version_matches
=
version_regex
.
match
(
filename
)
if
version_matches
:
return
version_matches
.
group
(
2
)
return
None
def
extract_zip
(
artifact_zipfile
):
with
zipfile
.
ZipFile
(
artifact_zipfile
)
as
artifact_zip
:
version
=
find_version_from_archive
(
artifact_zip
.
infolist
())
print
(
f
"
Version is
{
version
}
"
)
with
tempfile
.
TemporaryDirectory
(
dir
=
os
.
getcwd
())
as
tempdir
:
artifact_zip
.
extractall
(
tempdir
)
outputdir
=
os
.
path
.
join
(
tempdir
,
"
gluon
"
,
"
output
"
)
os
.
rename
(
outputdir
,
version
)
if
args
.
gluonzip
:
extract_zip
(
args
.
gluonzip
)
sys
.
exit
(
0
)
if
args
.
pipeline_id
is
None
:
pipelines_request
=
requests
.
get
(
"
{}/projects/{}/pipelines
"
.
format
(
GITLAB_API_BASE
,
PROJECT_ID
))
pipelines_request
.
raise_for_status
()
pipelines
=
pipelines_request
.
json
()
pipeline_id
=
pipelines
[
0
][
"
id
"
]
else
:
pipeline_id
=
args
.
pipeline_id
pipeline_jobs_request
=
requests
.
get
(
"
{}/projects/{}/pipelines/{}/jobs
"
.
format
(
GITLAB_API_BASE
,
PROJECT_ID
,
pipeline_id
))
pipeline_jobs_request
.
raise_for_status
()
pipeline_jobs
=
pipeline_jobs_request
.
json
()
for
job
in
pipeline_jobs
:
if
job
[
"
name
"
]
==
"
package
"
:
with
tempfile
.
TemporaryFile
()
as
artifact_temp
:
with
requests
.
get
(
"
{}/projects/{}/jobs/{}/artifacts
"
.
format
(
GITLAB_API_BASE
,
PROJECT_ID
,
job
[
"
id
"
]),
stream
=
True
)
as
artifact_request
:
artifact_request
.
raise_for_status
()
for
chunk
in
artifact_request
.
iter_content
(
chunk_size
=
1024
*
1024
):
artifact_temp
.
write
(
chunk
)
with
zipfile
.
ZipFile
(
artifact_temp
)
as
artifact_zip
:
version
=
find_version_from_archive
(
artifact_zip
.
infolist
())
print
(
f
"
Version is
{
version
}
"
)
artifact_zip
.
extractall
(
"
gluon/output/
"
)
os
.
rename
(
"
gluon/output
"
,
version
)
os
.
removedirs
(
"
gluon
"
)
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