From 5b80bfd7bffd4c20d80b7c70a7130529e9a755dd Mon Sep 17 00:00:00 2001 From: ToshikazuOhiwa Date: Mon, 30 Mar 2020 09:24:26 +0900 Subject: agl-basesystem --- .../toaster/toastergui/templatetags/projecttags.py | 299 +++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 external/poky/bitbake/lib/toaster/toastergui/templatetags/projecttags.py (limited to 'external/poky/bitbake/lib/toaster/toastergui/templatetags/projecttags.py') diff --git a/external/poky/bitbake/lib/toaster/toastergui/templatetags/projecttags.py b/external/poky/bitbake/lib/toaster/toastergui/templatetags/projecttags.py new file mode 100644 index 00000000..b170a161 --- /dev/null +++ b/external/poky/bitbake/lib/toaster/toastergui/templatetags/projecttags.py @@ -0,0 +1,299 @@ +# +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# BitBake Toaster Implementation +# +# Copyright (C) 2013 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from datetime import datetime, timedelta +from os.path import relpath +import re +from django import template +from django.utils import timezone +from django.template.defaultfilters import filesizeformat +import json as JsonLib +from django.utils.safestring import mark_safe + +register = template.Library() + +@register.simple_tag +def time_difference(start_time, end_time): + return end_time - start_time + +@register.filter(name = 'sectohms') +def sectohms(time): + try: + tdsec = int(time) + except ValueError: + tdsec = 0 + hours = int(tdsec / 3600) + return "%02d:%02d:%02d" % (hours, int((tdsec - (hours * 3600))/ 60), int(tdsec) % 60) + + +@register.filter(name = 'get_tasks') +def get_tasks(queryset): + return list(target + ':' + task if task else target \ + for target, task in queryset.values_list('target', 'task')) + + +@register.filter(name = "json") +def json(value, default = None): + # JSON spec says that "\/" is functionally identical to "/" to allow for HTML-tag embedding in JSON strings + # unfortunately, I can't find any option in the json module to turn on forward-slash escaping, so we do + # it manually here + return mark_safe(JsonLib.dumps(value, indent=2, default = default, ensure_ascii=False).replace('' + r += '' + return mark_safe(r) + +@register.filter +def get_dict_value(dictionary, key): + """ return the value of a dictionary key + """ + try: + return dictionary[key] + except (KeyError, IndexError): + return '' + +@register.filter +def is_shaid(text): + """ return True if text length is 40 characters and all hex-digits + """ + try: + int(text, 16) + if len(text) == 40: + return True + return False + except ValueError: + return False + +@register.filter +def cut_path_prefix(fullpath, prefixes): + """Cut path prefix from fullpath.""" + for prefix in prefixes: + if fullpath.startswith(prefix): + return relpath(fullpath, prefix) + return fullpath + + +@register.filter +def for_target(package_dependencies, target): + """ filter the dependencies to be displayed by the supplied target + if no dependences are found for the target then return the predicted + dependences""" + return package_dependencies.for_target_or_none(target) -- cgit 1.2.3-korg