Skip to content

Commit 6f19ba0

Browse files
committed
Proper documentation
1 parent 8a2426d commit 6f19ba0

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

tools/importer/importer.py

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ def __call__(self, parser, namespace, values, option_string=None):
5555

5656

5757
def del_file(name):
58-
""" Delete the file in RTOS/CMSIS/features directory of mbed-os
59-
Args:
60-
name - name of the file
6158
"""
59+
Delete the file in RTOS/CMSIS/features directory of mbed-os.
60+
61+
:param name: Name of the file.
62+
:return: None.
63+
"""
64+
6265
result = []
6366
search_path = [join(ROOT, 'rtos'), join(ROOT, 'cmsis'),
6467
join(ROOT, 'features')]
@@ -71,36 +74,38 @@ def del_file(name):
7174
rel_log.debug("Deleted %s", os.path.relpath(f, ROOT))
7275

7376

74-
def copy_folder(src, dest):
75-
""" Copy contents of folder in mbed-os listed path
76-
Args:
77-
src - src folder path
78-
dest - destination folder path
77+
def copy_folder(src, dst):
78+
"""
79+
Copy contents of folder in mbed-os listed path.
80+
81+
:param src: Source folder path.
82+
:param dst: Destination folder path.
83+
:return: None.
7984
"""
85+
8086
files = os.listdir(src)
8187
for f in files:
8288
abs_src_file = join(src, f)
8389
if isfile(abs_src_file):
84-
abs_dst_file = join(dest, f)
90+
abs_dst_file = join(dst, f)
8591
mkdir(dirname(abs_dst_file))
8692
copy_file(abs_src_file, abs_dst_file)
8793

8894

8995
def run_cmd_with_output(command, exit_on_failure=False):
90-
""" Passes a command to the system and returns a True/False result once the
91-
command has been executed, indicating success/failure. If the command was
92-
successful then the output from the command is returned to the caller.
93-
Commands are passed as a list of tokens.
94-
E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v']
95-
96-
Args:
97-
command - system command as a list of tokens
98-
exit_on_failure - If True exit the program on failure (default = False)
99-
100-
Returns:
101-
result - True/False indicating the success/failure of the command
102-
output - The output of the command if it was successful, else empty string
10396
"""
97+
Passes a command to the system and returns a True/False result once the
98+
command has been executed, indicating success/failure. If the command was
99+
successful then the output from the command is returned to the caller.
100+
Commands are passed as a list of tokens.
101+
E.g. The command 'git remote -v' would be passed in as:
102+
['git', 'remote', '-v']
103+
104+
:param command: System command as a list of tokens.
105+
:param exit_on_failure: Exit the program on failure (default=False)
106+
:return: Command return status code and output as tuple.
107+
"""
108+
104109
rel_log.debug('[Exec] %s', ' '.join(command))
105110
return_code = 0
106111
output = ""
@@ -117,12 +122,11 @@ def run_cmd_with_output(command, exit_on_failure=False):
117122

118123

119124
def get_curr_sha(repo_path):
120-
""" Gets the latest SHA for the specified repo
121-
Args:
122-
repo_path - path to the repository
125+
"""
126+
Gets the latest SHA for the specified repo.
123127
124-
Returns:
125-
sha - last commit SHA
128+
:param repo_path: Path to a git repository.
129+
:return: Last commit SHA.
126130
"""
127131

128132
cmd = ['git', '-C', repo_path, 'log', '--pretty=format:%h', '-n', '1']
@@ -137,39 +141,38 @@ def get_curr_sha(repo_path):
137141

138142

139143
def branch_exists(name):
140-
""" Check if branch already exists in mbed-os local repository.
141-
It will not verify if branch is present in remote repository.
142-
Args:
143-
name - branch name
144-
Returns:
145-
True - If branch is already present
146144
"""
145+
Check if branch already exists in mbed-os local repository.
147146
148-
cmd = ['git', 'branch']
147+
:param name: Branch name.
148+
:return: True if branch is already present, False otherwise.
149+
"""
150+
151+
cmd = ['git', '-C', ROOT, 'branch']
149152
_, output = run_cmd_with_output(cmd, exit_on_failure=False)
150-
if name in output:
151-
return True
152-
return False
153+
154+
return name in output
153155

154156

155157
def branch_checkout(name):
156158
"""
157-
Checkout the required branch
158-
Args:
159-
name - branch name
159+
Checkout the required git branch.
160+
161+
:param name: Branch to checkout.
162+
:return: None.
160163
"""
164+
161165
cmd = ['git', 'checkout', name]
162166
_, _ = run_cmd_with_output(cmd, exit_on_failure=False)
163167
rel_log.info("Checkout to branch %s", name)
164168

165169

166170
def get_last_cherry_pick_sha():
167171
"""
168-
SHA of last cherry pick commit is returned. SHA should be added to all
169-
cherry-pick commits with -x option.
172+
Finds the SHA of last cherry picked commit.
173+
SHA should be added to cherry-pick commits with -x option.
170174
171-
Args:
172-
Returns - SHA if found, else None
175+
:return: SHA if found, None otherwise.
173176
"""
174177

175178
get_commit = ['git', '-C', ROOT, 'log', '-n', '1']
@@ -185,6 +188,15 @@ def get_last_cherry_pick_sha():
185188

186189

187190
def normalize_commit_sha(sha_lst):
191+
"""
192+
The commit_sha section of the config file can hold commits in 2 ways:
193+
* "<SHA>" - E.g. "428acae1b2ac15c3ad523e8d40755a9301220822".
194+
* {"sha": "<SHA>", "msg": "<HELP>"} - E.g.
195+
{"sha": "d9d622afe0ca8c7ab9d24c17f9fe59b54dcc61c9", "msg": "Fix ..."}.
196+
197+
:param sha_lst: JSON data from config file.
198+
:return: list of commit SHA.
199+
"""
188200
return [_sha['sha'] if isinstance(_sha, dict) else _sha for _sha in sha_lst]
189201

190202

0 commit comments

Comments
 (0)