<s> from __future__ import print_function <EOL> __doc__ = """<STR_LIT>""" <EOL> from collections import namedtuple <EOL> import logging <EOL> log = logging . getLogger ( ) <EOL> ATTRS = ( <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ColorGroup = namedtuple ( '<STR_LIT>' , ATTRS ) <EOL> def cg_str ( self ) : <EOL> def _cg_str ( self ) : <EOL> if self . link : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> if self . cleared : <EOL> yield '<STR_LIT>' <EOL> yield self . name <EOL> yield '<STR_LIT:U+0020>' <EOL> if self . link : <EOL> yield '<STR_LIT>' % self . link <EOL> else : <EOL> for k , v in self . _asdict ( ) . iteritems ( ) : <EOL> if k in ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> continue <EOL> if v is not None : <EOL> yield '<STR_LIT>' % ( k , v ) <EOL> return str . join ( '<STR_LIT>' , _cg_str ( self ) ) <EOL> ColorGroup . __str__ = cg_str <EOL> def vim2vim ( filename ) : <EOL> """<STR_LIT>""" <EOL> with open ( filename , '<STR_LIT:r>' ) as f : <EOL> for line in f : <EOL> log . debug ( line . rstrip ( ) ) <EOL> l = line . strip ( ) <EOL> if not l or '<STR_LIT>' not in l : <EOL> continue <EOL> name , attrs = l . split ( '<STR_LIT>' ) <EOL> name = name . strip ( ) <EOL> attrs = attrs . strip ( ) <EOL> attrdict = dict . fromkeys ( ATTRS , None ) <EOL> attrdict [ '<STR_LIT:name>' ] = name <EOL> if attrs . startswith ( '<STR_LIT>' ) : <EOL> attrdict [ '<STR_LIT>' ] = attrs . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> elif attrs . startswith ( '<STR_LIT>' ) : <EOL> attrdict [ '<STR_LIT>' ] = True <EOL> else : <EOL> _attrs = [ x . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) for x in attrs . split ( '<STR_LIT:U+0020>' ) ] <EOL> try : <EOL> attrdict . update ( _attrs ) <EOL> except ValueError : <EOL> log . error ( _attrs ) <EOL> raise <EOL> yield ColorGroup ( ** attrdict ) <EOL> def sort_by_name_clear_inline ( iterable ) : <EOL> return sorted ( iterable , key = lambda x : ( x . name , not x . cleared , not x . link ) ) <EOL> def sort_by_name_clear_to_top ( iterable ) : <EOL> return sorted ( iterable , key = lambda x : ( not x . cleared , x . name , x . link ) ) <EOL> import unittest <EOL> class Test_vim2vim ( unittest . TestCase ) : <EOL> def test_vim2vim ( self ) : <EOL> import os . path <EOL> filename = os . path . join ( <EOL> os . path . dirname ( __file__ ) , <EOL> '<STR_LIT:..>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> print ( filename ) <EOL> log . info ( filename ) <EOL> color_groups = vim2vim ( filename ) <EOL> for group in color_groups : <EOL> log . debug ( group ) <EOL> def main ( * args ) : <EOL> import logging <EOL> import optparse <EOL> import sys <EOL> prs = optparse . OptionParser ( <EOL> usage = "<STR_LIT>" , <EOL> description = vim2vim . __doc__ <EOL> ) <EOL> prs . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , ) <EOL> prs . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , ) <EOL> prs . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , ) <EOL> prs . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , ) <EOL> prs . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , ) <EOL> args = args and list ( args ) or sys . argv [ <NUM_LIT:1> : ] <EOL> ( opts , args ) = prs . parse_args ( args ) <EOL> if not opts . quiet : <EOL> logging . basicConfig ( ) <EOL> if opts . verbose : <EOL> logging . getLogger ( ) . setLevel ( logging . DEBUG ) <EOL> if opts . run_tests : <EOL> import sys <EOL> sys . argv = [ sys . argv [ <NUM_LIT:0> ] ] + args <EOL> import unittest <EOL> sys . exit ( unittest . main ( ) ) <EOL> if len ( args ) : <EOL> filename = args [ <NUM_LIT:0> ] <EOL> color_groups = vim2vim ( filename ) <EOL> if opts . sort_by_name_clear_inline : <EOL> color_groups = sort_by_name_clear_inline ( color_groups ) <EOL> elif opts . sort_by_name_clear_to_top : <EOL> color_groups = sort_by_name_clear_to_top ( color_groups ) <EOL> for group in color_groups : <EOL> print ( group ) <EOL> else : <EOL> print ( __doc__ ) <EOL> prs . print_help ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
