Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab-ci
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
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
Clea OS
infrastructure
gitlab-ci
Commits
16669145
Commit
16669145
authored
3 years ago
by
Felix Gerking
Browse files
Options
Downloads
Patches
Plain Diff
package_release: Move metadata generation function to a separate file
parent
40524b7e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
generate_release_metadata.py
+82
-0
82 additions, 0 deletions
generate_release_metadata.py
package_release.py
+7
-86
7 additions, 86 deletions
package_release.py
with
89 additions
and
86 deletions
generate_release_metadata.py
0 → 100755
+
82
−
0
View file @
16669145
#!/usr/bin/env python3
import
json
import
os
from
datetime
import
datetime
def
generate_metadata
(
machine
,
version
,
artifacts_image
,
sdk
,
output_dir
,
outlocal_dir
,
):
"""
Generates a metainfo.json for the release
"""
install_script
=
None
licenses
=
None
image_general
=
None
image_wic
=
None
# Join filepath for metadata
if
output_dir
is
not
None
:
filepath
=
os
.
path
.
join
(
output_dir
,
machine
,
"
metainfo.json
"
)
elif
outlocal_dir
is
not
None
:
filepath
=
os
.
path
.
join
(
outlocal_dir
,
machine
,
"
metainfo.json
"
)
else
:
print
(
"
Error: Filepath is empty
"
)
return
-
1
# Collect metadata and write to metainfo.json
for
artifact
in
artifacts_image
:
if
artifact
==
"
fng-install.sh
"
:
install_script
=
artifact
elif
artifact
==
"
license.manifest
"
:
licenses
=
artifact
elif
artifact
.
endswith
(
machine
+
"
.tar.gz
"
):
image_general
=
artifact
elif
artifact
.
endswith
(
machine
+
"
.wic
"
):
image_wic
=
artifact
metadata
=
dict
()
metadata
[
"
files
"
]
=
[]
metadata
[
"
version
"
]
=
version
metadata
[
"
machine
"
]
=
machine
metadata
[
"
date
"
]
=
datetime
.
today
().
strftime
(
"
%Y-%m-%d
"
)
if
install_script
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Install Script
"
new_file
[
"
path
"
]
=
install_script
metadata
[
"
files
"
].
append
(
new_file
)
if
image_general
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Image
"
new_file
[
"
path
"
]
=
image_general
metadata
[
"
files
"
].
append
(
new_file
)
if
image_wic
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
SD-Card Image (WIC)
"
new_file
[
"
path
"
]
=
image_wic
metadata
[
"
files
"
].
append
(
new_file
)
if
sdk
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
SDK
"
new_file
[
"
path
"
]
=
"
sdk/
"
+
sdk
+
"
.sh
"
metadata
[
"
files
"
].
append
(
new_file
)
if
licenses
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Licenses
"
new_file
[
"
path
"
]
=
licenses
metadata
[
"
files
"
].
append
(
new_file
)
with
open
(
filepath
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
file
:
file
.
write
(
json
.
dumps
(
metadata
))
This diff is collapsed.
Click to expand it.
package_release.py
+
7
−
86
View file @
16669145
...
...
@@ -7,9 +7,8 @@ import sys
import
shutil
import
hashlib
import
tempfile
from
datetime
import
datetime
from
convert_md2html
import
convertmd2html
from
generate_release_metadata
import
generate_metadata
def
md5
(
fname
):
...
...
@@ -76,84 +75,6 @@ def copy_files(files, input_dir, subdir, output_dir, outlocal_dir):
return
md5sums
def
generate_metadata
(
machine
,
version
,
artifacts_image
,
sdk
,
output_dir
,
outlocal_dir
,
):
"""
Generates a metainfo.json for the release
"""
install_script
=
None
licenses
=
None
image_general
=
None
image_wic
=
None
# Join filepath for metadata
if
output_dir
is
not
None
:
filepath
=
os
.
path
.
join
(
output_dir
,
machine
,
"
metainfo.json
"
)
elif
outlocal_dir
is
not
None
:
filepath
=
os
.
path
.
join
(
outlocal_dir
,
machine
,
"
metainfo.json
"
)
else
:
print
(
"
Error: Filepath is empty
"
)
return
-
1
# Collect metadata and write to metainfo.json
for
artifact
in
artifacts_image
:
if
artifact
==
"
fng-install.sh
"
:
install_script
=
artifact
elif
artifact
==
"
license.manifest
"
:
licenses
=
artifact
elif
artifact
.
endswith
(
machine
+
"
.tar.gz
"
):
image_general
=
artifact
elif
artifact
.
endswith
(
machine
+
"
.wic
"
):
image_wic
=
artifact
metadata
=
dict
()
metadata
[
"
files
"
]
=
[]
metadata
[
"
version
"
]
=
version
metadata
[
"
machine
"
]
=
machine
metadata
[
"
date
"
]
=
datetime
.
today
().
strftime
(
"
%Y-%m-%d
"
)
if
install_script
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Install Script
"
new_file
[
"
path
"
]
=
install_script
metadata
[
"
files
"
].
append
(
new_file
)
if
image_general
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Image
"
new_file
[
"
path
"
]
=
image_general
metadata
[
"
files
"
].
append
(
new_file
)
if
image_wic
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
SD-Card Image (WIC)
"
new_file
[
"
path
"
]
=
image_wic
metadata
[
"
files
"
].
append
(
new_file
)
if
sdk
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
SDK
"
new_file
[
"
path
"
]
=
"
sdk/
"
+
sdk
+
"
.sh
"
metadata
[
"
files
"
].
append
(
new_file
)
if
licenses
is
not
None
:
new_file
=
dict
()
new_file
[
"
name
"
]
=
"
Licenses
"
new_file
[
"
path
"
]
=
licenses
metadata
[
"
files
"
].
append
(
new_file
)
with
open
(
filepath
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
file
:
file
.
write
(
json
.
dumps
(
metadata
))
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
...
...
@@ -251,7 +172,8 @@ def main():
convertmd2html
(
f
,
fout
)
html_files
.
append
(
fout
)
copy_files
(
doc_files
+
html_files
,
""
,
""
,
output_dir
,
outlocal_dir
)
doc_md5sums
=
copy_files
(
doc_files
+
html_files
,
""
,
""
,
output_dir
,
outlocal_dir
)
write_md5sums_file
(
doc_md5sums
,
""
,
output_dir
,
outlocal_dir
)
if
args
.
images_dir
is
not
None
:
# Add some additional files to the artifacts
...
...
@@ -285,11 +207,9 @@ def main():
artifacts_all
.
append
(
"
license.manifest
"
)
# Everything copied? Create md5sums file
write_md5sums_file
(
md5sums
,
machine
,
output_dir
,
outlocal_dir
)
write_md5sums_file
(
md5sums
,
machine
,
output_dir
,
outlocal_dir
)
# Generate metadata
# Generate metadata
in case of an image build
if
args
.
sdk_dir
is
None
:
generate_metadata
(
machine
,
...
...
@@ -303,7 +223,8 @@ def main():
# Handle SDK if available
if
args
.
sdk_dir
is
not
None
:
sdkfiles
=
glob
.
glob
(
os
.
path
.
join
(
args
.
sdk_dir
,
sdkname
+
"
*
"
))
copy_files
(
sdkfiles
,
""
,
os
.
path
.
join
(
machine
,
"
sdk
"
),
None
,
outlocal_dir
)
sdk_md5sums
=
copy_files
(
sdkfiles
,
""
,
os
.
path
.
join
(
machine
,
"
sdk
"
),
None
,
outlocal_dir
)
write_md5sums_file
(
sdk_md5sums
,
os
.
path
.
join
(
machine
,
"
sdk
"
),
None
,
outlocal_dir
)
# Store pathes and other stuff in environment variable file
with
open
(
"
package.env
"
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
env_file
:
...
...
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