abf show: get project details, list project buildlists

This commit is contained in:
din (Dmitry Fedorov) 2014-12-16 11:59:03 +03:00
parent e647fb03a4
commit 48a4acef6d
3 changed files with 42 additions and 11 deletions

26
abf.py
View file

@ -172,8 +172,8 @@ def parse_command_line():
# show
parser_show = subparsers.add_parser('show', help=_('show some general information. Bash autocomplete uses it.'))
show_choices = ['build-repos', 'build-platforms', 'save-to-repos', 'save-to-platforms']
parser_show.add_argument('type', action='store', choices=show_choices,help=_('The type of information to show'))
show_choices = ['buildlists', 'build-repos', 'build-platforms', 'save-to-repos', 'save-to-platforms']
parser_show.add_argument('type', action='store', nargs='?', choices=show_choices,help=_('The type of information to show'))
parser_show.add_argument('-p', '--project', action='store', help=_('Project to show information for (if needed). Format: '
'"[group/]name". If no group specified, default group will be used.'))
parser_show.set_defaults(func=show)
@ -1525,10 +1525,21 @@ def update():
def show():
log.debug(_('SHOW started'))
Log.set_silent()
#Log.set_silent()
t = command_line.type
if t in ['build-platforms', 'build-repos']:
if t is None:
proj = get_project(models, must_exist=True, name=command_line.project)
for i in proj.required_fields:
print (_("%s: %s") % (i, getattr(proj, i)))
elif t == 'buildlists':
proj = get_project(models, must_exist=True, name=command_line.project)
res = models.jsn.get_project_buildlists(proj.id, '' ,1)
for bl in res['build_lists']:
buildlist = BuildList(models, bl['id'])
print buildlist
elif t in ['build-platforms', 'build-repos']:
build_platforms = Platform.get_build_platforms(models)
platform_names = []
repo_names = []
@ -1538,9 +1549,9 @@ def show():
for repo in plat.repositories:
repo_names.append(str(repo))
out = (t == 'build-platforms' and platform_names) or (t == 'build-repos' and repo_names)
print ' '.join(out)
if t in ['save-to-platforms', 'save-to-repos']:
proj = get_project(models, must_exist=True, name=command_line.project)
elif t in ['save-to-platforms', 'save-to-repos']:
repos = proj.repositories
platform_names = []
repo_names = []
@ -1549,8 +1560,7 @@ def show():
repo_names.append(str(repo))
platform_names = list(set(platform_names))
out = (t == 'save-to-platforms' and platform_names) or (t == 'save-to-repos' and repo_names)
print ' '.join(out)
print ' '.join(out)
def clean():

View file

@ -331,6 +331,20 @@ class AbfJson(object):
URL = "/api/v1/build_lists/%d.json" % bl_id
return self.get_url_contents(URL)
def get_list_buildlists(self, prj_id, filter_query, page):
prj_id = int(prj_id)
URL = "/api/v1/build_lists.json"
GET = {'page': page, 'per_page': 10}
GET.update(filter_query)
return self.get_url_contents(URL, GET=GET)
def get_project_buildlists(self, prj_id, filter_query, page):
prj_id = int(prj_id)
URL = "/api/v1/projects/%d/build_lists.json" % prj_id
GET = {'page': page, 'per_page': 10}
GET.update(filter_query)
return self.get_url_contents(URL, GET=GET)
def get_project_by_id(self, p_id):
p_id = int(p_id)
URL = "/api/v1/projects/%d.json" % p_id

View file

@ -339,8 +339,8 @@ class Group(Model):
return self.uname
class Project(Model):
required_fields = ['id', 'name', 'created_at', 'updated_at', 'visibility', 'description', 'ancestry', 'has_issues',
'has_wiki', 'default_branch', 'is_package', 'owner', 'repositories', 'owner_type', 'maintainer']
required_fields = ['id', 'name', 'fullname', 'git_url', 'created_at', 'updated_at', 'visibility', 'description', 'ancestry', 'has_issues',
'has_wiki', 'default_branch', 'is_package', 'owner', 'repositories', 'owner_type', 'maintainer', 'project_statistics',]
filter_dict = { 'id': '*', 'name': '*', 'page': '1' }
@ -375,7 +375,14 @@ class Project(Model):
self.params_dict['owner'] = User(self.models, init_data=self.init_data['owner'])
elif self.params_dict['owner_type'] == 'Group':
self.params_dict['owner'] = Group(self.models, init_data=self.init_data['owner'])
if 'ancestry' in self.init_data:
ancestry = self.params_dict['ancestry']
if ancestry:
self.params_dict['ancestry'] = []
items = ancestry.split('/')
for item in items:
anc_proj=self.models.jsn.get_project_by_id(item)
self.params_dict['ancestry'].append(anc_proj['project']['fullname'])
if 'created_at' in self.init_data:
self.params_dict['created_at'] = datetime.fromtimestamp(float(self.init_data['created_at']))
if 'updated_at' in self.init_data: