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
On Thursday, 7th July from 1 to 3 pm there will be a maintenance with a short downtime of GitLab.
Open sidebar
mpcdf
obs
osc-plugins
Commits
3656e9af
Commit
3656e9af
authored
Nov 22, 2018
by
Lorenz Huedepohl
Browse files
Refactor mpcdf_sync_projects into common function
parent
93a86232
Changes
2
Hide whitespace changes
Inline
Side-by-side
mpcdf_common.py
View file @
3656e9af
...
...
@@ -447,3 +447,72 @@ def set_as_branch(api_url, my_project, my_package, main_project, main_package):
rev
=
pac
.
latest_rev
(
expand
=
True
)
pac
.
update
(
rev
)
return
True
def
sync_projects
(
api_url
,
package
=
None
,
from_project
=
"software"
,
to_projects
=
None
,
redo_all
=
False
):
if
package
is
not
None
and
redo_all
:
raise
osc
.
oscerr
.
WrongArgs
(
'Cannot specify `redo_all` and package'
)
if
to_projects
is
None
:
to_projects
=
filter
(
lambda
s
:
s
.
startswith
(
"software:"
)
and
not
(
s
==
"software:dist"
or
s
==
"software:images"
),
osc
.
core
.
meta_get_project_list
(
api_url
))
for
to_project
in
to_projects
:
print
(
"Syncing {0} with {1}"
.
format
(
to_project
,
from_project
))
to_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
to_project
)
if
package
is
None
:
from_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
from_project
)
if
not
redo_all
:
from_packages
=
list
(
sorted
(
set
(
from_packages
)
-
set
(
to_packages
)))
else
:
from_packages
=
[
package
]
project_attributes
=
[
"MPCDF:compiler_modules"
,
"MPCDF:cuda_modules"
,
"MPCDF:mpi_modules"
]
package_attributes
=
[
"MPCDF:enable_repositories"
]
+
project_attributes
for
attribute
in
project_attributes
:
try
:
get_attribute
(
api_url
,
to_project
,
None
,
attribute
)
except
Exception
:
attr
=
get_attribute
(
api_url
,
from_project
,
None
,
attribute
)
print
(
"Setting attribute"
,
attribute
)
set_attribute
(
api_url
,
to_project
,
None
,
attr
)
for
orig_package
in
from_packages
:
if
orig_package
not
in
to_packages
:
filelist
=
osc
.
core
.
meta_get_filelist
(
api_url
,
from_project
,
orig_package
)
if
"_link"
in
filelist
:
print
(
"Not branching package {0}, is a link"
.
format
(
orig_package
))
else
:
print
(
"Branching package {0}"
.
format
(
orig_package
))
exists
,
targetprj
,
targetpkg
,
srcprj
,
srcpkg
=
\
osc
.
core
.
branch_pkg
(
api_url
,
from_project
,
orig_package
,
target_project
=
to_project
,
nodevelproject
=
True
)
else
:
print
(
"Not branching package {0}, already present in target"
.
format
(
orig_package
))
for
attribute
in
package_attributes
:
try
:
attr
=
get_attribute
(
api_url
,
from_project
,
orig_package
,
attribute
)
except
UnsetAttributeException
:
if
has_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
):
remove_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
)
continue
set_attribute
(
api_url
,
to_project
,
orig_package
,
attr
)
if
package
is
None
and
redo_all
:
# Check if distribution is already set in to_project
to_prj_meta
=
project_meta
(
api_url
,
to_project
)
sys_repo
=
to_prj_meta
.
find
(
'./repository[@name="System"]'
)
if
sys_repo
is
None
:
distribution
=
project_meta
(
api_url
,
from_project
).
find
(
'./repository[@name="System"]/path[@project="distributions"]'
).
get
(
"repository"
)
else
:
distribution
=
sys_repo
.
find
(
'./path[@project="distributions"]'
).
get
(
"repository"
)
print
(
"Creating repository configuration"
)
mpcdf_setup_repositories
(
api_url
,
to_project
,
distribution
)
else
:
for
orig_package
in
from_packages
:
if
not
mpcdf_enable_repositories
(
api_url
,
to_project
,
orig_package
):
print
(
"ATTENTION: Not changing unmanaged package {0}"
.
format
(
orig_package
))
mpcdf_sync_projects.py
View file @
3656e9af
...
...
@@ -51,64 +51,6 @@ def do_mpcdf_sync_projects(self, subcmd, opts, *args):
if
opts
.
to
:
to_projects
=
[
opts
.
to
]
else
:
to_projects
=
filter
(
lambda
s
:
s
.
startswith
(
"software:"
)
and
not
(
s
==
"software:dist"
or
s
==
"software:images"
),
osc
.
core
.
meta_get_project_list
(
api_url
))
to_projects
=
None
for
to_project
in
to_projects
:
print
(
"Syncing {0} with {1}"
.
format
(
to_project
,
from_project
))
to_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
to_project
)
if
package
is
None
:
from_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
from_project
)
if
not
opts
.
all
:
from_packages
=
list
(
sorted
(
set
(
from_packages
)
-
set
(
to_packages
)))
else
:
from_packages
=
[
package
]
project_attributes
=
[
"MPCDF:compiler_modules"
,
"MPCDF:cuda_modules"
,
"MPCDF:mpi_modules"
]
package_attributes
=
[
"MPCDF:enable_repositories"
]
+
project_attributes
for
attribute
in
project_attributes
:
try
:
mpcdf_common
.
get_attribute
(
api_url
,
to_project
,
None
,
attribute
)
except
Exception
:
attr
=
mpcdf_common
.
get_attribute
(
api_url
,
from_project
,
None
,
attribute
)
print
(
"Setting attribute"
,
attribute
)
mpcdf_common
.
set_attribute
(
api_url
,
to_project
,
None
,
attr
)
for
orig_package
in
from_packages
:
if
orig_package
not
in
to_packages
:
filelist
=
osc
.
core
.
meta_get_filelist
(
api_url
,
from_project
,
orig_package
)
if
"_link"
in
filelist
:
print
(
"Not branching package {0}, is a link"
.
format
(
orig_package
))
else
:
print
(
"Branching package {0}"
.
format
(
orig_package
))
exists
,
targetprj
,
targetpkg
,
srcprj
,
srcpkg
=
\
osc
.
core
.
branch_pkg
(
api_url
,
from_project
,
orig_package
,
target_project
=
to_project
,
nodevelproject
=
True
)
else
:
print
(
"Not branching package {0}, already present in target"
.
format
(
orig_package
))
for
attribute
in
package_attributes
:
try
:
attr
=
mpcdf_common
.
get_attribute
(
api_url
,
from_project
,
orig_package
,
attribute
)
except
mpcdf_common
.
UnsetAttributeException
:
if
mpcdf_common
.
has_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
):
mpcdf_common
.
remove_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
)
continue
mpcdf_common
.
set_attribute
(
api_url
,
to_project
,
orig_package
,
attr
)
if
package
is
None
and
opts
.
all
:
# Check if distribution is already set in to_project
to_prj_meta
=
mpcdf_common
.
project_meta
(
api_url
,
to_project
)
sys_repo
=
to_prj_meta
.
find
(
'./repository[@name="System"]'
)
if
sys_repo
is
None
:
distribution
=
mpcdf_common
.
project_meta
(
api_url
,
from_project
).
find
(
'./repository[@name="System"]/path[@project="distributions"]'
).
get
(
"repository"
)
else
:
distribution
=
sys_repo
.
find
(
'./path[@project="distributions"]'
).
get
(
"repository"
)
print
(
"Creating repository configuration"
)
mpcdf_common
.
mpcdf_setup_repositories
(
api_url
,
to_project
,
distribution
)
else
:
for
orig_package
in
from_packages
:
if
not
mpcdf_common
.
mpcdf_enable_repositories
(
api_url
,
to_project
,
orig_package
):
print
(
"ATTENTION: Not changing unmanaged package {0}"
.
format
(
orig_package
))
mpcdf_common
.
sync_projects
(
api_url
,
package
,
from_project
=
from_project
,
to_projects
=
to_projects
,
redo_all
=
opts
.
all
)
Write
Preview
Markdown
is supported
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