Ignore:
Timestamp:
Apr 3, 2014 5:22:58 AM (10 years ago)
Author:
Jeff Krzywon <jeffery.krzywon@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
caf273b
Parents:
307fa4f
Message:

Fix for ticket #204 - processing instructions were not being set properly when saving as cansas data file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sans/dataloader/readers/cansas_reader.py

    rb65ae90 rea67541  
    2828 
    2929_ZERO = 1e-16 
     30PREPROCESS = "xmlpreprocess" 
    3031HAS_CONVERTER = True 
    3132try: 
     
    212213                            data1d.filename = name 
    213214                            data1d.meta_data["loader"] = "CanSAS 1D" 
     215                             
     216                            # Get all preprocessing events 
     217                            self.reader.setProcessingInstructions() 
     218                            data1d.meta_data[PREPROCESS] = \ 
     219                                    self.reader.processingInstructions 
     220                             
     221                            # Parse the XML file 
    214222                            return_value, extras = \ 
    215223                                self._parse_entry(entry, ns, data1d) 
     
    247255        return None 
    248256     
    249     def _create_unique_key(self, dictionary, name, i): 
     257    def _create_unique_key(self, dictionary, name, i = 0): 
    250258        """ 
    251259        Create a unique key value for any dictionary to prevent overwriting 
    252          
     260        Recurses until a unique key value is found. 
    253261         
    254262        :param dictionary: A dictionary with any number of entries 
    255263        :param name: The index of the item to be added to dictionary 
    256         :param i: The number to be appended to the name 
     264        :param i: The number to be appended to the name, starts at 0 
    257265        """ 
    258266        if dictionary.get(name) is not None: 
     
    291299                    if HAS_CONVERTER == True: 
    292300                        try: 
    293                             ## Check local units - bad units should raise KeyError 
     301                            ## Check local units - bad units raise KeyError 
    294302                            Converter(local_unit) 
    295303                            data_conv_q = Converter(attr['unit']) 
     
    347355                            CANSAS_NS.get(self.cansas_version).get("ns"), "}") 
    348356        unit = '' 
     357        tagname = '' 
     358        tagname_original = '' 
    349359         
    350360        # Go through each child in the parent element 
     
    440450                        exec item 
    441451                # Don't bother saving empty information unless it is a float 
    442                 if cs_values.ns_variable is not None and node_value is not None and \ 
     452                if cs_values.ns_variable is not None and \ 
     453                            node_value is not None and \ 
    443454                            node_value.isspace() == False: 
    444455                    # Format a string and then execute it. 
    445                     store_me = cs_values.ns_variable.format("data1d", node_value, tagname) 
     456                    store_me = cs_values.ns_variable.format("data1d", \ 
     457                                                            node_value, tagname) 
    446458                    exec store_me 
    447459                # Get attributes and process them 
     
    503515         
    504516        main_node = doc.createElement("SASroot") 
    505         if self.cansas_version == "1.1": 
    506             pi = doc.createProcessingInstruction('xml-stylesheet', \ 
    507                                     'type="text/xsl" href="cansasxml-html.xsl"') 
    508             root = doc.firstChild 
    509             doc.insertBefore(pi, root) 
     517         
     518        doc = self.setProcessingInstructions(doc, datainfo.meta_data[PREPROCESS]) 
    510519        main_node.setAttribute("version", self.cansas_version) 
    511520        main_node.setAttribute("xmlns", ns) 
     
    789798        fd.write(doc.toprettyxml()) 
    790799        fd.close() 
     800     
     801    ## Once I convert the writer to lxml from minidom 
     802    ## This can be moved into xml_reader 
     803    def setProcessingInstructions(self, minidomObject, dic): 
     804        xmlroot = minidomObject.firstChild 
     805        for item in dic: 
     806            pi = minidomObject.createProcessingInstruction(item, dic[item]) 
     807            minidomObject.insertBefore(pi, xmlroot) 
     808        return minidomObject 
     809     
     810     
Note: See TracChangeset for help on using the changeset viewer.