Permalink
Browse files

Fix revert_display_name.py to actually work

  • Loading branch information...
1 parent d902bde commit c09d566708db5712f16d7656e5bb45f1a23eb102 @kemitche committed Jun 18, 2012
Showing with 14 additions and 18 deletions.
  1. +14 −18 revert_display_name.py
View
@@ -6,30 +6,26 @@
'''
import fileinput
import os
+import subprocess
import sys
-def read_display_name_lines(filename, backup_suffix=".bak"):
- lines = []
- with open(filename + backup_suffix) as bak:
- for line in bak:
- if line.startswith('"Display-Name'):
- lines.append(line)
- if len(lines) >= 2:
- break
- else:
- raise ValueError("Could not find Display-Name lines "
- "in: %s" % bak.name)
+COMMAND = "git show HEAD:%s | grep -i display-name"
+def get_display_name(filename):
+ lines = subprocess.check_output(COMMAND % filename, shell=True)
return lines
+def has_display_name(filename):
+ with open(filename) as f:
+ contents = f.read().lower()
+ return '\n"display-name' in contents
+
+
def write_display_name_lines(filename, lines):
written = False
- try:
- read_display_name_lines(filename, backup_suffix="")
- except ValueError:
- pass
- else:
- raise ValueError("%s already has Display-Name lines" % filename)
+ if has_display_name(filename):
+ print "%s already has Display-Name lines" % filename
+ return
for line in fileinput.input(filename, inplace=1, backup=".dn.bak"):
if not written and line.startswith('"Content-Transfer-Encoding'):
for l in lines:
@@ -40,7 +36,7 @@ def write_display_name_lines(filename, lines):
def handle_lang(lang_path, po_file="r2.po"):
filename = os.path.join(lang_path, po_file)
- lines = read_display_name_lines(filename)
+ lines = get_display_name(filename)
write_display_name_lines(filename, lines)

0 comments on commit c09d566

Please sign in to comment.