hpe chassis id and its price are now parsed instead of being hardcoded
work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=4015]
This commit is contained in:
		
							parent
							
								
									3b002ee17b
								
							
						
					
					
						commit
						a0ba1f3b95
					
				
							
								
								
									
										129
									
								
								concho/hpev2.py
								
								
								
								
							
							
						
						
									
										129
									
								
								concho/hpev2.py
								
								
								
								
							|  | @ -26,6 +26,78 @@ class Quantity(): | |||
| 
 | ||||
| 
 | ||||
| class HpeV2ConfiguratorParser(IHtmlConfiguratorParser): | ||||
|     # the body of the HpeV2 html pages look like this: | ||||
|     # <body style=""> | ||||
|     #     <div id="dataWrap" class="lang_en_US"> | ||||
|     #         <div id="theData" data-role="page"> | ||||
|     #             <div id="eocs_config_page" class="eocs_page hybris_punchout"> | ||||
|     #                 <div id="sce_toolbar" class="sce-toolbar" style="display: none;"> | ||||
|     #                     <div id="sce_toolbar_left" class="pull-left"> | ||||
|     #                         <ul> | ||||
|     #                             <li id="sce_toolbar_new_config_normal" class="sce-toolbar-new-config ison"><a | ||||
|     #                                     id="sce_toolbar_new_config">New Configuration</a></li> | ||||
|     #                             <li id="sce_toolbar_banding_normal" class="sce_toolbar_banding"><a | ||||
|     #                                     id="sce_toolbar_banding">Banding</a></li> | ||||
|     #                             <li id="sce_toolbar_localization_normal" class="sce_toolbar_localization"><a | ||||
|     #                                     id="sce_toolbar_localization">Localization</a></li> | ||||
|     #                             <li id="sce_toolbar_search_normal" class="sce_toolbar_search"><a | ||||
|     #                                     id="sce_toolbar_search">Search</a></li> | ||||
|     #                         </ul> | ||||
|     #                     </div> | ||||
|     #                     <div id="sce_toolbar_right" class="pull-right"> | ||||
|     #                         <ul> | ||||
|     #                             <li class="sce_toolbar_save_config"><span id="sce_toolbar_save_config_icon" | ||||
|     #                                     class="tool-bar-icons sce-toolbar-save-config-icon"></span><input | ||||
|     #                                     id="sce_toolbar_save_config" value="Save" type="button" style="font-size: 14px;" | ||||
|     #                                     class="button slim critical"></li> | ||||
|     #                         </ul> | ||||
|     #                     </div> | ||||
|     #                     <li id="sce_toolbar_support_normal"><a id="sce_toolbar_support">Support</a></li> | ||||
|     #                     <div id="email_toolbar" class="pull-right"></div> | ||||
|     #                     <hr> | ||||
|     #                 </div> | ||||
|     #                 <div class="config_header"> | ||||
|     #                     <div class="left_title_container"> | ||||
|     #                         <div class="prod-titles-grp"> | ||||
|     #                             <span id="main_title" title="DL380 Gen11 (Cat2 Conf16)" class="product-title pull-left">DL380 Gen11 (Cat2 Conf16)</span> | ||||
|     #                             <span class="product_subtitle">HPE ProLiant DL380 Gen11 8SFF NC Configure-to-order Server</span> | ||||
|     #                         </div> | ||||
|     #                         <div id="expandAll_collapseAll_buttonsDiv"><span id="expandAll_collapseAll" | ||||
|     #                                 class="expandAll_button selected">Expand All</span><span id="angle_id" | ||||
|     #                                 class="angle_class icon-angle-down"></span></div> | ||||
|     #                     </div> | ||||
|     #                     <div class="right_message_btns_container pull-left"> | ||||
|     #                         <ul class="product-message-btns pull-right"><label id="config_your_product"></label> | ||||
|     #                             <li class="pull-left eocs_message_div"><span class="msg-icon hpenew-notes"></span><input | ||||
|     #                                     id="see_all_system_message_div_id" type="button" value="Messages" | ||||
|     #                                     class="all-messages-popup-btn"></li> | ||||
|     #                         </ul> | ||||
|     #                     </div> | ||||
|     #                 </div> | ||||
|     #                 <div id="center_div" class="column"> | ||||
|     #                     <where all module tables are> | ||||
|     #                 </div> | ||||
|     #                 <div id="right_div" class="column"> | ||||
|     #                     ... | ||||
|     #                     <section class="eocsrightsectiondiv"> | ||||
|     #                         <section class="rsection1"> | ||||
|     #                             <div id="referenceid">Reference Model ID: 46951646</div> | ||||
|     #                             <div id="price_div"> | ||||
|     #                                 <span id="rsection1_actprice" class="rsection_price"> | ||||
|     #                                     <label>Your price</label> | ||||
|     #                                     <span class="currency_code">EUR</span> | ||||
|     #                                     <span class="total_price">1,375.99</span> | ||||
|     #                                 </span> | ||||
|     #                                 <span id="rsection1_maxtime" class="rsection_maxtime" style="display: block;"> | ||||
|     #                                     <label><i>Estimated to ship in </i></label> | ||||
|     #                                     <span id="max_leadtime" class="max_leadtime">15</span> | ||||
|     #                                     <i class="max_leadtime"> business days </i> | ||||
|     #                                 </span> | ||||
|     #                                 <span id="ecoLablels" class="ecoLablels"><img id="eStar" class="eStar"><img id="ePeat" | ||||
|     #                                         class="ePeat"></span></div> | ||||
| 
 | ||||
|     # inside the <where all module tables are>: | ||||
| 
 | ||||
|     # <div id="ProcessorSection_AdditionalProcessorsChoice" class="choice_container choice_type_multi_select" choicename="Processors"> | ||||
|     #   <div class="section_container"> | ||||
|     #     <span id="section_title">Processors</span> | ||||
|  | @ -253,6 +325,29 @@ class HpeV2ConfiguratorParser(IHtmlConfiguratorParser): | |||
|         assert len(ram_options.options) > 0 | ||||
|         return ram_options, selected_dimms | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def _parse_base_config_info(html_root: HtmlElement) -> Tuple[str, Price]: | ||||
|         prod_titles_grp_el = html_root.xpath(r".//div[@class='prod-titles-grp']")[0] | ||||
|         assert prod_titles_grp_el | ||||
| 
 | ||||
|         #                         <div class="prod-titles-grp"> | ||||
|         #                             <span id="main_title" title="DL380 Gen11 (Cat2 Conf16)" class="product-title pull-left">DL380 Gen11 (Cat2 Conf16)</span> | ||||
|         #                             <span class="product_subtitle">HPE ProLiant DL380 Gen11 8SFF NC Configure-to-order Server</span> | ||||
|         #                         </div> | ||||
|         product_subtitle = prod_titles_grp_el.xpath(r".//span[@class='product_subtitle']")[0].text.replace('\n', '').replace('\t', '')  # eg HPE ProLiant DL380 Gen11 8SFF NC Configure-to-order Server | ||||
|         # print(product_subtitle) | ||||
|         match = re.match(r'^HPE ProLiant DL(?P<chassis_number>[3][68][05]) *Gen11 *8SFF *NC *Configure-to-order *Server$', product_subtitle) | ||||
|         assert match | ||||
|         chassis_number = match['chassis_number'] | ||||
|         # configurator.base_config = self._parse_base_config() | ||||
|         chassis_id = f"hpe-proliant-dl{chassis_number}-gen11" | ||||
| 
 | ||||
|         #  <span class="total_price">1,375.99</span> | ||||
|         config_price_as_str = html_root.xpath(r".//span[@class='total_price']")[0].text | ||||
|         config_price = Price(config_price_as_str.replace(',', '')) | ||||
|         print(f'config_price = {config_price}') | ||||
|         return chassis_id, config_price | ||||
| 
 | ||||
|     def parse(self, hpe_configurator_html_file_path: Path, configurator: Configurator): | ||||
|         ''' | ||||
|         hpe_configurator_html_file_path : eg '/home/graffy/work/concho/catalogs/hpev2/20250314-cat2-conf16-hpe-dl380-gen11.html' | ||||
|  | @ -262,33 +357,41 @@ class HpeV2ConfiguratorParser(IHtmlConfiguratorParser): | |||
|         html_root: HtmlElement = parse_html(str(hybris_file_path)).getroot() | ||||
|         # print(type(html_root)) | ||||
| 
 | ||||
|         # configurator.base_config = self._parse_base_config() | ||||
|         chassis_id = "hpe-proliant-dl380-gen11" | ||||
|         configurator.chassis = Option(Chassis(chassis_id), 1000.0)  # TODO: compute the chassis price | ||||
| 
 | ||||
|         # configurator.base_config = self._parse_base_config(html_root, configurator) | ||||
| 
 | ||||
|         configurator.base_config = Config(configurator) | ||||
|         configurator.base_config.num_servers = 1 | ||||
|         configurator.base_config.num_cpu_per_server = 2 | ||||
|         configurator.base_config.get_price | ||||
| 
 | ||||
|         proc_table = self._parse_module_html_table(html_root, 'additional_cpus') | ||||
|         proc_module, selected_procs = self._parse_proc_options(proc_table) | ||||
|         configurator.add_module(proc_module) | ||||
|         assert len(selected_procs) == 1 | ||||
|         configurator.base_config.set_cpu(selected_procs[0]) | ||||
| 
 | ||||
|         ram_table = self._parse_module_html_table(html_root, 'ram') | ||||
|         ram_module, selected_dimms = self._parse_ram_options(ram_table) | ||||
|         configurator.add_module(ram_module) | ||||
| 
 | ||||
|         chassis_id, config_price = HpeV2ConfiguratorParser._parse_base_config_info(html_root) | ||||
| 
 | ||||
|         selected_procs_price = sum([proc_module.options[cpu.uid].price for cpu in selected_procs])  | ||||
|         selected_dimms_price = sum([ram_module.options[dimm.uid].price for dimm in selected_dimms])  | ||||
|         chassis_price = config_price - selected_procs_price - selected_dimms_price | ||||
|         base_config = Config(configurator) | ||||
|         base_config.num_servers = 1 | ||||
|         base_config.num_cpu_per_server = 2 | ||||
|         print(f'selected_procs_price = {selected_procs_price}') | ||||
|         print(f'selected_dimms_price = {selected_dimms_price}') | ||||
|         print(f'chassis_price = {chassis_price}') | ||||
|         configurator.chassis = Option(Chassis(chassis_id), chassis_price) | ||||
| 
 | ||||
|         base_config.set_cpu(selected_procs[0]) | ||||
| 
 | ||||
|         channel_index = 0 | ||||
|         for dimm in selected_dimms: | ||||
|             configurator.base_config.cpu_slots_mem[0].mem_channels[channel_index].dimms.append(dimm) | ||||
|             base_config.cpu_slots_mem[0].mem_channels[channel_index].dimms.append(dimm) | ||||
|             channel_index += 1 | ||||
|         configurator.base_config = base_config | ||||
| 
 | ||||
| 
 | ||||
|         # configurator.add_module(self._parse_ram_options(html_root)) | ||||
| 
 | ||||
|         # script_elements = html_root.xpath(".//script[@type='text/javascript']") | ||||
|         # print('number of javascript scripts:', len(script_elements)) | ||||
|         # # script type="text/javascript" | ||||
|         # db_jscript = None | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue