diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-10-04 19:48:41 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-08-22 13:23:35 -0400 |
commit | 138e70b0d40609b896ab576a8f0ea23e23c7825b (patch) | |
tree | 4ae29b46fe42cbd65545d14a06874d4533319419 | |
parent | 2b2b4f9b14fdd4448200546f2a47d2603df30e38 (diff) |
scripts: rfr: Add file support
Add support for reading a file full of commit IDs/URLs. This
makes generating an RFR from a long list of commits easier in
some cases.
Change-Id: Id71173853e29d951048e8c3394ffce5d8b1eeb52
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1576523
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rwxr-xr-x | scripts/rfr | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/scripts/rfr b/scripts/rfr index 030a9895..27ed1927 100755 --- a/scripts/rfr +++ b/scripts/rfr | |||
@@ -13,7 +13,7 @@ import smtplib | |||
13 | 13 | ||
14 | from email.mime.text import MIMEText | 14 | from email.mime.text import MIMEText |
15 | 15 | ||
16 | VERSION = '1.0.0' | 16 | VERSION = '1.0.1' |
17 | 17 | ||
18 | # Gerrit commit URL formats. These are regular expressions to match the | 18 | # Gerrit commit URL formats. These are regular expressions to match the |
19 | # incoming URLs against. | 19 | # incoming URLs against. |
@@ -65,10 +65,12 @@ Otherwise it's treated as a git commit ID. | |||
65 | parser.add_argument('-t', '--to', action='append', default=[], | 65 | parser.add_argument('-t', '--to', action='append', default=[], |
66 | help='Specify an additional To: email address. ' | 66 | help='Specify an additional To: email address. ' |
67 | 'Can be repeated (-t a -t b).') | 67 | 'Can be repeated (-t a -t b).') |
68 | parser.add_argument('-F', '--file', action='store', default=None, | ||
69 | help='File with commits, one per line') | ||
68 | 70 | ||
69 | # Positionals: the gerrit URLs. | 71 | # Positionals: the gerrit URLs. |
70 | parser.add_argument('commits', metavar='Commit-IDs', | 72 | parser.add_argument('commits', metavar='Commit-IDs', |
71 | nargs='+', | 73 | nargs='*', |
72 | help=help_msg) | 74 | help=help_msg) |
73 | 75 | ||
74 | arg_parser = parser.parse_args() | 76 | arg_parser = parser.parse_args() |
@@ -89,6 +91,32 @@ def get_gerrit_url_id(cmt): | |||
89 | 91 | ||
90 | return None | 92 | return None |
91 | 93 | ||
94 | def read_commit_file(filp): | ||
95 | """ | ||
96 | Read a file full of commits and return a list of those commits. | ||
97 | """ | ||
98 | |||
99 | commits = [ ] | ||
100 | |||
101 | for line in filp: | ||
102 | |||
103 | line = line.strip() | ||
104 | |||
105 | # Skip empty lines and lines that start with a '#'. | ||
106 | if line.find('#') == 0 or line == '': | ||
107 | continue | ||
108 | |||
109 | # Otherwise append the line to the list of commits. This will append | ||
110 | # all the text, so in cases like: | ||
111 | # | ||
112 | # http://git-master/r/1540705 - my commit | ||
113 | # | ||
114 | # Anything after the first space in the line is ignored. This lets you | ||
115 | # add some descriptive text after the commit. | ||
116 | commits.append(line.split()[0]) | ||
117 | |||
118 | return commits | ||
119 | |||
92 | def gerrit_query(change): | 120 | def gerrit_query(change): |
93 | """ | 121 | """ |
94 | Query gerrit for the JSON change information. Return a python object | 122 | Query gerrit for the JSON change information. Return a python object |
@@ -303,6 +331,19 @@ def main(): | |||
303 | print('Version: %s' % VERSION) | 331 | print('Version: %s' % VERSION) |
304 | exit(0) | 332 | exit(0) |
305 | 333 | ||
334 | if arg_parser.file: | ||
335 | filp = open(arg_parser.file, 'r') | ||
336 | |||
337 | if arg_parser.commits: | ||
338 | arg_parser.commits.extend(read_commit_file(filp)) | ||
339 | else: | ||
340 | arg_parser.commits = read_commit_file(filp) | ||
341 | |||
342 | # Oops: no commits? | ||
343 | if not arg_parser.commits or len(arg_parser.commits) == 0: | ||
344 | print 'No commits!' | ||
345 | exit(-1) | ||
346 | |||
306 | # Builds a dictionary of Gerrit Change-Ids. From the Change-Ids we can then | 347 | # Builds a dictionary of Gerrit Change-Ids. From the Change-Ids we can then |
307 | # get the commit message and URL. | 348 | # get the commit message and URL. |
308 | # | 349 | # |
@@ -310,6 +351,7 @@ def main(): | |||
310 | # of the commits so that the user can choose the order of the patches based | 351 | # of the commits so that the user can choose the order of the patches based |
311 | # on the order in which they pass the commits. | 352 | # on the order in which they pass the commits. |
312 | for cmt in arg_parser.commits: | 353 | for cmt in arg_parser.commits: |
354 | |||
313 | if cmt[0] == 'I': | 355 | if cmt[0] == 'I': |
314 | info = commit_info_from_gerrit_change_id(cmt) | 356 | info = commit_info_from_gerrit_change_id(cmt) |
315 | elif get_gerrit_url_id(cmt): | 357 | elif get_gerrit_url_id(cmt): |