Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCore
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
Container registry
Model registry
Operate
Environments
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
VIPS
VIPSCore
Commits
3902b73c
Commit
3902b73c
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Add license header and comments
parent
56edc9a2
No related branches found
No related tags found
2 merge requests
!26
Renovate-updates deployed to prod
,
!25
All the latest updates from Renovate
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
build_models_xml.py
+30
-4
30 additions, 4 deletions
build_models_xml.py
with
30 additions
and
4 deletions
build_models_xml.py
+
30
−
4
View file @
3902b73c
#!/usr/bin/python3
#!/usr/bin/python3
# Fetch package registry list, build models.xml structure
'''
# with the latest version of each model
Copyright (C) 2023 NIBIO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
@author Tor-Einar Skog <tor-einar.skog@nibio.no>
'''
# Fetches the package registry list from our GitLab,
# filters only models packages,
# figures out which is the newest version of each package,
# creates Maven dependencies XML stubs
# dumps to stdout
# Example usage:
# $ ./build_models_xml.py -s > models.xml
import
sys
import
sys
import
requests
import
requests
...
@@ -11,9 +35,11 @@ if len(sys.argv) == 2 and sys.argv[1] == "-h":
...
@@ -11,9 +35,11 @@ if len(sys.argv) == 2 and sys.argv[1] == "-h":
print
(
"""
usage: build_with_models [-s]
"""
)
print
(
"""
usage: build_with_models [-s]
"""
)
exit
(
0
)
exit
(
0
)
# Use the -s option to fetch only SNAPSHOT versions
snapshot
=
True
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"
-s
"
else
False
snapshot
=
True
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"
-s
"
else
False
url
=
"
https://gitlab.nibio.no/api/v4/projects/401/packages?per_page=100&order_by=version&sort=desc
"
url
=
"
https://gitlab.nibio.no/api/v4/projects/401/packages?per_page=100&order_by=version&sort=desc
"
all_packages
=
[]
all_packages
=
[]
response
=
requests
.
get
(
url
)
response
=
requests
.
get
(
url
)
...
@@ -35,6 +61,7 @@ models = {}
...
@@ -35,6 +61,7 @@ models = {}
model_prefixes
=
[
"
no/nibio/vips/model
"
,
"
fi/luke/vips/model
"
]
model_prefixes
=
[
"
no/nibio/vips/model
"
,
"
fi/luke/vips/model
"
]
# Filter models and store only the most recent version (highest alphanumeric number)
for
package
in
all_packages
:
for
package
in
all_packages
:
for
model_prefix
in
model_prefixes
:
for
model_prefix
in
model_prefixes
:
if
package
[
"
name
"
].
find
(
model_prefix
)
>=
0
and
((
snapshot
and
package
[
"
version
"
].
find
(
"
SNAPSHOT
"
)
>=
0
)
or
(
not
snapshot
and
package
[
"
version
"
].
find
(
"
SNAPSHOT
"
)
<
0
)):
if
package
[
"
name
"
].
find
(
model_prefix
)
>=
0
and
((
snapshot
and
package
[
"
version
"
].
find
(
"
SNAPSHOT
"
)
>=
0
)
or
(
not
snapshot
and
package
[
"
version
"
].
find
(
"
SNAPSHOT
"
)
<
0
)):
...
@@ -53,9 +80,8 @@ for model_name, value in models.items():
...
@@ -53,9 +80,8 @@ for model_name, value in models.items():
ET
.
SubElement
(
dependency
,
"
groupId
"
).
text
=
value
[
"
groupId
"
]
ET
.
SubElement
(
dependency
,
"
groupId
"
).
text
=
value
[
"
groupId
"
]
ET
.
SubElement
(
dependency
,
"
artifactId
"
).
text
=
model_name
ET
.
SubElement
(
dependency
,
"
artifactId
"
).
text
=
model_name
ET
.
SubElement
(
dependency
,
"
version
"
).
text
=
value
[
"
version
"
]
ET
.
SubElement
(
dependency
,
"
version
"
).
text
=
value
[
"
version
"
]
#print("%s %s" % (model_name, value["version"]))
# Dumps the indented XML to stdout
tree
=
ET
.
ElementTree
(
dependencies
)
tree
=
ET
.
ElementTree
(
dependencies
)
ET
.
indent
(
tree
,
space
=
"
\t
"
,
level
=
0
)
ET
.
indent
(
tree
,
space
=
"
\t
"
,
level
=
0
)
# Dumps the indented XML to stdout
ET
.
dump
(
tree
)
ET
.
dump
(
tree
)
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