<s> import os <EOL> import sys <EOL> import errno <EOL> import re <EOL> acts = os . path . expanduser ( '<STR_LIT>' ) <EOL> act_link_l = os . path . join ( acts , '<STR_LIT>' ) <EOL> act_link_r = os . path . join ( acts , '<STR_LIT>' ) <EOL> act_lhs = os . path . join ( acts , '<STR_LIT>' ) <EOL> act_rhs = os . path . join ( acts , '<STR_LIT>' ) <EOL> temp = os . path . expanduser ( '<STR_LIT>' ) <EOL> state = os . path . join ( temp , '<STR_LIT>' ) <EOL> if len ( sys . argv ) == <NUM_LIT:3> : <EOL> if sys . argv [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> if len ( sys . argv [ <NUM_LIT:2> ] ) > <NUM_LIT:0> and os . path . exists ( state ) : <EOL> rhs = sys . argv [ <NUM_LIT:2> ] <EOL> with open ( state , '<STR_LIT:r>' ) as f : <EOL> lhs = f . readline ( ) . strip ( ) <EOL> os . unlink ( state ) <EOL> os . unlink ( act_link_r ) <EOL> os . execlp ( '<STR_LIT>' , '<STR_LIT>' , lhs , rhs ) <EOL> elif sys . argv [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> if len ( sys . argv [ <NUM_LIT:2> ] ) > <NUM_LIT:0> : <EOL> with open ( state , '<STR_LIT:w>' ) as f : <EOL> f . write ( sys . argv [ <NUM_LIT:2> ] ) <EOL> lines = [ line for line in open ( act_rhs , '<STR_LIT:r>' ) ] <EOL> pat = r'<STR_LIT>' <EOL> lines = [ re . sub ( pat , '<STR_LIT>' + os . path . basename ( sys . argv [ <NUM_LIT:2> ] ) , line ) for line in lines ] <EOL> with open ( act_rhs , '<STR_LIT:w>' ) as f : <EOL> for line in lines : <EOL> f . write ( line ) <EOL> os . symlink ( act_rhs , act_link_r ) <EOL> else : <EOL> if not os . path . exists ( temp ) : <EOL> os . makedirs ( temp ) <EOL> if os . path . exists ( state ) : <EOL> os . unlink ( state ) <EOL> try : <EOL> os . symlink ( act_lhs , act_link_l ) <EOL> except OSError , e : <EOL> if errno . EEXIST == e . errno : <EOL> try : <EOL> os . unlink ( act_link_l ) <EOL> os . symlink ( act_lhs , act_link_l ) <EOL> except : <EOL> print "<STR_LIT>" </s>
