mirror of
https://abf.rosa.ru/djam/abf-console-client-src.git
synced 2025-02-23 18:02:50 +00:00
Fix project aliasing, ad 'destroy' command
This commit is contained in:
parent
37a9c1ba14
commit
cd8e668966
3 changed files with 97 additions and 11 deletions
65
abf.py
65
abf.py
|
@ -130,6 +130,7 @@ def parse_command_line():
|
|||
parser_get.add_argument('project', action='store', help=_('project name. ([group/]project). If no group specified, '
|
||||
'it\'s assumed to be your default group.'))
|
||||
parser_get.add_argument('-b', '--branch', action='store', help=_('branch to checkout'))
|
||||
parser_get.add_argument('--skip-proj-cfg-update', action='store_true', help=_('Do not update cache with information about project builds.'))
|
||||
parser_get.set_defaults(func=get)
|
||||
|
||||
# put
|
||||
|
@ -314,6 +315,12 @@ def parse_command_line():
|
|||
parser_pull.add_argument('target_project', action='store', nargs='?', help=_('target project group and name (group/project)'))
|
||||
parser_pull.set_defaults(func=fork_project)
|
||||
|
||||
# alias project
|
||||
parser_pull = subparsers.add_parser('alias', help=_('Create alias of existing project'))
|
||||
parser_pull.add_argument('source_project', action='store', help=_('project to fork (group/project)'))
|
||||
parser_pull.add_argument('target_project', action='store', nargs='?', help=_('target project group and name (group/project)'))
|
||||
parser_pull.set_defaults(func=alias_project)
|
||||
|
||||
# create project from SRPM
|
||||
parser_pull = subparsers.add_parser('create', help=_('Create project from SRPM'))
|
||||
parser_pull.add_argument('srpm', action='store', help=_('srpm file'))
|
||||
|
@ -322,6 +329,12 @@ def parse_command_line():
|
|||
parser_pull.add_argument('--no-def-branch', action='store_true', help=_('Do not automatically create branch set as default in user config (if it is set to smth different from "master").'))
|
||||
parser_pull.set_defaults(func=create)
|
||||
|
||||
# destroy project
|
||||
parser_destroy = subparsers.add_parser('destroy', help=_('Destroy project'))
|
||||
parser_destroy.add_argument('project', action='store', help=_('project name. ([group/]project). If no group specified, '
|
||||
'it\'s assumed to be your default group.'))
|
||||
parser_destroy.set_defaults(func=destroy)
|
||||
|
||||
# add project to repository
|
||||
parser_pull = subparsers.add_parser('add', help=_('Add project to specified repository'))
|
||||
parser_pull.add_argument('repository', action='store', help=_('target repository ([platform/]repository)'))
|
||||
|
@ -734,6 +747,13 @@ def get():
|
|||
if 'projects_cfg' in globals():
|
||||
projects_cfg[proj]['location'] = os.path.join(os.getcwd(), project_name)
|
||||
|
||||
def destroy():
|
||||
log.debug(_('DESTROY started'))
|
||||
|
||||
proj = get_project(models, must_exist=True, name=command_line.project)
|
||||
|
||||
ProjectCreator.destroy_project(models, proj.id)
|
||||
|
||||
def put():
|
||||
log.debug(_('PUT started'))
|
||||
|
||||
|
@ -877,16 +897,9 @@ def fork_project():
|
|||
source_proj = get_project(models, must_exist=True, name=command_line.source_project)
|
||||
|
||||
if command_line.target_project:
|
||||
tmp = command_line.target_project.split('/')
|
||||
if len(tmp) > 2:
|
||||
log.error(_('Specify a project name as "group_name/project_name" or just "project_name"'))
|
||||
exit(1)
|
||||
elif len(tmp) == 1:
|
||||
target_name = tmp[0]
|
||||
target_group = default_group
|
||||
elif len(tmp) == 2:
|
||||
target_group = tmp[0]
|
||||
target_name = tmp[1]
|
||||
tmp = get_project_name_only(True, command_line.target_project)
|
||||
target_group = tmp[0]
|
||||
target_name = tmp[1]
|
||||
else:
|
||||
target_group = default_group
|
||||
target_name = source_proj.name
|
||||
|
@ -898,7 +911,7 @@ def fork_project():
|
|||
owner_id = owner_group[0].id
|
||||
elif owner_user:
|
||||
# ABF doesn't seem to accept forks to platforms of other users
|
||||
print(_("No group named '%s', will fork to you personal platform") % target_group)
|
||||
print(_("No group named '%s', will fork to your personal platform") % target_group)
|
||||
# owner_id = owner_user[0].id
|
||||
owner_id = 0
|
||||
else:
|
||||
|
@ -907,6 +920,35 @@ def fork_project():
|
|||
|
||||
ProjectCreator.fork_project(models, source_proj.id, owner_id, target_name)
|
||||
|
||||
def alias_project():
|
||||
log.debug(_('ALIAS PROJECT started'))
|
||||
|
||||
source_proj = get_project(models, must_exist=True, name=command_line.source_project)
|
||||
|
||||
if command_line.target_project:
|
||||
tmp = get_project_name_only(True, command_line.target_project)
|
||||
target_group = tmp[0]
|
||||
target_name = tmp[1]
|
||||
else:
|
||||
target_group = default_group
|
||||
target_name = source_proj.name
|
||||
|
||||
owner_group = Group.search(models, target_group)
|
||||
owner_user = User.search(models, target_group)
|
||||
|
||||
if owner_group:
|
||||
owner_id = owner_group[0].id
|
||||
elif owner_user:
|
||||
# ABF doesn't seem to accept forks to platforms of other users
|
||||
print(_("No group named '%s', will create alias in your personal platform") % target_group)
|
||||
# owner_id = owner_user[0].id
|
||||
owner_id = 0
|
||||
else:
|
||||
print(_("Incorrect target group"))
|
||||
return 1
|
||||
|
||||
ProjectCreator.alias_project(models, source_proj.id, owner_id, target_name)
|
||||
|
||||
|
||||
def create():
|
||||
log.debug(_('CREATE PROJECT started'))
|
||||
|
@ -1552,6 +1594,7 @@ def show():
|
|||
print ' '.join(out)
|
||||
|
||||
elif t in ['save-to-platforms', 'save-to-repos']:
|
||||
proj = get_project(models, must_exist=True, name=command_line.project)
|
||||
repos = proj.repositories
|
||||
platform_names = []
|
||||
repo_names = []
|
||||
|
|
|
@ -381,6 +381,14 @@ class AbfJson(object):
|
|||
URL = "/api/v1/projects/%d/fork.json" % proj_id
|
||||
return self.get_url_contents(URL, GET=None, POST=data)
|
||||
|
||||
def alias_project(self, data, proj_id):
|
||||
URL = "/api/v1/projects/%d/alias.json" % proj_id
|
||||
return self.get_url_contents(URL, GET=None, POST=data)
|
||||
|
||||
def destroy_project(self, data, proj_id):
|
||||
URL = "/api/v1/projects/%d.json" % proj_id
|
||||
return self.get_url_contents(URL, GET=None, POST=None, DELETE=data)
|
||||
|
||||
def add_project_to_repo(self, data, repo_id):
|
||||
URL = "/api/v1/repositories/%d/add_project.json" % repo_id
|
||||
return self.get_url_contents(URL, GET=None, POST=None, PUT=data)
|
||||
|
|
35
abf/model.py
35
abf/model.py
|
@ -758,6 +758,41 @@ class ProjectCreator(Model):
|
|||
exit(1)
|
||||
log.info(_("The project has been forked."))
|
||||
|
||||
@staticmethod
|
||||
def alias_project(models, proj_id, owner_id, target_name):
|
||||
if owner_id > 0:
|
||||
DATA = {
|
||||
'fork_name': target_name,
|
||||
'group_id': owner_id,
|
||||
}
|
||||
else:
|
||||
DATA = {
|
||||
'fork_name': target_name,
|
||||
}
|
||||
|
||||
log.debug(_('Creating alias for a project: ') + str(DATA))
|
||||
try:
|
||||
result = models.jsn.alias_project(DATA, proj_id)
|
||||
except BadRequestError, ex:
|
||||
log.error(_('Sorry, but something went wrong and request I\'ve sent to ABF is bad. Please, '
|
||||
'notify the console-client developers. Send them a set of command-line arguments and the request data:\n%s') % DATA )
|
||||
exit(1)
|
||||
log.info(_("The project alias has been created."))
|
||||
|
||||
@staticmethod
|
||||
def destroy_project(models, proj_id):
|
||||
DATA = {
|
||||
'id': proj_id,
|
||||
}
|
||||
log.debug(_('Destroying project: ') + str(proj_id))
|
||||
try:
|
||||
result = models.jsn.destroy_project(DATA, proj_id)
|
||||
except BadRequestError, ex:
|
||||
log.error(_('Sorry, but something went wrong and request I\'ve sent to ABF is bad. Please, '
|
||||
'notify the console-client developers. Send them a set of command-line arguments and the request data:\n%s') % DATA )
|
||||
exit(1)
|
||||
log.info(_("The project has been destroyed."))
|
||||
|
||||
class Models(object):
|
||||
_instance = {}
|
||||
def __new__(cls, abf_url, file_store_url, login, password, *args, **kwargs):
|
||||
|
|
Loading…
Add table
Reference in a new issue