Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcdf
obs
osc-plugins
Commits
ce288a7f
Commit
ce288a7f
authored
May 02, 2020
by
Lorenz Hüdepohl
Browse files
Add '--dry-run' for mpcdf_setup_cluster_project
parent
6f950c36
Changes
1
Hide whitespace changes
Inline
Side-by-side
mpcdf_setup_clusters_project.py
View file @
ce288a7f
...
...
@@ -4,10 +4,13 @@ import osc
import
osc.conf
import
osc.core
import
osc.cmdln
from
xml.etree
import
ElementTree
import
mpcdf_common
@
osc
.
cmdln
.
option
(
'-n'
,
'--dry-run'
,
action
=
"store_true"
,
help
=
"Do not actually run anything but output the resulting prj/prjconf configuration"
)
@
osc
.
cmdln
.
alias
(
"mpcdf_setup_clusters"
)
def
do_mpcdf_setup_cluster_project
(
self
,
subcmd
,
opts
,
*
args
):
"""${cmd_name}: Set-up the 'clusters' project
...
...
@@ -26,12 +29,13 @@ def do_mpcdf_setup_cluster_project(self, subcmd, opts, *args):
api_url
=
self
.
get_api_url
()
projects
=
[
p
for
p
in
osc
.
core
.
meta_get_project_list
(
api_url
)
if
p
.
startswith
(
"software:"
)]
software_meta
=
mpcdf_common
.
project_meta
(
api_url
,
"software"
)
subprojects
=
[
p
for
p
in
osc
.
core
.
meta_get_project_list
(
api_url
)
if
p
.
startswith
(
"software:"
)]
macros
=
{}
for
project
in
projects
:
target
=
project
[
len
(
"software:"
):].
replace
(
":"
,
"-"
)
for
sub
project
in
sub
projects
:
target
=
sub
project
[
len
(
"software:"
):].
replace
(
":"
,
"-"
)
if
target
in
macros
:
raise
Exception
(
"Internal error"
)
...
...
@@ -39,10 +43,10 @@ def do_mpcdf_setup_cluster_project(self, subcmd, opts, *args):
macros
[
target
]
=
[]
for
attribute
in
mpcdf_common
.
config_attributes
+
mpcdf_common
.
default_attributes
:
_
,
name
=
attribute
.
split
(
":"
)
values
=
mpcdf_common
.
overloaded_project_attribute
(
api_url
,
project
,
attribute
)
values
=
mpcdf_common
.
overloaded_project_attribute
(
api_url
,
sub
project
,
attribute
)
macros
[
target
].
append
(
"%available_{0} {1}"
.
format
(
name
,
","
.
join
(
sorted
(
values
))))
all_compilers
=
mpcdf_common
.
overloaded_project_attribute
(
api_url
,
project
,
"MPCDF:compiler_modules"
)
all_compilers
=
mpcdf_common
.
overloaded_project_attribute
(
api_url
,
sub
project
,
"MPCDF:compiler_modules"
)
latest_intel
=
sorted
((
c
for
c
in
all_compilers
if
c
.
startswith
(
"intel"
)),
key
=
mpcdf_common
.
package_sort_key
)[
-
1
]
latest_gcc
=
sorted
((
c
for
c
in
all_compilers
if
c
.
startswith
(
"gcc"
)),
key
=
mpcdf_common
.
package_sort_key
)[
-
1
]
macros
[
target
].
append
(
"%latest_intel "
+
latest_intel
)
...
...
@@ -63,22 +67,51 @@ def do_mpcdf_setup_cluster_project(self, subcmd, opts, *args):
prjconf_tail
=
""
.
join
(
prjconf
[
end
+
1
:])
prjconf
=
[
start_marker
]
distributions
=
osc
.
core
.
get_repositories_of_project
(
api_url
,
"software"
)
for
repo
in
osc
.
core
.
get_repositories_of_project
(
api_url
,
"clusters"
):
for
dist
in
distributions
:
if
repo
.
startswith
(
dist
):
break
dist
=
None
if
dist
is
None
:
raise
Exception
(
"Internal error"
)
prjconf
.
append
(
'%if "%_repository" == "{0}"'
.
format
(
repo
))
prj_meta
=
mpcdf_common
.
project_meta
(
api_url
,
"clusters"
)
for
oldrepo
in
prj_meta
.
findall
(
"./repository"
):
prj_meta
.
remove
(
oldrepo
)
for
subproject
in
subprojects
:
_
,
distribution
,
microarchitecture
=
subproject
.
split
(
":"
)
reponame
=
"{0}-{1}"
.
format
(
distribution
,
microarchitecture
)
prjconf
.
append
(
'%if "%_repository" == "{0}"'
.
format
(
reponame
))
prjconf
.
append
(
"Macros:"
)
prjconf
.
extend
(
macros
[
repo
])
prjconf
.
append
(
"%distribution {0}"
.
format
(
dist
))
prjconf
.
extend
(
macros
[
repo
name
])
prjconf
.
append
(
"%distribution {0}"
.
format
(
dist
ribution
))
prjconf
.
append
(
":Macros"
)
prjconf
.
append
(
"%endif"
)
prjconf
.
append
(
""
)
r
=
ElementTree
.
SubElement
(
prj_meta
,
"repository"
)
r
.
set
(
"name"
,
reponame
)
r
.
text
=
"
\n
"
for
repo
in
osc
.
core
.
get_repositories_of_project
(
api_url
,
subproject
):
p
=
ElementTree
.
SubElement
(
r
,
"path"
)
p
.
set
(
"project"
,
subproject
)
p
.
set
(
"repository"
,
repo
)
p
.
tail
=
"
\n
"
for
arch
in
software_meta
.
findall
(
'./repository[@name="{0}"]/arch'
.
format
(
distribution
)):
a
=
ElementTree
.
SubElement
(
r
,
"arch"
)
a
.
text
=
arch
.
text
a
.
tail
=
"
\n
"
a
.
tail
=
"
\n
"
r
.
tail
=
"
\n
"
r
.
tail
=
"
\n
"
prjconf
.
append
(
end_marker
)
prjconf
=
prjconf_head
+
"
\n
"
.
join
(
prjconf
)
+
prjconf_tail
osc
.
core
.
edit_meta
(
"prjconf"
,
"clusters"
,
data
=
prjconf
,
apiurl
=
api_url
)
new_prj_meta
=
ElementTree
.
tostring
(
prj_meta
,
encoding
=
osc
.
core
.
ET_ENCODING
)
if
opts
.
dry_run
:
print
(
"osc meta prjconf {0} -F - <<EOF
\n
{1}
\n
EOF
\n
"
.
format
(
"clusters"
,
prjconf
))
print
(
"osc meta prj {0} -F - <<EOF
\n
{1}
\n
EOF
\n
"
.
format
(
"clusters"
,
new_prj_meta
))
else
:
print
(
"Updating prjconf meta"
)
osc
.
core
.
edit_meta
(
"prjconf"
,
"clusters"
,
data
=
prjconf
,
apiurl
=
api_url
)
# Update repositories
print
(
"Updating prj meta"
)
osc
.
core
.
edit_meta
(
"prj"
,
"clusters"
,
data
=
new_prj_meta
,
force
=
True
,
apiurl
=
api_url
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment