diff options
Diffstat (limited to 'meta/lib/patchtest/utils.py')
-rw-r--r-- | meta/lib/patchtest/utils.py | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/meta/lib/patchtest/utils.py b/meta/lib/patchtest/utils.py deleted file mode 100644 index 8eddf3e85f..0000000000 --- a/meta/lib/patchtest/utils.py +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # utils: common methods used by the patchtest framework | ||
5 | # | ||
6 | # Copyright (C) 2016 Intel Corporation | ||
7 | # | ||
8 | # SPDX-License-Identifier: GPL-2.0-only | ||
9 | # | ||
10 | |||
11 | import os | ||
12 | import subprocess | ||
13 | import logging | ||
14 | import re | ||
15 | import mailbox | ||
16 | |||
17 | def logger_create(name): | ||
18 | logger = logging.getLogger(name) | ||
19 | loggerhandler = logging.StreamHandler() | ||
20 | loggerhandler.setFormatter(logging.Formatter("%(message)s")) | ||
21 | logger.addHandler(loggerhandler) | ||
22 | logger.setLevel(logging.INFO) | ||
23 | return logger | ||
24 | |||
25 | def valid_branch(branch): | ||
26 | """ Check if branch is valid name """ | ||
27 | lbranch = branch.lower() | ||
28 | |||
29 | invalid = lbranch.startswith('patch') or \ | ||
30 | lbranch.startswith('rfc') or \ | ||
31 | lbranch.startswith('resend') or \ | ||
32 | re.search(r'^v\d+', lbranch) or \ | ||
33 | re.search(r'^\d+/\d+', lbranch) | ||
34 | |||
35 | return not invalid | ||
36 | |||
37 | def get_branch(path): | ||
38 | """ Get the branch name from mbox """ | ||
39 | fullprefix = "" | ||
40 | mbox = mailbox.mbox(path) | ||
41 | |||
42 | if len(mbox): | ||
43 | subject = mbox[0]['subject'] | ||
44 | if subject: | ||
45 | pattern = re.compile(r"(\[.*\])", re.DOTALL) | ||
46 | match = pattern.search(subject) | ||
47 | if match: | ||
48 | fullprefix = match.group(1) | ||
49 | |||
50 | branch, branches, valid_branches = None, [], [] | ||
51 | |||
52 | if fullprefix: | ||
53 | prefix = fullprefix.strip('[]') | ||
54 | branches = [ b.strip() for b in prefix.split(',')] | ||
55 | valid_branches = [b for b in branches if valid_branch(b)] | ||
56 | |||
57 | if len(valid_branches): | ||
58 | branch = valid_branches[0] | ||
59 | |||
60 | return branch | ||
61 | |||