Skip to content

Commit 8a2426d

Browse files
committed
Styling and annoyances
1 parent c0a1c45 commit 8a2426d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

tools/importer/importer.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/python
12
"""
23
Copyright (c) 2017-2019 ARM Limited. All rights reserved.
34
@@ -37,7 +38,7 @@
3738

3839
class StoreDir(argparse.Action):
3940
def __call__(self, parser, namespace, values, option_string=None):
40-
directory = os.path.abspath(values)
41+
directory = abspath(values)
4142
if not os.path.isdir(directory):
4243
raise argparse.ArgumentError(
4344
None, "The directory %s does not exist!" % directory)
@@ -46,8 +47,8 @@ def __call__(self, parser, namespace, values, option_string=None):
4647

4748
class StoreValidFile(argparse.Action):
4849
def __call__(self, parser, namespace, values, option_string=None):
49-
fn = os.path.abspath(values)
50-
if not os.path.isfile(fn):
50+
fn = abspath(values)
51+
if not isfile(fn):
5152
raise argparse.ArgumentError(
5253
None, "The file %s does not exist!" % fn)
5354
setattr(namespace, self.dest, fn)
@@ -67,7 +68,7 @@ def del_file(name):
6768
result.append(join(root, name))
6869
for f in result:
6970
os.remove(f)
70-
rel_log.debug("Deleted %s", os.path.relpath(file, ROOT))
71+
rel_log.debug("Deleted %s", os.path.relpath(f, ROOT))
7172

7273

7374
def copy_folder(src, dest):
@@ -79,7 +80,7 @@ def copy_folder(src, dest):
7980
files = os.listdir(src)
8081
for f in files:
8182
abs_src_file = join(src, f)
82-
if os.path.isfile(abs_src_file):
83+
if isfile(abs_src_file):
8384
abs_dst_file = join(dest, f)
8485
mkdir(dirname(abs_dst_file))
8586
copy_file(abs_src_file, abs_dst_file)
@@ -101,18 +102,18 @@ def run_cmd_with_output(command, exit_on_failure=False):
101102
output - The output of the command if it was successful, else empty string
102103
"""
103104
rel_log.debug('[Exec] %s', ' '.join(command))
104-
returncode = 0
105+
return_code = 0
105106
output = ""
106107
try:
107108
output = subprocess.check_output(command)
108109
except subprocess.CalledProcessError as e:
109-
returncode = e.returncode
110+
return_code = e.returncode
110111

111112
if exit_on_failure:
112113
rel_log.error("The command %s failed with return code: %s",
113-
(' '.join(command)), returncode)
114+
(' '.join(command)), return_code)
114115
sys.exit(1)
115-
return returncode, output
116+
return return_code, output
116117

117118

118119
def get_curr_sha(repo_path):
@@ -123,10 +124,15 @@ def get_curr_sha(repo_path):
123124
Returns:
124125
sha - last commit SHA
125126
"""
126-
repo_path = abspath(repo_path)
127+
127128
cmd = ['git', '-C', repo_path, 'log', '--pretty=format:%h', '-n', '1']
128129
_, _sha = run_cmd_with_output(cmd, exit_on_failure=True)
129130

131+
if not _sha:
132+
rel_log.error("Could not obtain latest SHA")
133+
sys.exit(1)
134+
135+
rel_log.info("%s SHA = %s", repo_path, sha)
130136
return _sha
131137

132138

@@ -157,20 +163,16 @@ def branch_checkout(name):
157163
rel_log.info("Checkout to branch %s", name)
158164

159165

160-
def get_last_cherry_pick_sha(branch):
166+
def get_last_cherry_pick_sha():
161167
"""
162168
SHA of last cherry pick commit is returned. SHA should be added to all
163169
cherry-pick commits with -x option.
164170
165171
Args:
166-
branch - Hash to be verified.
167172
Returns - SHA if found, else None
168173
"""
169-
cmd = ['git', 'checkout', branch]
170-
run_cmd_with_output(cmd, exit_on_failure=False)
171174

172-
sha = None
173-
get_commit = ['git', 'log', '-n', '1']
175+
get_commit = ['git', '-C', ROOT, 'log', '-n', '1']
174176
_, output = run_cmd_with_output(get_commit, exit_on_failure=True)
175177

176178
lines = output.splitlines()
@@ -282,7 +284,7 @@ def normalize_commit_sha(sha_lst):
282284
# Checkout the feature branch
283285
branch_checkout(branch)
284286
commit_sha = normalize_commit_sha(json_data["commit_sha"])
285-
last_sha = get_last_cherry_pick_sha(branch)
287+
last_sha = get_last_cherry_pick_sha()
286288

287289
# Few commits are already applied, check the next in sequence
288290
# and skip to next commit

0 commit comments

Comments
 (0)