Changeset 11305:b85791927494 in orange


Ignore:
Timestamp:
02/12/13 12:39:13 (14 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Prevent a overwrite of the old version 1.0 ows scheme format.

Old schemes should not be allowed to be overwritten in a way that would
prevent the old interface from reading them.

Location:
Orange/OrangeCanvas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/application/canvasmain.py

    r11303 r11305  
    3131from ..gui.dock import CollapsibleDockWidget 
    3232from ..gui.quickhelp import QuickHelpTipEvent 
    33 from ..gui.utils import message_critical, message_question, message_warning 
     33from ..gui.utils import message_critical, message_question, \ 
     34                        message_warning, message_information 
    3435 
    3536from ..help import HelpManager 
     
    4344 
    4445from ..scheme import widgetsscheme 
    45 from ..scheme.readwrite import parse_scheme 
     46from ..scheme.readwrite import parse_scheme, sniff_version 
    4647 
    4748from . import welcomedialog 
     
    952953            return QDialog.Rejected 
    953954 
     955    def check_can_save(self, document, path): 
     956        """ 
     957        Check if saving the document to `path` would prevent it from 
     958        being read by the version 1.0 of scheme parser. 
     959 
     960        """ 
     961        if path and os.path.exists(path): 
     962            version = sniff_version(open(path, "rb")) 
     963            if version == "1.0": 
     964                message_information( 
     965                    self.tr("Can not overwrite a version 1.0 ows file. " 
     966                            "Please save your work to a new file"), 
     967                    title="Info", 
     968                    parent=self) 
     969                return False 
     970        return True 
     971 
    954972    def save_scheme(self): 
    955973        """Save the current scheme. If the scheme does not have an associated 
     
    962980        curr_scheme = document.scheme() 
    963981 
    964         if document.path(): 
     982        if document.path() and self.check_can_save(document, document.path()): 
    965983            curr_scheme.save_to(open(document.path(), "wb")) 
    966984            document.setModified(False) 
     
    9991017        if filename: 
    10001018            filename = unicode(filename) 
     1019            if not self.check_can_save(document, filename): 
     1020                return QDialog.Rejected 
     1021 
    10011022            dirname, basename = os.path.split(filename) 
    10021023            self.last_scheme_dir = dirname 
  • Orange/OrangeCanvas/scheme/readwrite.py

    r11303 r11305  
    2828class UnknownWidgetDefinition(Exception): 
    2929    pass 
     30 
     31 
     32def sniff_version(stream): 
     33    """ 
     34    Parse a scheme stream and return the scheme's version string. 
     35    """ 
     36    doc = parse(stream) 
     37    scheme_el = doc.getroot() 
     38    version = scheme_el.attrib.get("version", None) 
     39    # Fallback: check for "widgets" tag. 
     40    if scheme_el.find("widgets") is not None: 
     41        version = "1.0" 
     42    else: 
     43        version = "2.0" 
     44 
     45    return version 
    3046 
    3147 
Note: See TracChangeset for help on using the changeset viewer.