How to generate HTML color diff from git using python
Question: So I figured out creating HTML git diff i can embed in email but don't know
why is it all being spit in one line ?

here is how I did it!!

    
    
    import sys
    import subprocess
    import os
    
    from ansi2html.converter import Ansi2HTMLConverter
    
    
    
    ansiText =  os.path.expanduser('~/Desktop/colorDiff')
    
    
    pr = subprocess.Popen( "git diff HEAD^ HEAD --color > "+ansiText , cwd = os.getcwd() , shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
    (out, error) = pr.communicate()
    
    conv = Ansi2HTMLConverter()
    ansi = ''
    with open(ansiText, 'r+') as fh:
        fh.readline()
    
        for line in fh:
            ansi += ''.join(line.split())
    
    html = conv.convert(ansi)
    
    with open("%s.html" % ansiText, 'w+') as wf:
        wf.write(html)
    
    os.remove(ansiText)
    print str(error).capitalize()
    

maybe its too late to be awake...


Answer: figured out myself

    
    
    import sys
    import subprocess
    import os
    
    from ansi2html.converter import Ansi2HTMLConverter
    
    
    
    ansiText =  os.path.expanduser('~/Desktop/colorDiff')
    
    
    
    proc = subprocess.Popen('git diff HEAD^ HEAD --color',  shell=True, stdout=subprocess.PIPE, stderr = subprocess.PIPE )
    diffData = proc.stdout.read()
    conv = Ansi2HTMLConverter()
    
    html = conv.convert(diffData)
    
    
    with open("%s.html" % ansiText, 'w') as wf:
        wf.write(html)
    

