Proper documentation

pull/10505/head
Oren Cohen 2019-04-29 00:11:39 +03:00
parent 8a2426d6da
commit 6f19ba093a
No known key found for this signature in database
GPG Key ID: 6F54A3184C6F8FF9
1 changed files with 56 additions and 44 deletions

View File

@ -55,10 +55,13 @@ class StoreValidFile(argparse.Action):
def del_file(name): def del_file(name):
""" Delete the file in RTOS/CMSIS/features directory of mbed-os
Args:
name - name of the file
""" """
Delete the file in RTOS/CMSIS/features directory of mbed-os.
:param name: Name of the file.
:return: None.
"""
result = [] result = []
search_path = [join(ROOT, 'rtos'), join(ROOT, 'cmsis'), search_path = [join(ROOT, 'rtos'), join(ROOT, 'cmsis'),
join(ROOT, 'features')] join(ROOT, 'features')]
@ -71,36 +74,38 @@ def del_file(name):
rel_log.debug("Deleted %s", os.path.relpath(f, ROOT)) rel_log.debug("Deleted %s", os.path.relpath(f, ROOT))
def copy_folder(src, dest): def copy_folder(src, dst):
""" Copy contents of folder in mbed-os listed path
Args:
src - src folder path
dest - destination folder path
""" """
Copy contents of folder in mbed-os listed path.
:param src: Source folder path.
:param dst: Destination folder path.
:return: None.
"""
files = os.listdir(src) files = os.listdir(src)
for f in files: for f in files:
abs_src_file = join(src, f) abs_src_file = join(src, f)
if isfile(abs_src_file): if isfile(abs_src_file):
abs_dst_file = join(dest, f) abs_dst_file = join(dst, f)
mkdir(dirname(abs_dst_file)) mkdir(dirname(abs_dst_file))
copy_file(abs_src_file, abs_dst_file) copy_file(abs_src_file, abs_dst_file)
def run_cmd_with_output(command, exit_on_failure=False): def run_cmd_with_output(command, exit_on_failure=False):
""" Passes a command to the system and returns a True/False result once the """
Passes a command to the system and returns a True/False result once the
command has been executed, indicating success/failure. If the command was command has been executed, indicating success/failure. If the command was
successful then the output from the command is returned to the caller. successful then the output from the command is returned to the caller.
Commands are passed as a list of tokens. Commands are passed as a list of tokens.
E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v'] E.g. The command 'git remote -v' would be passed in as:
['git', 'remote', '-v']
Args: :param command: System command as a list of tokens.
command - system command as a list of tokens :param exit_on_failure: Exit the program on failure (default=False)
exit_on_failure - If True exit the program on failure (default = False) :return: Command return status code and output as tuple.
Returns:
result - True/False indicating the success/failure of the command
output - The output of the command if it was successful, else empty string
""" """
rel_log.debug('[Exec] %s', ' '.join(command)) rel_log.debug('[Exec] %s', ' '.join(command))
return_code = 0 return_code = 0
output = "" output = ""
@ -117,12 +122,11 @@ def run_cmd_with_output(command, exit_on_failure=False):
def get_curr_sha(repo_path): def get_curr_sha(repo_path):
""" Gets the latest SHA for the specified repo """
Args: Gets the latest SHA for the specified repo.
repo_path - path to the repository
Returns: :param repo_path: Path to a git repository.
sha - last commit SHA :return: Last commit SHA.
""" """
cmd = ['git', '-C', repo_path, 'log', '--pretty=format:%h', '-n', '1'] cmd = ['git', '-C', repo_path, 'log', '--pretty=format:%h', '-n', '1']
@ -137,27 +141,27 @@ def get_curr_sha(repo_path):
def branch_exists(name): def branch_exists(name):
""" Check if branch already exists in mbed-os local repository. """
It will not verify if branch is present in remote repository. Check if branch already exists in mbed-os local repository.
Args:
name - branch name :param name: Branch name.
Returns: :return: True if branch is already present, False otherwise.
True - If branch is already present
""" """
cmd = ['git', 'branch'] cmd = ['git', '-C', ROOT, 'branch']
_, output = run_cmd_with_output(cmd, exit_on_failure=False) _, output = run_cmd_with_output(cmd, exit_on_failure=False)
if name in output:
return True return name in output
return False
def branch_checkout(name): def branch_checkout(name):
""" """
Checkout the required branch Checkout the required git branch.
Args:
name - branch name :param name: Branch to checkout.
:return: None.
""" """
cmd = ['git', 'checkout', name] cmd = ['git', 'checkout', name]
_, _ = run_cmd_with_output(cmd, exit_on_failure=False) _, _ = run_cmd_with_output(cmd, exit_on_failure=False)
rel_log.info("Checkout to branch %s", name) rel_log.info("Checkout to branch %s", name)
@ -165,11 +169,10 @@ def branch_checkout(name):
def get_last_cherry_pick_sha(): def get_last_cherry_pick_sha():
""" """
SHA of last cherry pick commit is returned. SHA should be added to all Finds the SHA of last cherry picked commit.
cherry-pick commits with -x option. SHA should be added to cherry-pick commits with -x option.
Args: :return: SHA if found, None otherwise.
Returns - SHA if found, else None
""" """
get_commit = ['git', '-C', ROOT, 'log', '-n', '1'] get_commit = ['git', '-C', ROOT, 'log', '-n', '1']
@ -185,6 +188,15 @@ def get_last_cherry_pick_sha():
def normalize_commit_sha(sha_lst): def normalize_commit_sha(sha_lst):
"""
The commit_sha section of the config file can hold commits in 2 ways:
* "<SHA>" - E.g. "428acae1b2ac15c3ad523e8d40755a9301220822".
* {"sha": "<SHA>", "msg": "<HELP>"} - E.g.
{"sha": "d9d622afe0ca8c7ab9d24c17f9fe59b54dcc61c9", "msg": "Fix ..."}.
:param sha_lst: JSON data from config file.
:return: list of commit SHA.
"""
return [_sha['sha'] if isinstance(_sha, dict) else _sha for _sha in sha_lst] return [_sha['sha'] if isinstance(_sha, dict) else _sha for _sha in sha_lst]