@@ -53,6 +53,22 @@ def __init__(
5353 self .source = source
5454
5555
56+ class EnvVar :
57+ id : str
58+
59+ name : str
60+
61+ value : str
62+
63+ guid : str
64+
65+ def __init__ (self , id : str , name : str , value : str , guid : str ):
66+ self .id = id
67+ self .name = name
68+ self .value = value
69+ self .guid = guid
70+
71+
5672class _DestinationDirectory :
5773 id : str
5874
@@ -64,12 +80,15 @@ class _DestinationDirectory:
6480
6581 files : List [File ]
6682
83+ envvars : List [EnvVar ]
84+
6785 def __init__ (self , id : str , name : str , level : int ):
6886 self .id = id
6987 self .name = name
7088 self .level = level
7189 self .children : Dict [str , _DestinationDirectory ] = {}
7290 self .files = []
91+ self .envvars = []
7392
7493 def add_file (
7594 self , path : pathlib .Path , feature : str , guid : str , source_path : pathlib .Path
@@ -83,36 +102,55 @@ def add_file(
83102 child_id , child_name , self .level + 1
84103 )
85104 grandchild_path = pathlib .Path (str (path )[len (child_name ) + 1 :])
86- self .children [child_name ].add_file (grandchild_path , feature , guid , source_path )
105+ self .children [child_name ].add_file (
106+ grandchild_path , feature , guid , source_path
107+ )
87108 else :
88109 file_name : str = str (path )
89110 file_id : str = self .id + "." + file_name
90111 file_id = file_id [- 72 :]
91112 self .files .append (File (file_id , file_name , feature , guid , source_path ))
92113
114+ def add_envvar (self , name : str , value : str , guid : str ) -> None :
115+ envvar_id : str = self .id + "." + name
116+ self .envvars .append (EnvVar (envvar_id , name , value , guid ))
117+
93118
94119def _build_destination_tree (source_path : pathlib .Path ) -> _DestinationDirectory :
95120 destination_tree = _DestinationDirectory ("tetengo" , "" , 0 )
96121 with source_path .open (mode = "r" , encoding = "UTF-8" ) as stream :
97122 for line in stream :
98123 line = line .rstrip ("\r \n " )
99- matched : Optional [re .Match [str ]] = re .match (
124+ matched_as_file : Optional [re .Match [str ]] = re .match (
100125 "^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)" , line
101126 )
102- if not matched :
103- continue
104- kind : str = matched .group (1 )
105- if kind == "file" :
106- feature : str = matched .group (2 )
107- source_directory = pathlib .Path (matched .group (3 ))
108- source_path = pathlib .Path (matched .group (4 ))
109- destination = pathlib .Path (matched .group (5 ))
110- guid = matched .group (6 )
111- destination_tree .add_file (
112- destination / source_path , feature , guid , source_directory / source_path
113- )
127+ if matched_as_file :
128+ kind_as_file : str = matched_as_file .group (1 )
129+ if kind_as_file == "file" :
130+ feature_as_file : str = matched_as_file .group (2 )
131+ source_directory_as_file = pathlib .Path (matched_as_file .group (3 ))
132+ source_path_as_file = pathlib .Path (matched_as_file .group (4 ))
133+ destination_as_file = pathlib .Path (matched_as_file .group (5 ))
134+ guid_as_file = matched_as_file .group (6 )
135+ destination_tree .add_file (
136+ destination_as_file / source_path_as_file ,
137+ feature_as_file ,
138+ guid_as_file ,
139+ source_directory_as_file / source_path_as_file ,
140+ )
114141 else :
115- raise "error: " + kind
142+ matched_as_envvar : Optional [re .Match [str ]] = re .match (
143+ "^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)" , line
144+ )
145+ if matched_as_envvar :
146+ kind_as_envvar : str = matched_as_envvar .group (1 )
147+ if kind_as_envvar == "envvar" :
148+ name_as_envvar : str = matched_as_envvar .group (2 )
149+ value_as_envvar : str = matched_as_envvar .group (3 )
150+ guid_as_envvar : str = matched_as_envvar .group (4 )
151+ destination_tree .add_envvar (
152+ name_as_envvar , value_as_envvar , guid_as_envvar
153+ )
116154 return destination_tree
117155
118156
@@ -131,6 +169,10 @@ def _build_feature_map_iter(
131169 feature_map [file .feature ].append (file .id )
132170 for child_key in destination_tree .children :
133171 _build_feature_map_iter (destination_tree .children [child_key ], feature_map )
172+ for envvar in destination_tree .envvars :
173+ if not "environment_variable" in feature_map :
174+ feature_map ["environment_variable" ] = []
175+ feature_map ["environment_variable" ].append (envvar .id )
134176
135177
136178def _save_wxs (
@@ -187,6 +229,19 @@ def _write_directory_fragment_iter(
187229 file = stream ,
188230 )
189231 print ("{} </Component>" .format (indent ), file = stream )
232+ for envvar in destination_tree .envvars :
233+ print (
234+ '{} <Component Id="{}" Guid="{}">' .format (indent , envvar .id , envvar .guid ),
235+ file = stream ,
236+ )
237+ print ("{} <CreateFolder/>" .format (indent ), file = stream )
238+ print (
239+ '{} <Environment Id="{}" Name="{}" Action="set" System="yes" Part="all" Value="{}"/>' .format (
240+ indent , envvar .id , envvar .name , envvar .value
241+ ),
242+ file = stream ,
243+ )
244+ print ("{} </Component>" .format (indent ), file = stream )
190245 if len (destination_tree .name ) == 0 :
191246 print ("{}</DirectoryRef>" .format (indent ), file = stream )
192247 else :
0 commit comments