Commit bd0b4462b0c392da044497b99b91401b3902af11
1 parent
9bde801a
Exists in
master
and in
6 other branches
ENH: Create backup of the config.cfg FIX: #197
Showing
2 changed files
with
31 additions
and
9 deletions
Show diff stats
invesalius/invesalius.py
@@ -106,6 +106,8 @@ class SplashScreen(wx.SplashScreen): | @@ -106,6 +106,8 @@ class SplashScreen(wx.SplashScreen): | ||
106 | session.SetLanguage(lang) | 106 | session.SetLanguage(lang) |
107 | session.CreateSessionFile() | 107 | session.CreateSessionFile() |
108 | 108 | ||
109 | + session.SaveConfigFileBackup() | ||
110 | + | ||
109 | # Only after language was defined, splash screen will be | 111 | # Only after language was defined, splash screen will be |
110 | # shown | 112 | # shown |
111 | if lang: | 113 | if lang: |
invesalius/session.py
1 | import ConfigParser | 1 | import ConfigParser |
2 | import os | 2 | import os |
3 | +import shutil | ||
3 | from threading import Thread | 4 | from threading import Thread |
4 | import time | 5 | import time |
5 | 6 | ||
@@ -51,6 +52,25 @@ class Session(object): | @@ -51,6 +52,25 @@ class Session(object): | ||
51 | def StopRecording(self, pubsub_evt): | 52 | def StopRecording(self, pubsub_evt): |
52 | self.ws.Stop() | 53 | self.ws.Stop() |
53 | 54 | ||
55 | + def SaveConfigFileBackup(self): | ||
56 | + path = os.path.join(self.homedir , | ||
57 | + '.invesalius', 'config.cfg') | ||
58 | + path_dst = os.path.join(self.homedir , | ||
59 | + '.invesalius', 'config.backup') | ||
60 | + shutil.copy(path, path_dst) | ||
61 | + | ||
62 | + def RecoveryConfigFile(self): | ||
63 | + homedir = self.homedir = os.path.expanduser('~') | ||
64 | + try: | ||
65 | + path = os.path.join(self.homedir , | ||
66 | + '.invesalius', 'config.backup') | ||
67 | + path_dst = os.path.join(self.homedir , | ||
68 | + '.invesalius', 'config.cfg') | ||
69 | + shutil.copy(path, path_dst) | ||
70 | + return True | ||
71 | + except(IOError): | ||
72 | + return False | ||
73 | + | ||
54 | 74 | ||
55 | def CloseProject(self): | 75 | def CloseProject(self): |
56 | import constants as const | 76 | import constants as const |
@@ -171,7 +191,6 @@ class Session(object): | @@ -171,7 +191,6 @@ class Session(object): | ||
171 | return False | 191 | return False |
172 | 192 | ||
173 | def ReadSession(self): | 193 | def ReadSession(self): |
174 | - | ||
175 | config = ConfigParser.ConfigParser() | 194 | config = ConfigParser.ConfigParser() |
176 | home_path = os.path.expanduser('~') | 195 | home_path = os.path.expanduser('~') |
177 | path = os.path.join(home_path ,'.invesalius', 'config.cfg') | 196 | path = os.path.join(home_path ,'.invesalius', 'config.cfg') |
@@ -186,15 +205,16 @@ class Session(object): | @@ -186,15 +205,16 @@ class Session(object): | ||
186 | self.tempdir = config.get('paths','tempdir') | 205 | self.tempdir = config.get('paths','tempdir') |
187 | self.last_dicom_folder = config.get('paths','last_dicom_folder') | 206 | self.last_dicom_folder = config.get('paths','last_dicom_folder') |
188 | self.last_dicom_folder = self.last_dicom_folder.decode('utf-8') | 207 | self.last_dicom_folder = self.last_dicom_folder.decode('utf-8') |
189 | - #print "_______________________________" | ||
190 | - #print self.last_dicom_folder | ||
191 | - #print type(self.last_dicom_folder) | ||
192 | - #print "_______________________________" | ||
193 | return True | 208 | return True |
194 | - except(ConfigParser.NoSectionError, | ||
195 | - ConfigParser.NoOptionError, | ||
196 | - ConfigParser.MissingSectionHeaderError): | ||
197 | - return False | 209 | + |
210 | + except(ConfigParser.NoSectionError, ConfigParser.NoOptionError, | ||
211 | + ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): | ||
212 | + | ||
213 | + if (self.RecoveryConfigFile()): | ||
214 | + self.ReadSession() | ||
215 | + return True | ||
216 | + else: | ||
217 | + return False | ||
198 | 218 | ||
199 | 219 | ||
200 | class WriteSession(Thread): | 220 | class WriteSession(Thread): |