Skip to content

Instantly share code, notes, and snippets.

@cas--
Created November 3, 2016 19:12
Show Gist options
  • Save cas--/0ee1095c2de2e5c18b76afe69fc31d9a to your computer and use it in GitHub Desktop.
Save cas--/0ee1095c2de2e5c18b76afe69fc31d9a to your computer and use it in GitHub Desktop.
Python script to convert quotes in a `git format-patch -1 <sha1>` to apply to converted quotes branch `git am < <patch>`
import os
new_lines = []
os.chdir('/home/ubuntu/deluge.git/')
patchfile = '0001-Fix-pylint-warnings.patch'
with open(patchfile) as file_:
for line in file_.readlines():
line_strip = line.lstrip('-').lstrip('+').strip()
if '"' in line and not "'" in line and not '"""' in line and not '\\"' in line:
if '#' in line and '"' in line.split('#')[1]:
new_lines.append(line)
else:
new_lines.append(line.replace('"', "'"))
else:
new_lines.append(line)
with open(patchfile + '.new', 'w') as file_:
file_.write(''.join(new_lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment