2014-03-04 15:30:49 +01:00
|
|
|
from osc import oscerr
|
2014-03-04 09:39:14 +01:00
|
|
|
from osclib.request_finder import RequestFinder
|
|
|
|
|
2014-03-04 15:30:49 +01:00
|
|
|
|
|
|
|
class SelectCommand(object):
|
|
|
|
|
2014-03-04 09:39:14 +01:00
|
|
|
def __init__(self, api):
|
|
|
|
self.api = api
|
|
|
|
|
2014-03-04 15:30:49 +01:00
|
|
|
def select_request(self, rq, rq_prj, move, from_):
|
2014-03-04 09:39:14 +01:00
|
|
|
if 'staging' not in rq_prj:
|
|
|
|
# Normal 'select' command
|
|
|
|
self.api.rq_to_prj(rq, self.tprj)
|
2014-03-04 15:30:49 +01:00
|
|
|
elif 'staging' in rq_prj and move:
|
2014-03-04 09:39:14 +01:00
|
|
|
# 'select' command becomes a 'move'
|
|
|
|
fprj = None
|
2014-03-04 15:30:49 +01:00
|
|
|
if from_:
|
|
|
|
fprj = self.api.prj_from_letter(from_)
|
2014-03-04 09:39:14 +01:00
|
|
|
else:
|
|
|
|
fprj = rq_prj['staging']
|
|
|
|
print('Moving "{}" from "{}" to "{}"'.format(rq, fprj, self.tprj))
|
|
|
|
self.api.move_between_project(fprj, rq, self.tprj)
|
2014-03-04 15:30:49 +01:00
|
|
|
elif 'staging' in rq_prj and not move:
|
2014-03-04 09:39:14 +01:00
|
|
|
# Previously selected, but not explicit move
|
|
|
|
msg = 'Request {} is actually in "{}".\n'
|
|
|
|
msg = msg.format(rq, rq_prj['staging'])
|
|
|
|
msg += 'Use --move modifier to move the request from "{}" to "{}"'
|
|
|
|
msg = msg.format(rq_prj['staging'], self.tprj)
|
|
|
|
print(msg)
|
|
|
|
else:
|
|
|
|
raise oscerr.WrongArgs('Arguments for select are not correct.')
|
|
|
|
|
2014-03-04 15:30:49 +01:00
|
|
|
def perform(self, tprj, requests, move=False, from_=None):
|
2014-03-04 09:39:14 +01:00
|
|
|
if not self.api.prj_frozen_enough(tprj):
|
|
|
|
print('Freeze the prj first')
|
|
|
|
return False
|
|
|
|
self.tprj = tprj
|
|
|
|
|
|
|
|
for rq, rq_prj in RequestFinder.find_sr(requests, self.api.apiurl).items():
|
2014-03-04 15:30:49 +01:00
|
|
|
self.select_request(rq, rq_prj, move, from_)
|