X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=diff2html.py;h=92bbf362acf9a1b55b073c842181caa3112f2a59;hb=c23d783c8f55be1471c90c51b9bbab4dd302e7c9;hp=dc000eef6b1b12b8a1634864e4863adc2eed910a;hpb=0ca475f9e41664da1195d4582567d52be5ab24d8;p=diff2html.git
diff --git a/diff2html.py b/diff2html.py
index dc000ee..92bbf36 100644
--- a/diff2html.py
+++ b/diff2html.py
@@ -35,7 +35,7 @@
# and display those directly.
-import sys, re, htmlentitydefs, getopt, StringIO, codecs
+import sys, re, htmlentitydefs, getopt, StringIO, codecs, datetime
# minimum line size, we add a zero-sized breakable space every
# LINESIZE characters
@@ -43,32 +43,48 @@ linesize = 20
tabsize = 8
show_CR = False
encoding = "utf-8"
+lang = "en"
+desc = "File comparison"
+dtnow = datetime.datetime.now()
+modified_date = "%s+01:00"%dtnow.isoformat()
html_hdr = """
-
-
-
- HTML Diff
-
-
-
+
+
+
+
+
+ HTML Diff{0}
+
+
+
+
+
+
+
+
+
"""
html_footer = """
+
"""
@@ -295,14 +311,15 @@ def empty_buffer(output_file):
buf = []
-def parse_input(input_file, output_file,
+def parse_input(input_file, output_file, input_file_name, output_file_name,
exclude_headers, show_hunk_infos):
global add_cpt, del_cpt
global line1, line2
global hunk_off1, hunk_size1, hunk_off2, hunk_size2
if not exclude_headers:
- output_file.write(html_hdr.format(encoding).encode(encoding))
+ title_suffix = ' ' + input_file_name
+ output_file.write(html_hdr.format(title_suffix, encoding, desc, "", modified_date, lang).encode(encoding))
output_file.write(table_hdr.encode(encoding))
while True:
@@ -363,7 +380,7 @@ def parse_input(input_file, output_file,
empty_buffer(output_file)
output_file.write(table_footer.encode(encoding))
if not exclude_headers:
- output_file.write(html_footer.encode(encoding))
+ output_file.write(html_footer.format("", dtnow.strftime("%d.%m.%Y")).encode(encoding))
def usage():
@@ -391,8 +408,8 @@ def main():
global show_CR
global encoding
- input_file = sys.stdin
- output_file = sys.stdout
+ input_file_name = ''
+ output_file_name = ''
exclude_headers = False
show_hunk_infos = False
@@ -415,8 +432,10 @@ def main():
encoding = a
elif o in ("-i", "--input"):
input_file = codecs.open(a, "r", encoding)
+ input_file_name = a
elif o in ("-o", "--output"):
output_file = codecs.open(a, "w")
+ output_file_name = a
elif o in ("-x", "--exclude-html-headers"):
exclude_headers = True
elif o in ("-t", "--tabsize"):
@@ -429,14 +448,23 @@ def main():
show_hunk_infos = True
else:
assert False, "unhandled option"
- parse_input(input_file, output_file,
+
+ # Use stdin if not input file is set
+ if not ('input_file' in locals()):
+ input_file = codecs.getreader(encoding)(sys.stdin)
+
+ # Use stdout if not output file is set
+ if not ('output_file' in locals()):
+ output_file = codecs.getwriter(encoding)(sys.stdout)
+
+ parse_input(input_file, output_file, input_file_name, output_file_name,
exclude_headers, show_hunk_infos)
def parse_from_memory(txt, exclude_headers, show_hunk_infos):
" Parses diff from memory and returns a string with html "
input_stream = StringIO.StringIO(txt)
output_stream = StringIO.StringIO()
- parse_input(input_stream, output_stream, exclude_headers, show_hunk_infos)
+ parse_input(input_stream, output_stream, '', '', exclude_headers, show_hunk_infos)
return output_stream.getvalue()