Skip to content

Instantly share code, notes, and snippets.

@tajmone tajmone/theme2to3.py
Created Jun 19, 2018

Embed
What would you like to do?
Highlight `theme2to3.py` Script Recovered (from Highlight v3.5-1)
# -*- coding: utf-8 -*-
#/usr/bin/python
from __future__ import with_statement # This isn't required in Python 2.6
import sys
def convert(oldFile):
ParamMap = {
'$DEFAULTCOLOUR': 'Default',
'$BGCOLOUR' : 'Canvas' ,
'$NUMBER' : 'Number' ,
'$ESCAPECHAR' : 'Escape' ,
'$STRING' : 'String' ,
'$STRING-DIRECTIVE' : 'StringPreProc' ,
'$COMMENT' : 'BlockComment' ,
'$SL-COMMENT' : 'LineComment' ,
'$DIRECTIVE' : 'PreProcessor' ,
'$LINE' : 'LineNum' ,
'$SYMBOL' : 'Operator' ,
}
KeywordGroupMap = []
slcDefined=0
newFile=oldFile[0:oldFile.rfind('.')] + ".theme"
with open(newFile,'w') as outfile:
with open(oldFile) as f:
outfile.write('-- Theme generated by theme2to3\n\n')
for line in f:
values =line.rstrip().split('=',1)
if (values[0] in ParamMap):
if (values[0].lower()=='$sl-comment'): slcDefined=1
attributes=values[1].split(' ')
line= "%-14s = { Colour=\"%s\"" % (ParamMap[values[0]], attributes[0])
for a in attributes[1:]:
if a=='bold': line=line+", Bold=true"
elif a=='italic': line=line+", Italic=true"
elif a=='underline': line=line+", Underline=true"
line=line+" }\n"
outfile.write( line )
elif values[0].startswith('$KW')==True:
attributes=values[1].split(' ')
KeywordGroupMap.append(attributes)
if (slcDefined == 0):
outfile.write( 'LineComment = BlockComment\n')
outfile.write( '\nKeywords = {\n')
for kwGroup in KeywordGroupMap:
line = " { Colour= \"%s\"" % kwGroup[0]
for a in kwGroup[1:]:
if a=='bold': line=line+", Bold=true"
elif a=='italic': line=line+", Italic=true"
elif a=='underline': line=line+", Underline=true"
line = line + ' },\n'
outfile.write( line )
outfile.write( '}\n' )
if __name__ == "__main__":
if len(sys.argv) < 2:
print "USAGE: %s old_theme.style" % sys.argv[0]
else:
for f in sys.argv[1:]:
convert(f)
@tajmone

This comment has been minimized.

Copy link
Owner Author

tajmone commented Jun 19, 2018

This python script was extracted from highlight-3.5-1.el6.rf.i686.rpm, found at:

For more info, see andre-simon/highlight#67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.