113 writer = buildtools.get_writer(self.writerType, build_file_path) |
113 writer = buildtools.get_writer(self.writerType, build_file_path) |
114 writer.writeTopLevel(config_name_list, self.spec_name, output_path, xml_file) |
114 writer.writeTopLevel(config_name_list, self.spec_name, output_path, xml_file) |
115 writer.close() |
115 writer.close() |
116 |
116 |
117 def getCommonUncRoots(self, uncPaths): |
117 def getCommonUncRoots(self, uncPaths): |
118 """get common UNC roots""" |
118 """ Get common UNC roots. |
|
119 The following [r'\\server1\foo\bar', r'\\server2\foo', r'\\server1\foo'] input |
|
120 will return [r'\\server1\foo\', r'\\server2\foo']. |
|
121 """ |
119 commonRoots = {} |
122 commonRoots = {} |
|
123 uncPaths = [os.path.normpath(p_path) for p_path in uncPaths] |
|
124 # sorting the input by alphabetical order, so smaller roots |
|
125 # are coming first. |
|
126 uncPaths.sort() |
120 for p_path in uncPaths: |
127 for p_path in uncPaths: |
121 commonRoots["\\\\" + os.sep.join(p_path[2:].split(os.sep)[0:2]) + os.sep] = 1 |
128 common_path = "\\\\" |
|
129 for p_comp in p_path[2:].split(os.sep): |
|
130 common_path = common_path + p_comp + os.sep |
|
131 if common_path in commonRoots: |
|
132 break |
|
133 else: |
|
134 commonRoots[common_path] = 1 |
122 return commonRoots.keys() |
135 return commonRoots.keys() |
123 |
136 |
124 def getPrefix(self, dir, commonUncRoots): |
137 def getPrefix(self, dir, commonUncRoots): |
125 """get prefix""" |
138 """get prefix""" |
126 for root in commonUncRoots: |
139 for root in commonUncRoots: |
136 |
149 |
137 # Read all the config's root.dir to get UNC Path if any |
150 # Read all the config's root.dir to get UNC Path if any |
138 # Of course this is only on windows platform |
151 # Of course this is only on windows platform |
139 if os.sep == '\\': |
152 if os.sep == '\\': |
140 for config in self.configs: |
153 for config in self.configs: |
141 (drive, root_dir) = os.path.splitdrive(os.path.normpath(config['root.dir'])) |
154 (drive, root_dir) = os.path.splitdrive(os.path.abspath(os.path.normpath(config['root.dir']))) |
142 _logger.debug("drive=%s, root_dir=%s" % (drive, root_dir)) |
155 _logger.debug("drive=%s, root_dir=%s" % (drive, root_dir)) |
143 if drive == "": |
156 if drive == "": |
144 self.listToFindPrefix.append(root_dir) |
157 self.listToFindPrefix.append(root_dir) |
145 |
158 |
146 commonUncRoots = self.getCommonUncRoots(self.listToFindPrefix) |
159 commonUncRoots = self.getCommonUncRoots(self.listToFindPrefix) |
151 driveMapping[root] = self.substUncPath(root) |
164 driveMapping[root] = self.substUncPath(root) |
152 _logger.debug("%s subst as %s" % (root, driveMapping[root])) |
165 _logger.debug("%s subst as %s" % (root, driveMapping[root])) |
153 substDrives.append(driveMapping[root] + os.sep) |
166 substDrives.append(driveMapping[root] + os.sep) |
154 |
167 |
155 for config in self.configs: |
168 for config in self.configs: |
156 (drive, root_dir) = os.path.splitdrive(os.path.normpath(config['root.dir']) + os.sep) |
169 (drive, root_dir) = os.path.splitdrive(os.path.abspath(os.path.normpath(config['root.dir'])) + os.sep) |
157 if drive == "": |
170 if drive == "": |
158 for root in driveMapping: |
171 for root in driveMapping: |
159 if root_dir.startswith(root): |
172 if root_dir.startswith(root): |
160 config['root.dir'] = os.path.normpath(driveMapping[root] + os.sep + root_dir[len(root):len(root_dir)]) |
173 config['root.dir'] = os.path.normpath(driveMapping[root] + os.sep + root_dir[len(root):len(root_dir)]) |
161 _logger.info("Updated %s in %s" % (root_dir, config['root.dir'])) |
174 _logger.info("Updated %s in %s" % (root_dir, config['root.dir'])) |
162 config['unsubst.dir'] = driveMapping[root] |
175 config['unsubst.dir'] = driveMapping[root] |
163 break |
176 break |
|
177 else: |
|
178 _logger.error("Could not find root for %s." % root_dir) |
164 elif drive != build_drive: |
179 elif drive != build_drive: |
165 if config['root.dir'] not in substDrives: |
180 if config['root.dir'] not in substDrives: |
166 substDrives.append(config['root.dir']) |
181 substDrives.append(config['root.dir']) |
167 else: |
182 else: |
168 for config in self.configs: |
183 for config in self.configs: |