Created
May 19, 2012 02:23
-
-
Save marciomazza/2728705 to your computer and use it in GitHub Desktop.
reverting accidental replace 'tab' -> ' ' in collective.developermanual b59bd0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reverting accidental replace 'tab' -> ' ' in https://github.com/collective/collective.developermanual/commit/b59bd0 | |
import difflib | |
def agregar(lines): | |
diffs = [] | |
d = [] | |
for l in lines: | |
if l.startswith('diff --git'): | |
diffs.append(d) | |
d = [] | |
d.append(l) | |
return diffs[1:] | |
def tab_diffs(d): | |
i = iter(d[5:]) | |
for l in i: | |
if l.startswith('-'): | |
s1, s2 = l[1:], i.next()[1:] | |
s = difflib.SequenceMatcher(None, s1, s2) | |
if [(tag, s1[i1:i2], s2[j1:j2]) for tag, i1, i2, j1, j2 in s.get_opcodes() if tag == 'replace' and s1[i1:i2] == 'tab']: | |
yield s1, s2 | |
mv = {'source/models/database.txt': 'source/persistency/database.rst', | |
'source/models/index.txt': 'source/forms/index.rst', | |
'source/models/schema.txt': 'source/forms/schemas.rst', | |
'source/introduction/customizing_plone.txt': 'source/components/customizing_plone.rst' | |
} | |
def movido(nome): | |
if nome in mv: | |
return mv[nome] | |
else: | |
return nome.replace('.txt', '.rst') | |
def pegar(): | |
out = get_ipython().getoutput(u'git show b59bd0') | |
for d in agregar(out): | |
diffs = list(tab_diffs(d)) | |
if diffs: | |
nome = movido(d[3][6:]) | |
yield nome, diffs | |
def alterar(): | |
for nome, diffs in pegar(): | |
try: | |
nome = movido(nome) | |
with open(nome) as f: | |
conteudo = f.read() | |
for s1,s2 in diffs: | |
conteudo = conteudo.replace(s2, s1) | |
with open(nome, 'w') as f: | |
f.writelines(conteudo) | |
except: | |
print '-------------------- O_O this one --------------------' | |
print nome | |
for s1,s2 in diffs: | |
print s1 | |
print s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment