Revert "scripts: fix pylint in upload_prebuilts.py"
This reverts commit 0cd98cc5f8a49fd809799f2e862c56783b818e5e.
Reason for revert: breaks sdk builder b/235432117
Original change's description:
> scripts: fix pylint in upload_prebuilts.py
>
> BUG=b:234868433
> TEST=cros lint
>
> Change-Id: Ie40140e1ba0dec0deb1896182e5106cf4e4a2f85
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3692196
> Commit-Queue: Sergey Frolov <sfrolov@google.com>
> Reviewed-by: Sloan Johnson <sloanjohnson@google.com>
> Auto-Submit: Sergey Frolov <sfrolov@google.com>
> Tested-by: Sergey Frolov <sfrolov@google.com>
Bug: b:234868433
Change-Id: Id753e7db9b1b8b822470b98bf5eb4c5d54483c88
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3697808
Commit-Queue: Jack Neus <jackneus@google.com>
Reviewed-by: George Engelbrecht <engeg@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
diff --git a/scripts/upload_prebuilts.py b/scripts/upload_prebuilts.py
index 1c12fd3..a30b64f 100644
--- a/scripts/upload_prebuilts.py
+++ b/scripts/upload_prebuilts.py
@@ -108,35 +108,39 @@
Returns:
True if changes were made to the file.
"""
- with open(filename, 'a+') as file_fh:
- file_lines = []
- found = False
- made_changes = False
- keyval_str = '%(key)s=%(value)s'
- for line in file_fh:
- # Strip newlines from end of line. We already add newlines below.
- line = line.rstrip('\n')
+ if os.path.exists(filename):
+ file_fh = open(filename)
+ else:
+ file_fh = open(filename, 'w+')
+ file_lines = []
+ found = False
+ made_changes = False
+ keyval_str = '%(key)s=%(value)s'
+ for line in file_fh:
+ # Strip newlines from end of line. We already add newlines below.
+ line = line.rstrip('\n')
- if len(line.split('=')) != 2:
- # Skip any line that doesn't fit key=val.
- file_lines.append(line)
- continue
+ if len(line.split('=')) != 2:
+ # Skip any line that doesn't fit key=val.
+ file_lines.append(line)
+ continue
- file_var, file_val = line.split('=')
- if file_var == key:
- found = True
- print('Updating %s=%s to %s="%s"' % (file_var, file_val, key, value))
- value = '"%s"' % value
- made_changes |= (file_val != value)
- file_lines.append(keyval_str % {'key': key, 'value': value})
- else:
- file_lines.append(keyval_str % {'key': file_var, 'value': file_val})
-
- if not found:
+ file_var, file_val = line.split('=')
+ if file_var == key:
+ found = True
+ print('Updating %s=%s to %s="%s"' % (file_var, file_val, key, value))
value = '"%s"' % value
- made_changes = True
+ made_changes |= (file_val != value)
file_lines.append(keyval_str % {'key': key, 'value': value})
+ else:
+ file_lines.append(keyval_str % {'key': file_var, 'value': file_val})
+ if not found:
+ value = '"%s"' % value
+ made_changes = True
+ file_lines.append(keyval_str % {'key': key, 'value': value})
+
+ file_fh.close()
# write out new file
osutils.WriteFile(filename, '\n'.join(file_lines) + '\n')
return made_changes