<s> """<STR_LIT>""" <EOL> import os <EOL> import random <EOL> import gyp . common <EOL> try : <EOL> import hashlib <EOL> _new_md5 = hashlib . md5 <EOL> except ImportError : <EOL> import md5 <EOL> _new_md5 = md5 . new <EOL> random . seed ( ) <EOL> ENTRY_TYPE_GUIDS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def MakeGuid ( name , seed = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> d = _new_md5 ( str ( seed ) + str ( name ) ) . hexdigest ( ) . upper ( ) <EOL> guid = ( '<STR_LIT:{>' + d [ : <NUM_LIT:8> ] + '<STR_LIT:->' + d [ <NUM_LIT:8> : <NUM_LIT:12> ] + '<STR_LIT:->' + d [ <NUM_LIT:12> : <NUM_LIT:16> ] + '<STR_LIT:->' + d [ <NUM_LIT:16> : <NUM_LIT:20> ] <EOL> + '<STR_LIT:->' + d [ <NUM_LIT:20> : <NUM_LIT:32> ] + '<STR_LIT:}>' ) <EOL> return guid <EOL> class MSVSSolutionEntry ( object ) : <EOL> def __cmp__ ( self , other ) : <EOL> return cmp ( ( self . name , self . get_guid ( ) ) , ( other . name , other . get_guid ( ) ) ) <EOL> class MSVSFolder ( MSVSSolutionEntry ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , path , name = None , entries = None , <EOL> guid = None , items = None ) : <EOL> """<STR_LIT>""" <EOL> if name : <EOL> self . name = name <EOL> else : <EOL> self . name = os . path . basename ( path ) <EOL> self . path = path <EOL> self . guid = guid <EOL> self . entries = sorted ( list ( entries or [ ] ) ) <EOL> self . items = list ( items or [ ] ) <EOL> self . entry_type_guid = ENTRY_TYPE_GUIDS [ '<STR_LIT>' ] <EOL> def get_guid ( self ) : <EOL> if self . guid is None : <EOL> self . guid = MakeGuid ( self . path , seed = '<STR_LIT>' ) <EOL> return self . guid <EOL> class MSVSProject ( MSVSSolutionEntry ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , path , name = None , dependencies = None , guid = None , <EOL> spec = None , build_file = None , config_platform_overrides = None , <EOL> fixpath_prefix = None ) : <EOL> """<STR_LIT>""" <EOL> self . path = path <EOL> self . guid = guid <EOL> self . spec = spec <EOL> self . build_file = build_file <EOL> self . name = name or os . path . splitext ( os . path . basename ( path ) ) [ <NUM_LIT:0> ] <EOL> self . dependencies = list ( dependencies or [ ] ) <EOL> self . entry_type_guid = ENTRY_TYPE_GUIDS [ '<STR_LIT>' ] <EOL> if config_platform_overrides : <EOL> self . config_platform_overrides = config_platform_overrides <EOL> else : <EOL> self . config_platform_overrides = { } <EOL> self . fixpath_prefix = fixpath_prefix <EOL> self . msbuild_toolset = None <EOL> def set_dependencies ( self , dependencies ) : <EOL> self . dependencies = list ( dependencies or [ ] ) <EOL> def get_guid ( self ) : <EOL> if self . guid is None : <EOL> self . guid = MakeGuid ( self . name ) <EOL> return self . guid <EOL> def set_msbuild_toolset ( self , msbuild_toolset ) : <EOL> self . msbuild_toolset = msbuild_toolset <EOL> class MSVSSolution : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , path , version , entries = None , variants = None , <EOL> websiteProperties = True ) : <EOL> """<STR_LIT>""" <EOL> self . path = path <EOL> self . websiteProperties = websiteProperties <EOL> self . version = version <EOL> self . entries = list ( entries or [ ] ) <EOL> if variants : <EOL> self . variants = variants [ : ] <EOL> else : <EOL> self . variants = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . Write ( ) <EOL> def Write ( self , writer = gyp . common . WriteOnDiff ) : <EOL> """<STR_LIT>""" <EOL> all_entries = set ( ) <EOL> entries_to_check = self . entries [ : ] <EOL> while entries_to_check : <EOL> e = entries_to_check . pop ( <NUM_LIT:0> ) <EOL> if e in all_entries : <EOL> continue <EOL> all_entries . add ( e ) <EOL> if isinstance ( e , MSVSFolder ) : <EOL> entries_to_check += e . entries <EOL> all_entries = sorted ( all_entries ) <EOL> f = writer ( self . path ) <EOL> f . write ( '<STR_LIT>' <EOL> '<STR_LIT>' % self . version . SolutionVersion ( ) ) <EOL> f . write ( '<STR_LIT>' % self . version . Description ( ) ) <EOL> sln_root = os . path . split ( self . path ) [ <NUM_LIT:0> ] <EOL> for e in all_entries : <EOL> relative_path = gyp . common . RelativePath ( e . path , sln_root ) <EOL> folder_name = relative_path . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) or '<STR_LIT:.>' <EOL> f . write ( '<STR_LIT>' % ( <EOL> e . entry_type_guid , <EOL> e . name , <EOL> folder_name , <EOL> e . get_guid ( ) , <EOL> ) ) <EOL> if self . websiteProperties : <EOL> f . write ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if isinstance ( e , MSVSFolder ) : <EOL> if e . items : <EOL> f . write ( '<STR_LIT>' ) <EOL> for i in e . items : <EOL> f . write ( '<STR_LIT>' % ( i , i ) ) <EOL> f . write ( '<STR_LIT>' ) <EOL> if isinstance ( e , MSVSProject ) : <EOL> if e . dependencies : <EOL> f . write ( '<STR_LIT>' ) <EOL> for d in e . dependencies : <EOL> f . write ( '<STR_LIT>' % ( d . get_guid ( ) , d . get_guid ( ) ) ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> for v in self . variants : <EOL> f . write ( '<STR_LIT>' % ( v , v ) ) <EOL> f . write ( '<STR_LIT>' ) <EOL> config_guids = [ ] <EOL> config_guids_overrides = { } <EOL> for e in all_entries : <EOL> if isinstance ( e , MSVSProject ) : <EOL> config_guids . append ( e . get_guid ( ) ) <EOL> config_guids_overrides [ e . get_guid ( ) ] = e . config_platform_overrides <EOL> config_guids . sort ( ) <EOL> f . write ( '<STR_LIT>' ) <EOL> for g in config_guids : <EOL> for v in self . variants : <EOL> nv = config_guids_overrides [ g ] . get ( v , v ) <EOL> f . write ( '<STR_LIT>' % ( <EOL> g , <EOL> v , <EOL> nv , <EOL> ) ) <EOL> f . write ( '<STR_LIT>' % ( <EOL> g , <EOL> v , <EOL> nv , <EOL> ) ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> for e in all_entries : <EOL> if not isinstance ( e , MSVSFolder ) : <EOL> continue <EOL> for subentry in e . entries : <EOL> f . write ( '<STR_LIT>' % ( subentry . get_guid ( ) , e . get_guid ( ) ) ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . close ( ) </s>
