@@ -55,10 +55,13 @@ def __call__(self, parser, namespace, values, option_string=None):
55
55
56
56
57
57
def del_file (name ):
58
- """ Delete the file in RTOS/CMSIS/features directory of mbed-os
59
- Args:
60
- name - name of the file
61
58
"""
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
+
62
65
result = []
63
66
search_path = [join (ROOT , 'rtos' ), join (ROOT , 'cmsis' ),
64
67
join (ROOT , 'features' )]
@@ -71,36 +74,38 @@ def del_file(name):
71
74
rel_log .debug ("Deleted %s" , os .path .relpath (f , ROOT ))
72
75
73
76
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.
79
84
"""
85
+
80
86
files = os .listdir (src )
81
87
for f in files :
82
88
abs_src_file = join (src , f )
83
89
if isfile (abs_src_file ):
84
- abs_dst_file = join (dest , f )
90
+ abs_dst_file = join (dst , f )
85
91
mkdir (dirname (abs_dst_file ))
86
92
copy_file (abs_src_file , abs_dst_file )
87
93
88
94
89
95
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
103
96
"""
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
+
104
109
rel_log .debug ('[Exec] %s' , ' ' .join (command ))
105
110
return_code = 0
106
111
output = ""
@@ -117,12 +122,11 @@ def run_cmd_with_output(command, exit_on_failure=False):
117
122
118
123
119
124
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.
123
127
124
- Returns:
125
- sha - last commit SHA
128
+ :param repo_path: Path to a git repository.
129
+ :return: Last commit SHA.
126
130
"""
127
131
128
132
cmd = ['git' , '-C' , repo_path , 'log' , '--pretty=format:%h' , '-n' , '1' ]
@@ -137,39 +141,38 @@ def get_curr_sha(repo_path):
137
141
138
142
139
143
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
146
144
"""
145
+ Check if branch already exists in mbed-os local repository.
147
146
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' ]
149
152
_ , 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
153
155
154
156
155
157
def branch_checkout (name ):
156
158
"""
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.
160
163
"""
164
+
161
165
cmd = ['git' , 'checkout' , name ]
162
166
_ , _ = run_cmd_with_output (cmd , exit_on_failure = False )
163
167
rel_log .info ("Checkout to branch %s" , name )
164
168
165
169
166
170
def get_last_cherry_pick_sha ():
167
171
"""
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.
170
174
171
- Args:
172
- Returns - SHA if found, else None
175
+ :return: SHA if found, None otherwise.
173
176
"""
174
177
175
178
get_commit = ['git' , '-C' , ROOT , 'log' , '-n' , '1' ]
@@ -185,6 +188,15 @@ def get_last_cherry_pick_sha():
185
188
186
189
187
190
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
+ """
188
200
return [_sha ['sha' ] if isinstance (_sha , dict ) else _sha for _sha in sha_lst ]
189
201
190
202
0 commit comments