Guest User

Untitled

a guest
Jun 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #/usr/bin/python
  3.  
  4. from __future__ import with_statement # This isn't required in Python 2.6
  5. import sys
  6.  
  7. def convert(oldFile):
  8.  
  9. ParamMap = {
  10. '$DEFAULTCOLOUR': 'Default',
  11. '$BGCOLOUR' : 'Canvas' ,
  12. '$NUMBER' : 'Number' ,
  13. '$ESCAPECHAR' : 'Escape' ,
  14. '$STRING' : 'String' ,
  15. '$STRING-DIRECTIVE' : 'StringPreProc' ,
  16. '$COMMENT' : 'BlockComment' ,
  17. '$SL-COMMENT' : 'LineComment' ,
  18. '$DIRECTIVE' : 'PreProcessor' ,
  19. '$LINE' : 'LineNum' ,
  20. '$SYMBOL' : 'Operator' ,
  21. }
  22.  
  23. KeywordGroupMap = []
  24. slcDefined=0
  25. newFile=oldFile[0:oldFile.rfind('.')] + ".theme"
  26. with open(newFile,'w') as outfile:
  27. with open(oldFile) as f:
  28. outfile.write('-- Theme generated by theme2to3\n\n')
  29. for line in f:
  30. values =line.rstrip().split('=',1)
  31. if (values[0] in ParamMap):
  32. if (values[0].lower()=='$sl-comment'): slcDefined=1
  33. attributes=values[1].split(' ')
  34. line= "%-14s = { Colour=\"%s\"" % (ParamMap[values[0]], attributes[0])
  35. for a in attributes[1:]:
  36. if a=='bold': line=line+", Bold=true"
  37. elif a=='italic': line=line+", Italic=true"
  38. elif a=='underline': line=line+", Underline=true"
  39. line=line+" }\n"
  40. outfile.write( line )
  41. elif values[0].startswith('$KW')==True:
  42. attributes=values[1].split(' ')
  43. KeywordGroupMap.append(attributes)
  44. if (slcDefined == 0):
  45. outfile.write( 'LineComment = BlockComment\n')
  46. outfile.write( '\nKeywords = {\n')
  47. for kwGroup in KeywordGroupMap:
  48. line = " { Colour= \"%s\"" % kwGroup[0]
  49. for a in kwGroup[1:]:
  50. if a=='bold': line=line+", Bold=true"
  51. elif a=='italic': line=line+", Italic=true"
  52. elif a=='underline': line=line+", Underline=true"
  53. line = line + ' },\n'
  54. outfile.write( line )
  55. outfile.write( '}\n' )
  56.  
  57. if __name__ == "__main__":
  58. if len(sys.argv) < 2:
  59. print "USAGE: %s old_theme.style" % sys.argv[0]
  60. else:
  61. for f in sys.argv[1:]:
  62. convert(f)
Add Comment
Please, Sign In to add comment