diff options
author | Trevor Gamblin <tgamblin@baylibre.com> | 2024-05-03 09:10:32 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-13 16:28:35 +0100 |
commit | cec77d941ebcd6d3c693f220bef4af411eab39cf (patch) | |
tree | 2ce9733aa3b32266a37f7cf4a27173c11f7ed3eb /meta/lib/patchtest/utils.py | |
parent | 9c4e35079716bb612f2c90262ae0a111e0e6c766 (diff) | |
download | poky-cec77d941ebcd6d3c693f220bef4af411eab39cf.tar.gz |
patchtest: utils: remove unused functions
Specifically, remove four things:
- get_subject_prefix(): This function is only being used once (in the next
function found in the module), so remove it for easier
comprehension/maintenance.
- exec_cmd: the backend for executing a custom command
- exec_cmds: for running multiple calls to exec_cmd
- CmdException: A custom exception class specifically for exec_cmd
These are only used to execute git commands, but GitPython can be used
to handle all of that more efficiently, so remove them.
(From OE-Core rev: e2fabdd6d53ee30a67992bd966961f423f18a388)
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/utils.py')
-rw-r--r-- | meta/lib/patchtest/utils.py | 129 |
1 files changed, 11 insertions, 118 deletions
diff --git a/meta/lib/patchtest/utils.py b/meta/lib/patchtest/utils.py index dd0abc22d9..8eddf3e85f 100644 --- a/meta/lib/patchtest/utils.py +++ b/meta/lib/patchtest/utils.py | |||
@@ -14,109 +14,6 @@ import logging | |||
14 | import re | 14 | import re |
15 | import mailbox | 15 | import mailbox |
16 | 16 | ||
17 | class CmdException(Exception): | ||
18 | """ Simple exception class where its attributes are the ones passed when instantiated """ | ||
19 | def __init__(self, cmd): | ||
20 | self._cmd = cmd | ||
21 | def __getattr__(self, name): | ||
22 | value = None | ||
23 | if self._cmd.has_key(name): | ||
24 | value = self._cmd[name] | ||
25 | return value | ||
26 | |||
27 | def exec_cmd(cmd, cwd, ignore_error=False, input=None, strip=True, updateenv={}): | ||
28 | """ | ||
29 | Input: | ||
30 | |||
31 | cmd: dict containing the following keys: | ||
32 | |||
33 | cmd : the command itself as an array of strings | ||
34 | ignore_error: if False, no exception is raised | ||
35 | strip: indicates if strip is done on the output (stdout and stderr) | ||
36 | input: input data to the command (stdin) | ||
37 | updateenv: environment variables to be appended to the current | ||
38 | process environment variables | ||
39 | |||
40 | NOTE: keys 'ignore_error' and 'input' are optional; if not included, | ||
41 | the defaults are the ones specify in the arguments | ||
42 | cwd: directory where commands are executed | ||
43 | ignore_error: raise CmdException if command fails to execute and | ||
44 | this value is False | ||
45 | input: input data (stdin) for the command | ||
46 | |||
47 | Output: dict containing the following keys: | ||
48 | |||
49 | cmd: the same as input | ||
50 | ignore_error: the same as input | ||
51 | strip: the same as input | ||
52 | input: the same as input | ||
53 | stdout: Standard output after command's execution | ||
54 | stderr: Standard error after command's execution | ||
55 | returncode: Return code after command's execution | ||
56 | |||
57 | """ | ||
58 | cmddefaults = { | ||
59 | 'cmd':'', | ||
60 | 'ignore_error':ignore_error, | ||
61 | 'strip':strip, | ||
62 | 'input':input, | ||
63 | 'updateenv':updateenv, | ||
64 | } | ||
65 | |||
66 | # update input values if necessary | ||
67 | cmddefaults.update(cmd) | ||
68 | |||
69 | _cmd = cmddefaults | ||
70 | |||
71 | if not _cmd['cmd']: | ||
72 | raise CmdException({'cmd':None, 'stderr':'no command given'}) | ||
73 | |||
74 | # update the environment | ||
75 | env = os.environ | ||
76 | env.update(_cmd['updateenv']) | ||
77 | |||
78 | _command = [e for e in _cmd['cmd']] | ||
79 | p = subprocess.Popen(_command, | ||
80 | stdin=subprocess.PIPE, | ||
81 | stdout=subprocess.PIPE, | ||
82 | stderr=subprocess.PIPE, | ||
83 | universal_newlines=True, | ||
84 | cwd=cwd, | ||
85 | env=env) | ||
86 | |||
87 | # execute the command and strip output | ||
88 | (_stdout, _stderr) = p.communicate(_cmd['input']) | ||
89 | if _cmd['strip']: | ||
90 | _stdout, _stderr = map(str.strip, [_stdout, _stderr]) | ||
91 | |||
92 | # generate the result | ||
93 | result = _cmd | ||
94 | result.update({'cmd':_command,'stdout':_stdout,'stderr':_stderr,'returncode':p.returncode}) | ||
95 | |||
96 | # launch exception if necessary | ||
97 | if not _cmd['ignore_error'] and p.returncode: | ||
98 | raise CmdException(result) | ||
99 | |||
100 | return result | ||
101 | |||
102 | def exec_cmds(cmds, cwd): | ||
103 | """ Executes commands | ||
104 | |||
105 | Input: | ||
106 | cmds: Array of commands | ||
107 | cwd: directory where commands are executed | ||
108 | |||
109 | Output: Array of output commands | ||
110 | """ | ||
111 | results = [] | ||
112 | _cmds = cmds | ||
113 | |||
114 | for cmd in _cmds: | ||
115 | result = exec_cmd(cmd, cwd) | ||
116 | results.append(result) | ||
117 | |||
118 | return results | ||
119 | |||
120 | def logger_create(name): | 17 | def logger_create(name): |
121 | logger = logging.getLogger(name) | 18 | logger = logging.getLogger(name) |
122 | loggerhandler = logging.StreamHandler() | 19 | loggerhandler = logging.StreamHandler() |
@@ -125,20 +22,6 @@ def logger_create(name): | |||
125 | logger.setLevel(logging.INFO) | 22 | logger.setLevel(logging.INFO) |
126 | return logger | 23 | return logger |
127 | 24 | ||
128 | def get_subject_prefix(path): | ||
129 | prefix = "" | ||
130 | mbox = mailbox.mbox(path) | ||
131 | |||
132 | if len(mbox): | ||
133 | subject = mbox[0]['subject'] | ||
134 | if subject: | ||
135 | pattern = re.compile(r"(\[.*\])", re.DOTALL) | ||
136 | match = pattern.search(subject) | ||
137 | if match: | ||
138 | prefix = match.group(1) | ||
139 | |||
140 | return prefix | ||
141 | |||
142 | def valid_branch(branch): | 25 | def valid_branch(branch): |
143 | """ Check if branch is valid name """ | 26 | """ Check if branch is valid name """ |
144 | lbranch = branch.lower() | 27 | lbranch = branch.lower() |
@@ -153,7 +36,17 @@ def valid_branch(branch): | |||
153 | 36 | ||
154 | def get_branch(path): | 37 | def get_branch(path): |
155 | """ Get the branch name from mbox """ | 38 | """ Get the branch name from mbox """ |
156 | fullprefix = get_subject_prefix(path) | 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 | |||
157 | branch, branches, valid_branches = None, [], [] | 50 | branch, branches, valid_branches = None, [], [] |
158 | 51 | ||
159 | if fullprefix: | 52 | if fullprefix: |