2013-09-04 15:11:27 +02:00
|
|
|
#!/usr/bin/env python
|
2014-01-31 10:29:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-09-04 15:11:27 +02:00
|
|
|
#
|
2014-02-10 10:19:37 +01:00
|
|
|
# (C) 2014 mhrusecky@suse.cz, openSUSE.org
|
|
|
|
# (C) 2014 tchvatal@suse.cz, openSUSE.org
|
2013-09-04 15:11:27 +02:00
|
|
|
# Distribute under GPLv2 or GPLv3
|
|
|
|
|
2014-02-25 14:12:28 +01:00
|
|
|
import os
|
2014-02-12 13:15:49 +01:00
|
|
|
import os.path
|
2014-02-12 18:34:17 +01:00
|
|
|
import re
|
2014-02-12 13:15:49 +01:00
|
|
|
import sys
|
2014-02-12 18:34:17 +01:00
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
|
|
|
|
from osc import cmdln, oscerr
|
|
|
|
from osc.core import delete_project
|
|
|
|
from osc.core import makeurl
|
|
|
|
from osc.core import meta_get_packagelist
|
|
|
|
from osc.core import http_GET
|
|
|
|
from osc.core import http_POST
|
|
|
|
from osc.core import server_diff
|
2014-02-12 13:15:49 +01:00
|
|
|
|
|
|
|
# Expand sys.path to search modules inside the pluging directory
|
|
|
|
_plugin_dir = os.path.expanduser('~/.osc-plugins')
|
|
|
|
sys.path.append(_plugin_dir)
|
2014-02-12 17:58:19 +01:00
|
|
|
from osclib.stagingapi import StagingAPI
|
2014-02-17 13:32:34 +01:00
|
|
|
from osclib.request_finder import RequestFinder
|
2014-02-05 15:34:21 +01:00
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
OSC_STAGING_VERSION = '0.0.1'
|
|
|
|
|
2013-09-04 15:11:27 +02:00
|
|
|
|
|
|
|
def _print_version(self):
|
|
|
|
""" Print version information about this extension. """
|
2014-03-03 17:20:40 +01:00
|
|
|
print(self.OSC_STAGING_VERSION)
|
2013-09-04 15:11:27 +02:00
|
|
|
quit(0)
|
|
|
|
|
2014-02-10 14:05:18 +01:00
|
|
|
|
2014-01-31 10:29:44 +01:00
|
|
|
def _get_changed(opts, project, everything):
|
2013-12-16 15:33:50 +01:00
|
|
|
ret = []
|
|
|
|
# Check for local changes
|
2014-01-31 10:29:44 +01:00
|
|
|
for pkg in meta_get_packagelist(opts.apiurl, project):
|
2013-12-16 15:33:50 +01:00
|
|
|
if len(ret) != 0 and not everything:
|
2013-09-04 15:11:27 +02:00
|
|
|
break
|
2014-01-31 10:29:44 +01:00
|
|
|
f = http_GET(makeurl(opts.apiurl, ['source', project, pkg]))
|
2013-09-04 15:11:27 +02:00
|
|
|
linkinfo = ET.parse(f).getroot().find('linkinfo')
|
|
|
|
if linkinfo is None:
|
2014-03-03 17:20:40 +01:00
|
|
|
ret.append({'pkg': pkg, 'code': 'NOT_LINK',
|
|
|
|
'msg': 'Not a source link'})
|
2013-09-04 15:11:27 +02:00
|
|
|
continue
|
|
|
|
if linkinfo.get('error'):
|
2014-03-03 17:20:40 +01:00
|
|
|
ret.append({'pkg': pkg, 'code': 'BROKEN',
|
|
|
|
'msg': 'Broken source link'})
|
2013-09-04 15:11:27 +02:00
|
|
|
continue
|
|
|
|
t = linkinfo.get('project')
|
|
|
|
p = linkinfo.get('package')
|
|
|
|
r = linkinfo.get('revision')
|
2014-03-03 17:20:40 +01:00
|
|
|
if server_diff(opts.apiurl, t, p, r, project, pkg, None, True):
|
|
|
|
ret.append({
|
|
|
|
'pkg': pkg,
|
|
|
|
'code': 'MODIFIED',
|
|
|
|
'msg': 'Has local modifications',
|
|
|
|
'pprj': t,
|
|
|
|
'ppkg': p
|
|
|
|
})
|
2013-09-04 15:11:27 +02:00
|
|
|
continue
|
2013-12-16 15:33:50 +01:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2013-09-04 15:11:27 +02:00
|
|
|
def _staging_remove(self, project, opts):
|
|
|
|
"""
|
|
|
|
Remove staging project.
|
|
|
|
:param project: staging project to delete
|
|
|
|
:param opts: pointer to options
|
|
|
|
"""
|
2014-01-31 10:29:44 +01:00
|
|
|
chng = _get_changed(opts, project, True)
|
2013-12-16 15:33:50 +01:00
|
|
|
if len(chng) > 0:
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Staging project "%s" is not clean:' % project)
|
2013-12-16 15:33:50 +01:00
|
|
|
print('')
|
|
|
|
for pair in chng:
|
2014-03-03 17:20:40 +01:00
|
|
|
print(' * %s : %s' % (pair['pkg'], pair['msg']))
|
2013-12-16 15:33:50 +01:00
|
|
|
print('')
|
|
|
|
print('Really delete? (N/y)')
|
|
|
|
answer = sys.stdin.readline()
|
|
|
|
if not re.search("^\s*[Yy]", answer):
|
|
|
|
print('Aborting...')
|
|
|
|
exit(1)
|
2014-01-31 10:29:44 +01:00
|
|
|
delete_project(opts.apiurl, project, force=True, msg=None)
|
2013-09-04 15:11:27 +02:00
|
|
|
print("Deleted.")
|
|
|
|
return
|
|
|
|
|
2014-02-12 18:34:17 +01:00
|
|
|
|
2013-09-04 15:11:27 +02:00
|
|
|
def _staging_submit_devel(self, project, opts):
|
|
|
|
"""
|
2014-03-03 17:20:40 +01:00
|
|
|
Generate new review requests for devel-projects based on our
|
|
|
|
staging changes.
|
2013-09-04 15:11:27 +02:00
|
|
|
:param project: staging project to submit into devel projects
|
|
|
|
"""
|
2014-01-31 10:29:44 +01:00
|
|
|
chng = _get_changed(opts, project, True)
|
2013-12-17 13:45:59 +01:00
|
|
|
msg = "Fixes from staging project %s" % project
|
2014-01-06 10:58:30 +01:00
|
|
|
if opts.message is not None:
|
2013-12-17 13:45:59 +01:00
|
|
|
msg = opts.message
|
|
|
|
if len(chng) > 0:
|
|
|
|
for pair in chng:
|
|
|
|
if pair['code'] != 'MODIFIED':
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Error: Package "%s": %s' % (pair['pkg'], pair['msg']))
|
2013-12-17 13:45:59 +01:00
|
|
|
else:
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Sending changes back %s/%s -> %s/%s' % (project, pair['pkg'], pair['pprj'], pair['ppkg']))
|
|
|
|
action_xml = '<request>'
|
2013-12-17 13:45:59 +01:00
|
|
|
action_xml += ' <action type="submit"> <source project="%s" package="%s" /> <target project="%s" package="%s" />' % (project, pair['pkg'], pair['pprj'], pair['ppkg'])
|
|
|
|
action_xml += ' </action>'
|
|
|
|
action_xml += ' <state name="new"/> <description>%s</description>' % msg
|
|
|
|
action_xml += '</request>'
|
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
u = makeurl(opts.apiurl, ['request'],
|
|
|
|
query='cmd=create&addrevision=1')
|
2013-12-17 13:45:59 +01:00
|
|
|
f = http_POST(u, data=action_xml)
|
|
|
|
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
print("Created request %s" % (root.get('id')))
|
|
|
|
else:
|
2014-03-03 17:20:40 +01:00
|
|
|
print('No changes to submit')
|
2013-09-04 15:11:27 +02:00
|
|
|
return
|
|
|
|
|
2014-02-12 18:34:17 +01:00
|
|
|
|
2014-02-11 11:45:53 +01:00
|
|
|
@cmdln.option('-e', '--everything', action='store_true',
|
2013-09-04 15:11:27 +02:00
|
|
|
help='during check do not stop on first first issue and show them all')
|
2013-12-13 13:48:45 +01:00
|
|
|
@cmdln.option('-p', '--parent', metavar='TARGETPROJECT',
|
|
|
|
help='manually specify different parent project during creation of staging')
|
2013-12-17 13:45:59 +01:00
|
|
|
@cmdln.option('-m', '--message', metavar='TEXT',
|
|
|
|
help='manually specify different parent project during creation of staging')
|
2014-03-03 17:20:40 +01:00
|
|
|
@cmdln.option('-n', '--move', action='store_true',
|
|
|
|
help='force the selection to become a move')
|
2014-02-25 14:12:28 +01:00
|
|
|
@cmdln.option('-f', '--from', dest='from_', metavar='FROMPROJECT',
|
|
|
|
help='manually specify different source project during request moving')
|
2013-09-04 15:11:27 +02:00
|
|
|
@cmdln.option('-v', '--version', action='store_true',
|
|
|
|
help='show version of the plugin')
|
|
|
|
def do_staging(self, subcmd, opts, *args):
|
|
|
|
"""${cmd_name}: Commands to work with staging projects
|
|
|
|
|
|
|
|
"check" will check if all packages are links without changes
|
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
"remove" (or "r") will delete the staging project into submit
|
|
|
|
requests for openSUSE:Factory
|
2013-09-04 15:11:27 +02:00
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
"submit-devel" (or "s") will create review requests for changed
|
|
|
|
packages in staging project into their respective devel
|
|
|
|
projects to obtain approval from maitnainers for pushing the
|
2013-09-04 15:11:27 +02:00
|
|
|
changes to openSUSE:Factory
|
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
"freeze" will freeze the sources of the project's links (not
|
|
|
|
affecting the packages actually in)
|
2014-02-10 10:19:37 +01:00
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
"accept" will accept all requests in
|
|
|
|
openSUSE:Factory:Staging:<LETTER> (into Factory)
|
2014-01-31 10:29:44 +01:00
|
|
|
|
|
|
|
"list" will pick the requests not in rings
|
|
|
|
|
2014-02-12 13:36:41 +01:00
|
|
|
"select" will add requests to the project
|
2014-02-18 13:30:39 +01:00
|
|
|
"unselect" will remove them project - pushing them back to the backlog
|
2014-02-10 10:20:16 +01:00
|
|
|
|
2013-09-04 15:11:27 +02:00
|
|
|
Usage:
|
|
|
|
osc staging check [--everything] REPO
|
|
|
|
osc staging remove REPO
|
2014-01-31 10:29:44 +01:00
|
|
|
osc staging submit-devel [-m message] REPO
|
|
|
|
osc staging freeze PROJECT
|
|
|
|
osc staging list
|
2014-03-03 17:20:40 +01:00
|
|
|
osc staging select [--move [-from PROJECT]] LETTER REQUEST...
|
2014-02-18 13:30:39 +01:00
|
|
|
osc staging unselect LETTER REQUEST...
|
2014-01-31 10:29:44 +01:00
|
|
|
osc staging accept LETTER
|
2014-02-01 21:00:55 +01:00
|
|
|
osc staging cleanup_rings
|
2013-09-04 15:11:27 +02:00
|
|
|
"""
|
|
|
|
if opts.version:
|
|
|
|
self._print_version()
|
|
|
|
|
|
|
|
# verify the argument counts match the commands
|
2014-02-10 19:59:45 +01:00
|
|
|
if len(args) == 0:
|
|
|
|
raise oscerr.WrongArgs('No command given, see "osc help staging"!')
|
2013-09-04 15:11:27 +02:00
|
|
|
cmd = args[0]
|
2014-02-01 21:00:55 +01:00
|
|
|
if cmd in ['submit-devel', 's', 'remove', 'r', 'accept', 'freeze']:
|
2013-09-04 15:11:27 +02:00
|
|
|
min_args, max_args = 1, 1
|
2014-03-03 17:20:40 +01:00
|
|
|
elif cmd == 'check':
|
2014-02-17 15:13:27 +01:00
|
|
|
min_args, max_args = 0, 2
|
2014-02-18 13:30:39 +01:00
|
|
|
elif cmd in ['select', 'unselect']:
|
2014-02-11 15:23:34 +01:00
|
|
|
min_args, max_args = 2, None
|
2014-02-01 21:00:55 +01:00
|
|
|
elif cmd in ['list', 'cleanup_rings']:
|
2014-01-31 10:29:44 +01:00
|
|
|
min_args, max_args = 0, 0
|
2013-09-04 15:11:27 +02:00
|
|
|
else:
|
2014-03-03 17:20:40 +01:00
|
|
|
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
|
2013-09-04 15:11:27 +02:00
|
|
|
if len(args) - 1 < min_args:
|
|
|
|
raise oscerr.WrongArgs('Too few arguments.')
|
|
|
|
if not max_args is None and len(args) - 1 > max_args:
|
|
|
|
raise oscerr.WrongArgs('Too many arguments.')
|
|
|
|
|
|
|
|
# init the obs access
|
2014-01-31 10:29:44 +01:00
|
|
|
opts.apiurl = self.get_api_url()
|
|
|
|
opts.verbose = False
|
|
|
|
|
2014-02-12 17:58:19 +01:00
|
|
|
api = StagingAPI(opts.apiurl)
|
2014-01-31 10:29:44 +01:00
|
|
|
|
2013-09-04 15:11:27 +02:00
|
|
|
# call the respective command and parse args by need
|
2014-02-17 13:32:34 +01:00
|
|
|
if cmd in ['check']:
|
2014-02-27 09:59:19 +01:00
|
|
|
# FIXME: de-duplicate and use function when cleaning up this file
|
2014-02-17 15:13:27 +01:00
|
|
|
if len(args) > 1:
|
2014-02-27 09:59:19 +01:00
|
|
|
prj = api.prj_from_letter(args[1])
|
2014-03-03 17:20:40 +01:00
|
|
|
state = api.check_project_status(prj, True)
|
2014-02-27 09:59:19 +01:00
|
|
|
|
|
|
|
# If the state is green we do nothing
|
|
|
|
if not state:
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Skipping empty staging project: {}'.format(prj))
|
2014-02-27 09:59:19 +01:00
|
|
|
print('')
|
|
|
|
return True
|
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Checking staging project: {}'.format(prj))
|
2014-02-27 09:59:19 +01:00
|
|
|
if type(state) is list:
|
|
|
|
print(' -- Project still neeeds attention')
|
|
|
|
for i in state:
|
|
|
|
print(i)
|
|
|
|
else:
|
|
|
|
print(' ++ Acceptable staging project')
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2014-02-17 15:13:27 +01:00
|
|
|
for prj in api.get_staging_projects():
|
2014-02-26 14:51:01 +01:00
|
|
|
state = api.check_project_status(prj)
|
|
|
|
|
|
|
|
# If the state is green we do nothing
|
|
|
|
if not state:
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Skipping empty staging project: {}'.format(prj))
|
2014-02-26 14:51:01 +01:00
|
|
|
print('')
|
|
|
|
continue
|
|
|
|
|
2014-03-03 17:20:40 +01:00
|
|
|
print('Checking staging project: {}'.format(prj))
|
2014-02-26 14:51:01 +01:00
|
|
|
if type(state) is list:
|
|
|
|
print(' -- Project still neeeds attention')
|
|
|
|
for i in state:
|
|
|
|
print(i)
|
|
|
|
else:
|
|
|
|
print(' ++ Acceptable staging project')
|
|
|
|
print('')
|
2014-02-17 15:13:27 +01:00
|
|
|
return True
|
2013-09-04 15:11:27 +02:00
|
|
|
elif cmd in ['remove', 'r']:
|
|
|
|
project = args[1]
|
|
|
|
self._staging_remove(project, opts)
|
|
|
|
elif cmd in ['submit-devel', 's']:
|
|
|
|
project = args[1]
|
|
|
|
self._staging_submit_devel(project, opts)
|
2014-01-31 10:29:44 +01:00
|
|
|
elif cmd in ['freeze']:
|
2014-02-15 16:39:11 +01:00
|
|
|
import osclib.freeze_command
|
2014-02-24 11:49:46 +01:00
|
|
|
for prj in args[1:]:
|
2014-03-03 17:20:40 +01:00
|
|
|
osclib.freeze_command.FreezeCommand(api).perform(api. prj_from_letter(prj))
|
2014-02-19 11:48:16 +01:00
|
|
|
elif cmd in ['accept']:
|
|
|
|
import osclib.accept_command
|
2014-03-03 17:20:40 +01:00
|
|
|
osclib.accept_command.AcceptCommand(api).perform(api. prj_from_letter(args[1]))
|
2014-02-18 13:30:39 +01:00
|
|
|
elif cmd in ['select', 'unselect']:
|
2014-03-03 17:20:40 +01:00
|
|
|
tprj = api.prj_from_letter(args[1])
|
|
|
|
if not api.prj_frozen_enough(tprj):
|
|
|
|
print('Freeze the prj first')
|
2014-03-03 17:18:18 +01:00
|
|
|
return False
|
2014-03-03 17:20:40 +01:00
|
|
|
for rq, rq_prj in RequestFinder.find_sr(args[2:], opts.apiurl).items():
|
|
|
|
if cmd == 'select' and 'staging' not in rq_prj:
|
|
|
|
# Normal 'select' command
|
|
|
|
api.rq_to_prj(rq, tprj)
|
|
|
|
elif cmd == 'select' and 'staging' in rq_prj and opts.move:
|
|
|
|
# 'select' command becomes a 'move'
|
|
|
|
fprj = None
|
|
|
|
if opts.from_:
|
|
|
|
fprj = api.prj_from_letter(opts.from_)
|
|
|
|
else:
|
|
|
|
fprj = rq_prj['staging']
|
|
|
|
print('Moving "{}" from "{}" to "{}"'.format(rq, fprj, tprj))
|
|
|
|
api.move_between_project(fprj, rq, tprj)
|
|
|
|
elif cmd == 'select' and 'staging' in rq_prj and not opts.move:
|
|
|
|
# Previously selected, but not explicit move
|
|
|
|
msg = 'Request "{}" is actually in "{}".\n'
|
|
|
|
msg = msg.format(rq, rq_prj['staging'])
|
|
|
|
msg += 'Use --move (-n) modifier to move the request from "{}" to "{}"'
|
|
|
|
msg = msg.format(rq_prj['staging'], tprj)
|
|
|
|
print(msg)
|
|
|
|
elif cmd == 'unselect':
|
|
|
|
api.rm_from_prj(tprj, request_id=rq)
|
2014-02-20 14:22:33 +01:00
|
|
|
api.add_review(rq, by_group='factory-staging',
|
2014-02-20 11:43:28 +01:00
|
|
|
msg='Please recheck')
|
2014-03-03 17:20:40 +01:00
|
|
|
else:
|
|
|
|
raise oscerr.WrongArgs('Arguments for select are not correct.')
|
2014-02-01 21:00:55 +01:00
|
|
|
elif cmd in ['cleanup_rings']:
|
2014-02-12 15:34:57 +01:00
|
|
|
import osclib.cleanup_rings
|
|
|
|
osclib.cleanup_rings.CleanupRings(opts.apiurl).perform()
|
2014-02-18 14:05:57 +01:00
|
|
|
elif cmd in ['list']:
|
|
|
|
import osclib.list_command
|
|
|
|
osclib.list_command.ListCommand(api).perform()
|