mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 12:29:55 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
9c4e350797
commit
cec77d941e
+11
-118
@@ -14,109 +14,6 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import mailbox
|
import mailbox
|
||||||
|
|
||||||
class CmdException(Exception):
|
|
||||||
""" Simple exception class where its attributes are the ones passed when instantiated """
|
|
||||||
def __init__(self, cmd):
|
|
||||||
self._cmd = cmd
|
|
||||||
def __getattr__(self, name):
|
|
||||||
value = None
|
|
||||||
if self._cmd.has_key(name):
|
|
||||||
value = self._cmd[name]
|
|
||||||
return value
|
|
||||||
|
|
||||||
def exec_cmd(cmd, cwd, ignore_error=False, input=None, strip=True, updateenv={}):
|
|
||||||
"""
|
|
||||||
Input:
|
|
||||||
|
|
||||||
cmd: dict containing the following keys:
|
|
||||||
|
|
||||||
cmd : the command itself as an array of strings
|
|
||||||
ignore_error: if False, no exception is raised
|
|
||||||
strip: indicates if strip is done on the output (stdout and stderr)
|
|
||||||
input: input data to the command (stdin)
|
|
||||||
updateenv: environment variables to be appended to the current
|
|
||||||
process environment variables
|
|
||||||
|
|
||||||
NOTE: keys 'ignore_error' and 'input' are optional; if not included,
|
|
||||||
the defaults are the ones specify in the arguments
|
|
||||||
cwd: directory where commands are executed
|
|
||||||
ignore_error: raise CmdException if command fails to execute and
|
|
||||||
this value is False
|
|
||||||
input: input data (stdin) for the command
|
|
||||||
|
|
||||||
Output: dict containing the following keys:
|
|
||||||
|
|
||||||
cmd: the same as input
|
|
||||||
ignore_error: the same as input
|
|
||||||
strip: the same as input
|
|
||||||
input: the same as input
|
|
||||||
stdout: Standard output after command's execution
|
|
||||||
stderr: Standard error after command's execution
|
|
||||||
returncode: Return code after command's execution
|
|
||||||
|
|
||||||
"""
|
|
||||||
cmddefaults = {
|
|
||||||
'cmd':'',
|
|
||||||
'ignore_error':ignore_error,
|
|
||||||
'strip':strip,
|
|
||||||
'input':input,
|
|
||||||
'updateenv':updateenv,
|
|
||||||
}
|
|
||||||
|
|
||||||
# update input values if necessary
|
|
||||||
cmddefaults.update(cmd)
|
|
||||||
|
|
||||||
_cmd = cmddefaults
|
|
||||||
|
|
||||||
if not _cmd['cmd']:
|
|
||||||
raise CmdException({'cmd':None, 'stderr':'no command given'})
|
|
||||||
|
|
||||||
# update the environment
|
|
||||||
env = os.environ
|
|
||||||
env.update(_cmd['updateenv'])
|
|
||||||
|
|
||||||
_command = [e for e in _cmd['cmd']]
|
|
||||||
p = subprocess.Popen(_command,
|
|
||||||
stdin=subprocess.PIPE,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE,
|
|
||||||
universal_newlines=True,
|
|
||||||
cwd=cwd,
|
|
||||||
env=env)
|
|
||||||
|
|
||||||
# execute the command and strip output
|
|
||||||
(_stdout, _stderr) = p.communicate(_cmd['input'])
|
|
||||||
if _cmd['strip']:
|
|
||||||
_stdout, _stderr = map(str.strip, [_stdout, _stderr])
|
|
||||||
|
|
||||||
# generate the result
|
|
||||||
result = _cmd
|
|
||||||
result.update({'cmd':_command,'stdout':_stdout,'stderr':_stderr,'returncode':p.returncode})
|
|
||||||
|
|
||||||
# launch exception if necessary
|
|
||||||
if not _cmd['ignore_error'] and p.returncode:
|
|
||||||
raise CmdException(result)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def exec_cmds(cmds, cwd):
|
|
||||||
""" Executes commands
|
|
||||||
|
|
||||||
Input:
|
|
||||||
cmds: Array of commands
|
|
||||||
cwd: directory where commands are executed
|
|
||||||
|
|
||||||
Output: Array of output commands
|
|
||||||
"""
|
|
||||||
results = []
|
|
||||||
_cmds = cmds
|
|
||||||
|
|
||||||
for cmd in _cmds:
|
|
||||||
result = exec_cmd(cmd, cwd)
|
|
||||||
results.append(result)
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
def logger_create(name):
|
def logger_create(name):
|
||||||
logger = logging.getLogger(name)
|
logger = logging.getLogger(name)
|
||||||
loggerhandler = logging.StreamHandler()
|
loggerhandler = logging.StreamHandler()
|
||||||
@@ -125,20 +22,6 @@ def logger_create(name):
|
|||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
def get_subject_prefix(path):
|
|
||||||
prefix = ""
|
|
||||||
mbox = mailbox.mbox(path)
|
|
||||||
|
|
||||||
if len(mbox):
|
|
||||||
subject = mbox[0]['subject']
|
|
||||||
if subject:
|
|
||||||
pattern = re.compile(r"(\[.*\])", re.DOTALL)
|
|
||||||
match = pattern.search(subject)
|
|
||||||
if match:
|
|
||||||
prefix = match.group(1)
|
|
||||||
|
|
||||||
return prefix
|
|
||||||
|
|
||||||
def valid_branch(branch):
|
def valid_branch(branch):
|
||||||
""" Check if branch is valid name """
|
""" Check if branch is valid name """
|
||||||
lbranch = branch.lower()
|
lbranch = branch.lower()
|
||||||
@@ -153,7 +36,17 @@ def valid_branch(branch):
|
|||||||
|
|
||||||
def get_branch(path):
|
def get_branch(path):
|
||||||
""" Get the branch name from mbox """
|
""" Get the branch name from mbox """
|
||||||
fullprefix = get_subject_prefix(path)
|
fullprefix = ""
|
||||||
|
mbox = mailbox.mbox(path)
|
||||||
|
|
||||||
|
if len(mbox):
|
||||||
|
subject = mbox[0]['subject']
|
||||||
|
if subject:
|
||||||
|
pattern = re.compile(r"(\[.*\])", re.DOTALL)
|
||||||
|
match = pattern.search(subject)
|
||||||
|
if match:
|
||||||
|
fullprefix = match.group(1)
|
||||||
|
|
||||||
branch, branches, valid_branches = None, [], []
|
branch, branches, valid_branches = None, [], []
|
||||||
|
|
||||||
if fullprefix:
|
if fullprefix:
|
||||||
|
|||||||
Reference in New Issue
Block a user