1# common pyparsing variables 2# 3# Copyright (C) 2016 Intel Corporation 4# 5# SPDX-License-Identifier: GPL-2.0-only 6 7import pyparsing 8import re 9 10# general 11colon = pyparsing.Literal(":") 12line_start = pyparsing.LineStart() 13line_end = pyparsing.LineEnd() 14lessthan = pyparsing.Literal("<") 15greaterthan = pyparsing.Literal(">") 16inappropriate = pyparsing.CaselessLiteral("Inappropriate") 17submitted = pyparsing.CaselessLiteral("Submitted") 18 19# word related 20nestexpr = pyparsing.nestedExpr(opener='[', closer=']') 21inappropriateinfo = pyparsing.Literal("Inappropriate") + nestexpr 22submittedinfo = pyparsing.Literal("Submitted") + nestexpr 23word = pyparsing.Word(pyparsing.alphas) 24worddot = pyparsing.Word(pyparsing.alphas+".") 25 26# metadata 27 28metadata_lic = 'LICENSE' 29invalid_license = 'PATCHTESTINVALID' 30metadata_chksum = 'LIC_FILES_CHKSUM' 31license_var = 'LICENSE' 32closed = 'CLOSED' 33lictag_re = pyparsing.AtLineStart("License-Update:") 34lic_chksum_added = pyparsing.AtLineStart("+" + metadata_chksum) 35lic_chksum_removed = pyparsing.AtLineStart("-" + metadata_chksum) 36add_mark = pyparsing.Regex('\\+ ') 37patch_max_line_length = 200 38metadata_src_uri = "SRC_URI" 39metadata_summary = "SUMMARY" 40cve_check_ignore_var = "CVE_CHECK_IGNORE" 41cve_status_var = "CVE_STATUS" 42endcommit_messages_regex = re.compile( 43 r"\(From \w+-\w+ rev:|(?<!\S)Signed-off-by|(?<!\S)---\n" 44) 45patchmetadata_regex = re.compile( 46 r"-{3} \S+|\+{3} \S+|@{2} -\d+,\d+ \+\d+,\d+ @{2} \S+" 47) 48 49# mbox 50auh_email = 'auh@yoctoproject.org' 51 52invalid_submitters = [pyparsing.Regex("^Upgrade Helper.+"), 53 pyparsing.Regex(auh_email), 54 pyparsing.Regex("uh@not\.set"), 55 pyparsing.Regex("\S+@example\.com")] 56 57mbox_bugzilla = pyparsing.Regex('\[\s?YOCTO.*\]') 58mbox_bugzilla_validation = pyparsing.Regex('\[(\s?YOCTO\s?#\s?(\d+)\s?,?)+\]') 59mbox_revert_shortlog_regex = pyparsing.Regex('Revert\s+".*"') 60mbox_shortlog_maxlength = 90 61# based on https://stackoverflow.com/questions/30281026/regex-parsing-github-usernames-javascript 62mbox_github_username = pyparsing.Regex('\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))') 63 64# patch 65 66cve = pyparsing.Regex("CVE\-\d{4}\-\d+") 67cve_payload_tag = pyparsing.Regex("\+CVE:(\s+CVE\-\d{4}\-\d+)+") 68upstream_status_regex = pyparsing.AtLineStart("+" + "Upstream-Status") 69 70# shortlog 71 72shortlog_target = pyparsing.OneOrMore(pyparsing.Word(pyparsing.printables.replace(':',''))) 73shortlog_summary = pyparsing.OneOrMore(pyparsing.Word(pyparsing.printables)) 74shortlog = line_start + shortlog_target + colon + shortlog_summary + line_end 75 76# signed-off-bys 77 78email_pattern = pyparsing.Regex(r"(?P<user>[A-Za-z0-9._%+-]+)@(?P<hostname>[A-Za-z0-9.-]+)\.(?P<domain>[A-Za-z]{2,})") 79 80signed_off_by_prefix = pyparsing.Literal("Signed-off-by:") 81signed_off_by_name = pyparsing.Regex('\S+.*(?= <)') 82signed_off_by_email = lessthan + email_pattern + greaterthan 83signed_off_by = pyparsing.AtLineStart(signed_off_by_prefix + signed_off_by_name + signed_off_by_email) 84patch_signed_off_by = pyparsing.AtLineStart("+" + signed_off_by_prefix + signed_off_by_name + signed_off_by_email) 85 86# upstream-status 87 88upstream_status_literal_valid_status = ["Pending", "Backport", "Denied", "Inappropriate", "Submitted", "Inactive-Upstream"] 89upstream_status_nonliteral_valid_status = ["Pending", "Backport", "Denied", "Inappropriate [reason]", "Submitted [where]", "Inactive-Upstream [lastcommit: when (and/or) lastrelease: when]"] 90 91upstream_status_valid_status = pyparsing.Or( 92 [pyparsing.Literal(status) for status in upstream_status_literal_valid_status] 93) 94 95upstream_status_prefix = pyparsing.Literal("Upstream-Status") 96upstream_status = line_start + upstream_status_prefix + colon + upstream_status_valid_status 97upstream_status_inappropriate_info = line_start + upstream_status_prefix + colon + inappropriateinfo 98upstream_status_submitted_info = line_start + upstream_status_prefix + colon + submittedinfo 99