<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> from optparse import OptionParser <EOL> import os <EOL> import re <EOL> import shutil <EOL> import sys <EOL> def usage ( ) : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> parser = OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> ( opts , args ) = parser . parse_args ( ) <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> usage ( ) <EOL> src , dest = args <EOL> if not ( os . path . exists ( src ) and os . path . isdir ( src ) ) : <EOL> usage ( ) <EOL> if not os . path . exists ( dest ) : <EOL> os . makedirs ( dest ) <EOL> def copy_dir ( s , d ) : <EOL> if not os . path . exists ( d ) : <EOL> os . mkdir ( d ) <EOL> for f in os . listdir ( s ) : <EOL> if f [ <NUM_LIT:0> ] == '<STR_LIT:.>' : <EOL> continue <EOL> copy ( os . path . join ( s , f ) , os . path . join ( d , f ) ) <EOL> def copy_file ( s , d , xform = None ) : <EOL> with open ( s , '<STR_LIT:rb>' ) as f : <EOL> text = f . read ( ) <EOL> if xform : <EOL> ( d , text ) = xform ( d , text ) <EOL> if os . path . exists ( d ) : <EOL> if opts . force : <EOL> print >> sys . stderr , '<STR_LIT>' % d <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' % d <EOL> return <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' % d <EOL> with open ( d , '<STR_LIT:wb>' ) as f : <EOL> f . write ( text ) <EOL> def to_python_case ( name ) : <EOL> s1 = re . sub ( '<STR_LIT>' , r'<STR_LIT>' , name ) <EOL> return re . sub ( '<STR_LIT>' , r'<STR_LIT>' , s1 ) . lower ( ) <EOL> def xform_py ( d , text ) : <EOL> text = re . sub ( '<STR_LIT>' , '<STR_LIT:#>' , text ) <EOL> text = text . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> text ) <EOL> text = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> text ) <EOL> text = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> text ) <EOL> text = re . sub ( <EOL> r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( <EOL> r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT:\n>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> text = text . replace ( '<STR_LIT:true>' , '<STR_LIT:True>' ) <EOL> text = text . replace ( '<STR_LIT:false>' , '<STR_LIT:False>' ) <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> parent = os . path . dirname ( d ) <EOL> parent_name = os . path . basename ( parent ) <EOL> name , ext = os . path . splitext ( os . path . basename ( d ) ) <EOL> if name == parent_name : <EOL> newext = '<STR_LIT>' <EOL> else : <EOL> newext = '<STR_LIT>' <EOL> name = to_python_case ( name ) <EOL> d = parent + '<STR_LIT:/>' + name + newext <EOL> return ( d , text ) <EOL> def copy ( s , d ) : <EOL> if os . path . isdir ( s ) : <EOL> copy_dir ( s , d ) <EOL> elif s . endswith ( "<STR_LIT>" ) : <EOL> copy_file ( s , d , xform_py ) <EOL> else : <EOL> copy_file ( s , d ) <EOL> copy ( src , dest ) </s>
