1
+ #!/usr/bin/python
1
2
"""
2
3
Copyright (c) 2017-2019 ARM Limited. All rights reserved.
3
4
37
38
38
39
class StoreDir (argparse .Action ):
39
40
def __call__ (self , parser , namespace , values , option_string = None ):
40
- directory = os . path . abspath (values )
41
+ directory = abspath (values )
41
42
if not os .path .isdir (directory ):
42
43
raise argparse .ArgumentError (
43
44
None , "The directory %s does not exist!" % directory )
@@ -46,8 +47,8 @@ def __call__(self, parser, namespace, values, option_string=None):
46
47
47
48
class StoreValidFile (argparse .Action ):
48
49
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 ):
51
52
raise argparse .ArgumentError (
52
53
None , "The file %s does not exist!" % fn )
53
54
setattr (namespace , self .dest , fn )
@@ -67,7 +68,7 @@ def del_file(name):
67
68
result .append (join (root , name ))
68
69
for f in result :
69
70
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 ))
71
72
72
73
73
74
def copy_folder (src , dest ):
@@ -79,7 +80,7 @@ def copy_folder(src, dest):
79
80
files = os .listdir (src )
80
81
for f in files :
81
82
abs_src_file = join (src , f )
82
- if os . path . isfile (abs_src_file ):
83
+ if isfile (abs_src_file ):
83
84
abs_dst_file = join (dest , f )
84
85
mkdir (dirname (abs_dst_file ))
85
86
copy_file (abs_src_file , abs_dst_file )
@@ -101,18 +102,18 @@ def run_cmd_with_output(command, exit_on_failure=False):
101
102
output - The output of the command if it was successful, else empty string
102
103
"""
103
104
rel_log .debug ('[Exec] %s' , ' ' .join (command ))
104
- returncode = 0
105
+ return_code = 0
105
106
output = ""
106
107
try :
107
108
output = subprocess .check_output (command )
108
109
except subprocess .CalledProcessError as e :
109
- returncode = e .returncode
110
+ return_code = e .returncode
110
111
111
112
if exit_on_failure :
112
113
rel_log .error ("The command %s failed with return code: %s" ,
113
- (' ' .join (command )), returncode )
114
+ (' ' .join (command )), return_code )
114
115
sys .exit (1 )
115
- return returncode , output
116
+ return return_code , output
116
117
117
118
118
119
def get_curr_sha (repo_path ):
@@ -123,10 +124,15 @@ def get_curr_sha(repo_path):
123
124
Returns:
124
125
sha - last commit SHA
125
126
"""
126
- repo_path = abspath ( repo_path )
127
+
127
128
cmd = ['git' , '-C' , repo_path , 'log' , '--pretty=format:%h' , '-n' , '1' ]
128
129
_ , _sha = run_cmd_with_output (cmd , exit_on_failure = True )
129
130
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 )
130
136
return _sha
131
137
132
138
@@ -157,20 +163,16 @@ def branch_checkout(name):
157
163
rel_log .info ("Checkout to branch %s" , name )
158
164
159
165
160
- def get_last_cherry_pick_sha (branch ):
166
+ def get_last_cherry_pick_sha ():
161
167
"""
162
168
SHA of last cherry pick commit is returned. SHA should be added to all
163
169
cherry-pick commits with -x option.
164
170
165
171
Args:
166
- branch - Hash to be verified.
167
172
Returns - SHA if found, else None
168
173
"""
169
- cmd = ['git' , 'checkout' , branch ]
170
- run_cmd_with_output (cmd , exit_on_failure = False )
171
174
172
- sha = None
173
- get_commit = ['git' , 'log' , '-n' , '1' ]
175
+ get_commit = ['git' , '-C' , ROOT , 'log' , '-n' , '1' ]
174
176
_ , output = run_cmd_with_output (get_commit , exit_on_failure = True )
175
177
176
178
lines = output .splitlines ()
@@ -282,7 +284,7 @@ def normalize_commit_sha(sha_lst):
282
284
# Checkout the feature branch
283
285
branch_checkout (branch )
284
286
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 ()
286
288
287
289
# Few commits are already applied, check the next in sequence
288
290
# and skip to next commit
0 commit comments