~umang/indicator-stickynotes/trunk

« back to all changes in this revision

Viewing changes to stickynotes/backend.py

  • Committer: Umang Varma
  • Date: 2012-06-24 20:58:10 UTC
  • Revision ID: git-v1:bb4997b7b2950637edf8cfc16d4637f8fd6135af
ConfigurationĀ fileĀ location/behaviorĀ changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import json
21
21
from os.path import expanduser
22
22
 
23
 
SETTINGS_FILE = "stickynotesrc"
 
23
SETTINGS_FILE = "~/.stickynotes"
24
24
 
25
25
class Note:
26
26
    def __init__(self, content=None, gui_class=None, noteset=None):
86
86
 
87
87
    def save(self, path=''):
88
88
        output = self.dumps()
89
 
        with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)),
 
89
        with open(path or expanduser(SETTINGS_FILE),
90
90
                mode='w', encoding='utf-8') as fsock:
91
91
            fsock.write(output)
92
92
 
93
93
    def open(self, path=''):
94
 
        with open(path or expanduser("~/.{0}".format(SETTINGS_FILE)), 
95
 
                encoding='utf-8') as fsock:
96
 
            self.loads(fsock.read())
 
94
        try:
 
95
            with open(path or expanduser(SETTINGS_FILE), 
 
96
                    encoding='utf-8') as fsock:
 
97
                self.loads(fsock.read())
 
98
        except IOError:
 
99
            self.loads('{}')
 
100
            self.new()
97
101
 
98
102
    def new(self):
99
103
        """Creates a new note and adds it to the note set"""