return render(request, 'landing.html', context)
-"""
-# returns a list for most recent builds;
-def _get_latest_builds(prj=None):
- queryset = Build.objects.all()
-
- if prj is not None:
- queryset = queryset.filter(project = prj)
-
- return list(itertools.chain(
- queryset.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"),
- queryset.filter(outcome__lt=Build.IN_PROGRESS).order_by("-started_on")[:3] ))
-"""
-
-"""
-# a JSON-able dict of recent builds; for use in the Project page, xhr_ updates, and other places, as needed
-def _project_recent_build_list(prj):
- data = []
- # take the most recent 3 completed builds, plus any builds in progress
- for x in _get_latest_builds(prj):
- d = {
- "id": x.pk,
- "targets" : map(lambda y: {"target": y.target, "task": y.task }, x.target_set.all()), # TODO: create the task entry in the Target table
- "status": x.get_current_status(),
- "errors": map(lambda y: {"type": y.lineno, "msg": y.message, "tb": y.pathname}, (x.logmessage_set.filter(level__gte=LogMessage.WARNING)|x.logmessage_set.filter(level=LogMessage.EXCEPTION))),
- "updated": x.completed_on.strftime('%s')+"000",
- "command_time": (x.completed_on - x.started_on).total_seconds(),
- "br_page_url": reverse('builddashboard', args=(x.pk,) ),
- "build" : map( lambda y: {"id": y.pk,
- "status": y.get_outcome_display(),
- "completed_on" : y.completed_on.strftime('%s')+"000",
- "build_time" : (y.completed_on - y.started_on).total_seconds(),
- "build_page_url" : reverse('builddashboard', args=(y.pk,)),
- 'build_time_page_url': reverse('buildtime', args=(y.pk,)),
- "errors": y.errors.count(),
- "warnings": y.warnings.count(),
- "completeper": y.completeper() if y.outcome == Build.IN_PROGRESS else "0",
- "eta": y.eta().strftime('%s')+"000" if y.outcome == Build.IN_PROGRESS else "0",
- }, [x]),
- }
- data.append(d)
-
- return data
-"""
-
def objtojson(obj):
from django.db.models.query import QuerySet
from django.db.models import Model
''' The exception raised on invalid POST requests '''
pass
- """
- # helper function, to be used on "all builds" and "project builds" pages
- def _build_list_helper(request, queryset_all, redirect_page, pid=None):
- default_orderby = 'completed_on:-'
- (pagesize, orderby) = _get_parameters_values(request, 10, default_orderby)
- mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
- retval = _verify_parameters( request.GET, mandatory_parameters )
- if retval:
- params = {}
- if pid:
- params = {'pid': pid}
- raise RedirectException(redirect_page,
- request.GET,
- mandatory_parameters,
- **params)
-
- # boilerplate code that takes a request for an object type and returns a queryset
- # for that object type. copypasta for all needed table searches
- (filter_string, search_term, ordering_string) = _search_tuple(request, Build)
-
- # post-process any date range filters
- filter_string, daterange_selected = _modify_date_range_filter(filter_string)
-
- # don't show "in progress" builds in "all builds" or "project builds"
- queryset_all = queryset_all.exclude(outcome = Build.IN_PROGRESS)
-
- # append project info
- queryset_all = queryset_all.select_related("project")
-
- # annotate with number of ERROR and EXCEPTION log messages
- queryset_all = queryset_all.annotate(
- errors_no = Count(
- 'logmessage',
- only=Q(logmessage__level=LogMessage.ERROR) |
- Q(logmessage__level=LogMessage.EXCEPTION)
- )
- )
-
- # annotate with number of warnings
- q_warnings = Q(logmessage__level=LogMessage.WARNING)
- queryset_all = queryset_all.annotate(
- warnings_no = Count('logmessage', only=q_warnings)
- )
-
- queryset_with_search = _get_queryset(Build, queryset_all,
- None, search_term,
- ordering_string, '-completed_on')
-
- queryset = _get_queryset(Build, queryset_all,
- filter_string, search_term,
- ordering_string, '-completed_on')
-
- # retrieve the objects that will be displayed in the table; builds a paginator and gets a page range to display
- build_info = _build_page_range(Paginator(queryset, pagesize), request.GET.get('page', 1))
-
- # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds)
- build_mru = _get_latest_builds()[:3]
-
- # calculate the exact begining of local today and yesterday, append context
- context_date,today_begin,yesterday_begin = _add_daterange_context(queryset_all, request, {'started_on','completed_on'})
-
- # set up list of fstypes for each build
- fstypes_map = {}
-
- for build in build_info:
- fstypes_map[build.id] = build.get_image_file_extensions()
-
- # send the data to the template
- context = {
- # specific info for
- 'mru' : build_mru,
- # TODO: common objects for all table views, adapt as needed
- 'objects' : build_info,
- 'objectname' : "builds",
- 'default_orderby' : default_orderby,
- 'fstypes' : fstypes_map,
- 'search_term' : search_term,
- 'total_count' : queryset_with_search.count(),
- 'daterange_selected' : daterange_selected,
- # Specifies the display of columns for the table, appearance in "Edit columns" box, toggling default show/hide, and specifying filters for columns
- 'tablecols' : [
- {'name': 'Outcome', # column with a single filter
- 'qhelp' : "The outcome tells you if a build successfully completed or failed", # the help button content
- 'dclass' : "span2", # indication about column width; comes from the design
- 'orderfield': _get_toggle_order(request, "outcome"), # adds ordering by the field value; default ascending unless clicked from ascending into descending
- 'ordericon':_get_toggle_order_icon(request, "outcome"),
- # filter field will set a filter on that column with the specs in the filter description
- # the class field in the filter has no relation with clclass; the control different aspects of the UI
- # still, it is recommended for the values to be identical for easy tracking in the generated HTML
- 'filter' : {'class' : 'outcome',
- 'label': 'Show:',
- 'options' : [
- ('Successful builds', 'outcome:' + str(Build.SUCCEEDED), queryset_with_search.filter(outcome=str(Build.SUCCEEDED)).count()), # this is the field search expression
- ('Failed builds', 'outcome:'+ str(Build.FAILED), queryset_with_search.filter(outcome=str(Build.FAILED)).count()),
- ]
- }
- },
- {'name': 'Recipe', # default column, disabled box, with just the name in the list
- 'qhelp': "What you built (i.e. one or more recipes or image recipes)",
- 'orderfield': _get_toggle_order(request, "target__target"),
- 'ordericon':_get_toggle_order_icon(request, "target__target"),
- },
- {'name': 'Machine',
- 'qhelp': "The machine is the hardware for which you are building a recipe or image recipe",
- 'orderfield': _get_toggle_order(request, "machine"),
- 'ordericon':_get_toggle_order_icon(request, "machine"),
- 'dclass': 'span3'
- }, # a slightly wider column
- {'name': 'Started on', 'clclass': 'started_on', 'hidden' : 1, # this is an unchecked box, which hides the column
- 'qhelp': "The date and time you started the build",
- 'orderfield': _get_toggle_order(request, "started_on", True),
- 'ordericon':_get_toggle_order_icon(request, "started_on"),
- 'orderkey' : "started_on",
- 'filter' : {'class' : 'started_on',
- 'label': 'Show:',
- 'options' : [
- ("Today's builds" , 'started_on__gte:'+today_begin.strftime("%Y-%m-%d"), queryset_all.filter(started_on__gte=today_begin).count()),
- ("Yesterday's builds",
- 'started_on__gte!started_on__lt:'
- +yesterday_begin.strftime("%Y-%m-%d")+'!'
- +today_begin.strftime("%Y-%m-%d"),
- queryset_all.filter(
- started_on__gte=yesterday_begin,
- started_on__lt=today_begin
- ).count()),
- ("Build date range", 'daterange', 1, '', 'started_on'),
- ]
- }
- },
- {'name': 'Completed on',
- 'qhelp': "The date and time the build finished",
- 'orderfield': _get_toggle_order(request, "completed_on", True),
- 'ordericon':_get_toggle_order_icon(request, "completed_on"),
- 'orderkey' : 'completed_on',
- 'filter' : {'class' : 'completed_on',
- 'label': 'Show:',
- 'options' : [
- ("Today's builds" , 'completed_on__gte:'+today_begin.strftime("%Y-%m-%d"), queryset_all.filter(completed_on__gte=today_begin).count()),
- ("Yesterday's builds",
- 'completed_on__gte!completed_on__lt:'
- +yesterday_begin.strftime("%Y-%m-%d")+'!'
- +today_begin.strftime("%Y-%m-%d"),
- queryset_all.filter(
- completed_on__gte=yesterday_begin,
- completed_on__lt=today_begin
- ).count()),
- ("Build date range", 'daterange', 1, '', 'completed_on'),
- ]
- }
- },
- {'name': 'Failed tasks', 'clclass': 'failed_tasks', # specifing a clclass will enable the checkbox
- 'qhelp': "How many tasks failed during the build",
- 'filter' : {'class' : 'failed_tasks',
- 'label': 'Show:',
- 'options' : [
- ('Builds with failed tasks', 'task_build__outcome:4', queryset_with_search.filter(task_build__outcome=4).count()),
- ('Builds without failed tasks', 'task_build__outcome:NOT4', queryset_with_search.filter(~Q(task_build__outcome=4)).count()),
- ]
- }
- },
- {'name': 'Errors', 'clclass': 'errors_no',
- 'qhelp': "How many errors were encountered during the build (if any)",
- # Comment out sorting and filter until YOCTO #8131 is fixed
- #'orderfield': _get_toggle_order(request, "errors_no", True),
- #'ordericon':_get_toggle_order_icon(request, "errors_no"),
- #'orderkey' : 'errors_no',
- #'filter' : {'class' : 'errors_no',
- # 'label': 'Show:',
- # 'options' : [
- # ('Builds with errors', 'errors_no__gte:1', queryset_with_search.filter(errors_no__gte=1).count()),
- # ('Builds without errors', 'errors_no:0', queryset_with_search.filter(errors_no=0).count()),
- # ]
- # }
- },
- {'name': 'Warnings', 'clclass': 'warnings_no',
- 'qhelp': "How many warnings were encountered during the build (if any)",
- # Comment out sorting and filter until YOCTO #8131 is fixed
- #'orderfield': _get_toggle_order(request, "warnings_no", True),
- #'ordericon':_get_toggle_order_icon(request, "warnings_no"),
- #'orderkey' : 'warnings_no',
- #'filter' : {'class' : 'warnings_no',
- # 'label': 'Show:',
- # 'options' : [
- # ('Builds with warnings','warnings_no__gte:1', queryset_with_search.filter(warnings_no__gte=1).count()),
- # ('Builds without warnings','warnings_no:0', queryset_with_search.filter(warnings_no=0).count()),
- # ]
- # }
- },
- {'name': 'Time', 'clclass': 'time', 'hidden' : 1,
- 'qhelp': "How long it took the build to finish",
- # Comment out sorting until YOCTO #8131 is fixed
- #'orderfield': _get_toggle_order(request, "timespent", True),
- #'ordericon':_get_toggle_order_icon(request, "timespent"),
- #'orderkey' : 'timespent',
- },
- {'name': 'Image files', 'clclass': 'output',
- 'qhelp': "The root file system types produced by the build. You can find them in your <code>/build/tmp/deploy/images/</code> directory",
- # TODO: compute image fstypes from Target_Image_File
- }
- ]
- }
-
- # merge daterange values
- context.update(context_date)
- return context, pagesize, orderby
- """
-
-
-
# new project
def newproject(request):
template = "newproject.html"
return context
- # WARNING _build_list_helper() may raise a RedirectException, which
- # will set the GET parameters and redirect back to the
- # all-builds or projectbuilds page as appropriate;
- # TODO don't use exceptions to control program flow
- """
- def projectbuilds(request, pid):
- if request.method == "POST":
- # process any build request
-
- if 'buildCancel' in request.POST:
- for i in request.POST['buildCancel'].strip().split(" "):
- try:
- br = BuildRequest.objects.select_for_update().get(project = prj, pk = i, state__lte = BuildRequest.REQ_QUEUED)
- br.state = BuildRequest.REQ_DELETED
- br.save()
- except BuildRequest.DoesNotExist:
- pass
-
- if 'buildDelete' in request.POST:
- for i in request.POST['buildDelete'].strip().split(" "):
- try:
- BuildRequest.objects.select_for_update().get(project = prj, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
- except BuildRequest.DoesNotExist:
- pass
-
- if 'targets' in request.POST:
- ProjectTarget.objects.filter(project = prj).delete()
- s = str(request.POST['targets'])
- for t in s.translate(None, ";%|\"").split(" "):
- if ":" in t:
- target, task = t.split(":")
- else:
- target = t
- task = ""
- ProjectTarget.objects.create(project = prj,
- target = target,
- task = task)
- prj.schedule_build()
-
- queryset = Build.objects.filter(project_id = pid)
-
- redirect_page = resolve(request.path_info).url_name
-
- context, pagesize, orderby = _build_list_helper(request,
- queryset,
- redirect_page,
- pid)
-
- context['project'] = prj
- _set_parameters_values(pagesize, orderby, request)
-
- # add the most recent builds for this project
- context['mru'] = _get_latest_builds(prj)
-
- return context
- """
-
-
def _file_name_for_artifact(b, artifact_type, artifact_id):
file_name = None
# Target_Image_File file_name
'build' : Build.objects.get(pk = build_id),
}
return render(request, "unavailable_artifact.html", context)
-
- """
- @_template_renderer("projects.html")
- def projects(request):
- (pagesize, orderby) = _get_parameters_values(request, 10, 'updated:-')
- mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
- retval = _verify_parameters( request.GET, mandatory_parameters )
- if retval:
- raise RedirectException( 'all-projects', request.GET, mandatory_parameters )
-
- queryset_all = Project.objects.all()
-
- # annotate each project with its number of builds
- queryset_all = queryset_all.annotate(num_builds=Count('build'))
-
- # exclude the command line builds project if it has no builds
- q_default_with_builds = Q(is_default=True) & Q(num_builds__gt=0)
- queryset_all = queryset_all.filter(Q(is_default=False) |
- q_default_with_builds)
-
- # boilerplate code that takes a request for an object type and returns a queryset
- # for that object type. copypasta for all needed table searches
- (filter_string, search_term, ordering_string) = _search_tuple(request, Project)
- queryset_with_search = _get_queryset(Project, queryset_all, None, search_term, ordering_string, '-updated')
- queryset = _get_queryset(Project, queryset_all, filter_string, search_term, ordering_string, '-updated')
-
- # retrieve the objects that will be displayed in the table; projects a paginator and gets a page range to display
- project_info = _build_page_range(Paginator(queryset, pagesize), request.GET.get('page', 1))
-
- # add fields needed in JSON dumps for API call support
- for p in project_info.object_list:
- p.id = p.pk
- p.projectPageUrl = reverse('project', args=(p.id,))
- p.layersTypeAheadUrl = reverse('xhr_layerstypeahead', args=(p.id,))
- p.recipesTypeAheadUrl = reverse('xhr_recipestypeahead', args=(p.id,))
- p.projectBuildsUrl = reverse('projectbuilds', args=(p.id,))
-
- # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds)
- build_mru = _get_latest_builds()
-
- # translate the project's build target strings
- fstypes_map = {};
- for project in project_info:
- try:
- targets = Target.objects.filter( build_id = project.get_last_build_id() )
- comma = "";
- extensions = "";
- for t in targets:
- if ( not t.is_image ):
- continue
- tif = Target_Image_File.objects.filter( target_id = t.id )
- for i in tif:
- s=re.sub('.*tar.bz2', 'tar.bz2', i.file_name)
- if s == i.file_name:
- s=re.sub('.*\.', '', i.file_name)
- if None == re.search(s,extensions):
- extensions += comma + s
- comma = ", "
- fstypes_map[project.id]=extensions
- except (Target.DoesNotExist,IndexError):
- fstypes_map[project.id]=project.get_last_imgfiles
-
- context = {
- 'mru' : build_mru,
-
- 'objects' : project_info,
- 'objectname' : "projects",
- 'default_orderby' : 'id:-',
- 'search_term' : search_term,
- 'total_count' : queryset_with_search.count(),
- 'fstypes' : fstypes_map,
- 'build_FAILED' : Build.FAILED,
- 'build_SUCCEEDED' : Build.SUCCEEDED,
- 'tablecols': [
- {'name': 'Project',
- 'orderfield': _get_toggle_order(request, "name"),
- 'ordericon':_get_toggle_order_icon(request, "name"),
- 'orderkey' : 'name',
- },
- {'name': 'Last activity on',
- 'clclass': 'updated',
- 'qhelp': "Shows the starting date and time of the last project build. If the project has no builds, it shows the date the project was created",
- 'orderfield': _get_toggle_order(request, "updated", True),
- 'ordericon':_get_toggle_order_icon(request, "updated"),
- 'orderkey' : 'updated',
- },
- {'name': 'Release',
- 'qhelp' : "The version of the build system used by the project",
- 'orderfield': _get_toggle_order(request, "release__name"),
- 'ordericon':_get_toggle_order_icon(request, "release__name"),
- 'orderkey' : 'release__name',
- },
- {'name': 'Machine',
- 'qhelp': "The hardware currently selected for the project",
- },
- {'name': 'Number of builds',
- 'qhelp': "How many builds have been run for the project",
- },
- {'name': 'Last build outcome', 'clclass': 'loutcome',
- 'qhelp': "Tells you if the last project build completed successfully or failed",
- },
- {'name': 'Recipe', 'clclass': 'ltarget',
- 'qhelp': "The last recipe that was built in this project",
- },
- {'name': 'Errors', 'clclass': 'lerrors',
- 'qhelp': "How many errors were encountered during the last project build (if any)",
- },
- {'name': 'Warnings', 'clclass': 'lwarnings',
- 'qhelp': "How many warnigns were encountered during the last project build (if any)",
- },
- {'name': 'Image files', 'clclass': 'limagefiles', 'hidden': 1,
- 'qhelp': "The root file system types produced by the last project build",
- },
- ]
- }
-
- _set_parameters_values(pagesize, orderby, request)
- return context
- """