forked from openSUSE/openSUSE-release-tools
/
osc-staging.py
175 lines (150 loc) · 6.31 KB
/
osc-staging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright (C) 2015 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import os.path
import sys
import warnings
from osc import cmdln
from osc import oscerr
# Expand sys.path to search modules inside the pluging directory
_plugin_dir = os.path.expanduser('~/.osc-plugins')
sys.path.append(_plugin_dir)
from osclib.accept_command import AcceptCommand
from osclib.check_command import CheckCommand
from osclib.cleanup_rings import CleanupRings
from osclib.conf import Config
from osclib.freeze_command import FreezeCommand
from osclib.list_command import ListCommand
from osclib.obslock import OBSLock
from osclib.select_command import SelectCommand
from osclib.stagingapi import StagingAPI
from osclib.unselect_command import UnselectCommand
from osclib.adi_command import AdiCommand
OSC_STAGING_VERSION = '0.0.1'
def _print_version(self):
""" Print version information about this extension. """
print(self.OSC_STAGING_VERSION)
quit(0)
def _full_project_name(self, project):
"""Deduce the full project name."""
if project.startswith(('openSUSE', 'SUSE')):
return project
if 'Factory' in project or 'openSUSE' in project:
return 'openSUSE:%s' % project
if 'SLE' in project:
return 'SUSE:%s' % project
# If we can't guess, raise a Warning
warnings.warn('%s project not recognized.' % project)
return project
@cmdln.option('--move', action='store_true',
help='force the selection to become a move')
@cmdln.option('-f', '--from', dest='from_', metavar='FROMPROJECT',
help='manually specify different source project during request moving')
@cmdln.option('-p', '--project', dest='project', metavar='PROJECT', default='Factory',
help='select a different project instead of openSUSE:Factory')
@cmdln.option('--add', dest='add', metavar='PACKAGE',
help='mark additional packages to be checked by repo checker')
@cmdln.option('-o', '--old', action='store_true',
help='use the old check algorithm')
@cmdln.option('-v', '--version', action='store_true',
help='show version of the plugin')
@cmdln.option('--no-freeze', dest='no_freeze', action='store_true',
help='force the select command ignoring the time from the last freeze')
def do_staging(self, subcmd, opts, *args):
"""${cmd_name}: Commands to work with staging projects
"accept" will accept all requests in
openSUSE:Factory:Staging:<LETTER> (into Factory)
"check" will check if all packages are links without changes
"cleanup_rings" will try to cleanup rings content and print
out problems
"freeze" will freeze the sources of the project's links (not
affecting the packages actually in)
"list" will pick the requests not in rings
"select" will add requests to the project
"unselect" will remove from the project - pushing them back to the backlog
Usage:
osc staging accept LETTER
osc staging check [--old] REPO
osc staging cleanup_rings
osc staging freeze PROJECT...
osc staging list
osc staging select [--no-freeze] [--move [--from PROJECT]] LETTER REQUEST...
osc staging unselect REQUEST...
"""
if opts.version:
self._print_version()
# verify the argument counts match the commands
if len(args) == 0:
raise oscerr.WrongArgs('No command given, see "osc help staging"!')
cmd = args[0]
if cmd in ('accept', 'freeze'):
min_args, max_args = 1, None
elif cmd == 'check':
min_args, max_args = 0, 2
elif cmd == 'select':
min_args, max_args = 1, None
if not opts.add:
min_args = 2
elif cmd == 'unselect':
min_args, max_args = 1, None
elif cmd == 'adi':
min_args, max_args = None, None
elif cmd in ('list', 'cleanup_rings'):
min_args, max_args = 0, 0
else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
if len(args) - 1 < min_args:
raise oscerr.WrongArgs('Too few arguments.')
if max_args is not None and len(args) - 1 > max_args:
raise oscerr.WrongArgs('Too many arguments.')
# Init the OBS access and configuration
opts.project = self._full_project_name(opts.project)
opts.apiurl = self.get_api_url()
opts.verbose = False
Config(opts.project)
with OBSLock(opts.apiurl, opts.project):
api = StagingAPI(opts.apiurl, opts.project)
# call the respective command and parse args by need
if cmd == 'check':
prj = args[1] if len(args) > 1 else None
CheckCommand(api).perform(prj, opts.old)
elif cmd == 'freeze':
for prj in args[1:]:
FreezeCommand(api).perform(api.prj_from_letter(prj))
elif cmd == 'accept':
cmd = AcceptCommand(api)
for prj in args[1:]:
if not cmd.perform(api.prj_from_letter(prj)):
return
cmd.accept_other_new()
cmd.update_factory_version()
if api.item_exists(api.crebuild):
cmd.sync_buildfailures()
elif cmd == 'unselect':
UnselectCommand(api).perform(args[1:])
elif cmd == 'select':
tprj = api.prj_from_letter(args[1])
if opts.add:
api.mark_additional_packages(tprj, [opts.add])
else:
SelectCommand(api, tprj).perform(args[2:], opts.move,
opts.from_, opts.no_freeze)
elif cmd == 'cleanup_rings':
CleanupRings(api).perform()
elif cmd == 'list':
ListCommand(api).perform()
elif cmd == 'adi':
AdiCommand(api).perform(args[1:])