Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osc-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
mpcdf
obs
osc-plugins
Commits
917e7038
Commit
917e7038
authored
6 years ago
by
Lorenz Huedepohl
Browse files
Options
Downloads
Patches
Plain Diff
New and easier mpcdf_sync_projects command
parent
44fbdf5b
No related branches found
No related tags found
No related merge requests found
Pipeline
#67045
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mpcdf_sync_projects.py
+82
-67
82 additions, 67 deletions
mpcdf_sync_projects.py
with
82 additions
and
67 deletions
mpcdf_sync_projects.py
+
82
−
67
View file @
917e7038
...
@@ -11,89 +11,104 @@ import osc.cmdln
...
@@ -11,89 +11,104 @@ import osc.cmdln
@osc.cmdln.option
(
'
-a
'
,
'
--all
'
,
action
=
"
store_true
"
,
@osc.cmdln.option
(
'
-a
'
,
'
--all
'
,
action
=
"
store_true
"
,
help
=
"
Update all packages in the target repository, not only new ones
"
)
help
=
"
Update all packages in the target repository, not only new ones
"
)
@osc.cmdln.option
(
'
-f
'
,
'
--from
'
,
default
=
"
software
"
,
help
=
"
Source project
"
)
@osc.cmdln.option
(
'
-t
'
,
'
--to
'
,
help
=
"
Just sync with this single destination project
"
)
def
do_mpcdf_sync_projects
(
self
,
subcmd
,
opts
,
*
args
):
def
do_mpcdf_sync_projects
(
self
,
subcmd
,
opts
,
*
args
):
"""
${cmd_name}: Push all packages from a project to another
"""
${cmd_name}: Branch all/missing packages from a project to another and sync their metadata
Branch all missing packages from one project into a target project
Usage:
Usage:
osc mpcdf_push FROM_PROJECT TO_PROJECT
osc mpcdf_sync_projects
osc mpcdf_push FROM_PROJECT PACKAGE TO_PROJECT
osc mpcdf_sync_projects PACKAGE
osc mpcdf_sync_projects --all-packages
Examples:
Examples:
- Update the software:SLE_12_SP3:skylake project
- Sync all new packages from software into all software: sub-projects
#> osc mpcdf_sync_projects software software:SLE_12_SP3:skylake
#> osc mpcdf_sync_projects
- Sync the package foobar_1_2 into all software: sub-projects
#> osc mpcdf_sync_projects foobar_1_2
- Sync all packages from software to software:SLE_12_SP3:skylake
#> osc mpcdf_sync_projects --all-packages --to software:SLE_12_SP3:skylake
${cmd_option_list}
${cmd_option_list}
"""
"""
if
len
(
args
)
<
2
:
package
=
None
raise
osc
.
oscerr
.
WrongArgs
(
"
Not enough arguments
"
)
elif
len
(
args
)
==
2
:
if
len
(
args
)
>
1
:
from_project
,
to_project
=
args
package
=
None
elif
len
(
args
)
==
3
:
from_project
,
package
,
to_project
=
args
else
:
raise
osc
.
oscerr
.
WrongArgs
(
"
Too many arguments
"
)
raise
osc
.
oscerr
.
WrongArgs
(
"
Too many arguments
"
)
elif
len
(
args
)
==
1
and
opts
.
all
:
raise
osc
.
oscerr
.
WrongArgs
(
'
Cannot specify `--all` and PACKAGE
'
)
elif
len
(
args
)
==
1
:
package
,
=
args
api_url
=
self
.
get_api_url
()
api_url
=
self
.
get_api_url
()
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
)))
elif
opts
.
all
:
from_project
=
getattr
(
opts
,
"
from
"
)
if
getattr
(
opts
,
"
from
"
)
else
"
software
"
raise
osc
.
oscerr
.
WrongArgs
(
'
Cannot specify `--all` and PACKAGE
'
)
if
opts
.
to
:
to_projects
=
[
opts
.
to
]
else
:
else
:
from_packages
=
[
package
]
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
))
project_attributes
=
[
"
MPCDF:compiler_modules
"
,
"
MPCDF:cuda_modules
"
,
"
MPCDF:mpi_modules
"
]
for
to_project
in
to_projects
:
package_attributes
=
[
"
MPCDF:enable_repositories
"
]
+
project_attributes
print
(
"
Syncing {0} with {1}
"
.
format
(
to_project
,
from_project
))
for
attribute
in
project_attributes
:
to_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
to_project
)
try
:
mpcdf_common
.
get_attribute
(
api_url
,
to_project
,
None
,
attribute
)
if
package
is
None
:
except
Exception
:
from_packages
=
osc
.
core
.
meta_get_packagelist
(
api_url
,
from_project
)
attr
=
mpcdf_common
.
get_attribute
(
api_url
,
from_project
,
None
,
attribute
)
if
not
opts
.
all
:
print
(
"
Setting attribute
"
,
attribute
)
from_packages
=
list
(
sorted
(
set
(
from_packages
)
-
set
(
to_packages
)))
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
:
else
:
print
(
"
Not branching package {0}, already present in target
"
.
format
(
orig_package
))
from_packages
=
[
package
]
project_attributes
=
[
"
MPCDF:compiler_modules
"
,
"
MPCDF:cuda_modules
"
,
"
MPCDF:mpi_modules
"
]
package_attributes
=
[
"
MPCDF:enable_repositories
"
]
+
project_attributes
for
attribute
in
p
ackage
_attributes
:
for
attribute
in
p
roject
_attributes
:
try
:
try
:
attr
=
mpcdf_common
.
get_attribute
(
api_url
,
from_project
,
orig_package
,
attribute
)
mpcdf_common
.
get_attribute
(
api_url
,
to_project
,
None
,
attribute
)
except
mpcdf_common
.
UnsetAttributeException
:
except
Exception
:
if
mpcdf_common
.
has_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
):
attr
=
mpcdf_common
.
get_attribute
(
api_url
,
from_project
,
None
,
attribute
)
mpcdf_common
.
remove_attribute
(
api_url
,
to_project
,
orig_package
,
attribute
)
print
(
"
Setting attribute
"
,
attribute
)
continue
mpcdf_common
.
set_attribute
(
api_url
,
to_project
,
None
,
attr
)
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
:
for
orig_package
in
from_packages
:
if
not
mpcdf_common
.
mpcdf_enable_repositories
(
api_url
,
to_project
,
orig_package
):
if
orig_package
not
in
to_packages
:
print
(
"
ATTENTION: Not changing unmanaged package {0}
"
.
format
(
orig_package
))
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
))
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