poky/meta/lib/patchtest/patterns.py
Trevor Gamblin bb0f1625d7 patchtest: patterns: add module, refactor
Currently, patchtest has a lot of spread-out definitions for patterns
used in various setup and test functions. Organize these by putting them
all into a new patterns.py module. This allows the tests/pyparsing
directory to be removed, as it is now redundant. Also remove some
definitions where they were duplicated or unused, and perform some
renames to improve readability and avoid collisions. Many of these
variables are composed from others, so the file is only partially
sorted.

(From OE-Core rev: 1ab55d495957918be532a36224b5598c9955a44d)

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2024-09-30 17:00:50 +01:00

93 lines
3.4 KiB
Python

# common pyparsing variables
#
# Copyright (C) 2016 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-only
import pyparsing
# general
colon = pyparsing.Literal(":")
line_start = pyparsing.LineStart()
line_end = pyparsing.LineEnd()
at = pyparsing.Literal("@")
lessthan = pyparsing.Literal("<")
greaterthan = pyparsing.Literal(">")
opensquare = pyparsing.Literal("[")
closesquare = pyparsing.Literal("]")
inappropriate = pyparsing.CaselessLiteral("Inappropriate")
submitted = pyparsing.CaselessLiteral("Submitted")
# word related
nestexpr = pyparsing.nestedExpr(opener='[', closer=']')
inappropriateinfo = pyparsing.Literal("Inappropriate") + nestexpr
submittedinfo = pyparsing.Literal("Submitted") + nestexpr
word = pyparsing.Word(pyparsing.alphas)
worddot = pyparsing.Word(pyparsing.alphas+".")
# metadata
metadata_lic = 'LICENSE'
invalid_license = 'PATCHTESTINVALID'
metadata_chksum = 'LIC_FILES_CHKSUM'
license_var = 'LICENSE'
closed = 'CLOSED'
lictag_re = pyparsing.AtLineStart("License-Update:")
lic_chksum_added = pyparsing.AtLineStart("+" + metadata_chksum)
lic_chksum_removed = pyparsing.AtLineStart("-" + metadata_chksum)
add_mark = pyparsing.Regex('\\+ ')
patch_max_line_length = 200
metadata_src_uri = 'SRC_URI'
metadata_summary = 'SUMMARY'
cve_check_ignore_var = 'CVE_CHECK_IGNORE'
cve_status_var = 'CVE_STATUS'
# mbox
auh_email = 'auh@yoctoproject.org'
invalid_submitters = [pyparsing.Regex("^Upgrade Helper.+"),
pyparsing.Regex(auh_email),
pyparsing.Regex("uh@not\.set"),
pyparsing.Regex("\S+@example\.com")]
mbox_bugzilla = pyparsing.Regex('\[\s?YOCTO.*\]')
mbox_bugzilla_validation = pyparsing.Regex('\[(\s?YOCTO\s?#\s?(\d+)\s?,?)+\]')
mbox_revert_shortlog_regex = pyparsing.Regex('Revert\s+".*"')
mbox_shortlog_maxlength = 90
# patch
cve = pyparsing.Regex("CVE\-\d{4}\-\d+")
cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+")
upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status")
# shortlog
shortlog_target = pyparsing.OneOrMore(pyparsing.Word(pyparsing.printables.replace(':','')))
shortlog_summary = pyparsing.OneOrMore(pyparsing.Word(pyparsing.printables))
shortlog = line_start + shortlog_target + colon + shortlog_summary + line_end
# signed-off-bys
email_pattern = pyparsing.Regex(r"(?P<user>[A-Za-z0-9._%+-]+)@(?P<hostname>[A-Za-z0-9.-]+)\.(?P<domain>[A-Za-z]{2,})")
signed_off_by_prefix = pyparsing.Literal("Signed-off-by:")
signed_off_by_name = pyparsing.Regex('\S+.*(?= <)')
signed_off_by_email = lessthan + email_pattern + greaterthan
signed_off_by = pyparsing.AtLineStart(signed_off_by_prefix + signed_off_by_name + signed_off_by_email)
patch_signed_off_by = pyparsing.AtLineStart("+" + signed_off_by_prefix + signed_off_by_name + signed_off_by_email)
# upstream-status
upstream_status_literal_valid_status = ["Pending", "Backport", "Denied", "Inappropriate", "Submitted"]
upstream_status_nonliteral_valid_status = ["Pending", "Backport", "Denied", "Inappropriate [reason]", "Submitted [where]"]
upstream_status_valid_status = pyparsing.Or(
[pyparsing.Literal(status) for status in upstream_status_literal_valid_status]
)
upstream_status_prefix = pyparsing.Literal("Upstream-Status")
upstream_status = line_start + upstream_status_prefix + colon + upstream_status_valid_status
upstream_status_inappropriate_info = line_start + upstream_status_prefix + colon + inappropriateinfo
upstream_status_submitted_info = line_start + upstream_status_prefix + colon + submittedinfo