~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to stickynotes/backend.py

  • Committer: Umang Varma
  • Date: 2015-07-01 23:29:38 UTC
  • Revision ID: git-v1:ee83e4d6176c589a124c33e1fb0c549ac4416875
Prompt backup when error reading data file

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
 
103
103
    def loads(self, snoteset):
104
104
        """Loads notes into their respective objects"""
105
 
        try:
106
 
            notes = self._loads_updater(json.loads(snoteset))
107
 
        except ValueError:
108
 
            notes = {}
 
105
        notes = self._loads_updater(json.loads(snoteset))
109
106
        self.properties = notes.get("properties", {})
110
107
        self.categories = notes.get("categories", {})
111
108
        self.notes = [Note(note, gui_class=self.gui_class, noteset=self)
122
119
            fsock.write(output)
123
120
 
124
121
    def open(self, path=''):
125
 
        try:
126
 
            with open(path or expanduser(self.data_file), 
127
 
                    encoding='utf-8') as fsock:
128
 
                self.loads(fsock.read())
129
 
        except IOError:
130
 
            self.loads('{}')
131
 
            self.new()
 
122
        with open(path or expanduser(self.data_file), 
 
123
                encoding='utf-8') as fsock:
 
124
            self.loads(fsock.read())
 
125
 
 
126
    def load_fresh(self):
 
127
        """Load empty data"""
 
128
        self.loads('{}')
 
129
        self.new()
132
130
 
133
131
    def new(self):
134
132
        """Creates a new note and adds it to the note set"""