--- PyRoom/autosave.py 2010-08-18 18:36:35.514918948 +0200 +++ PyRoom/autosave.py 2010-08-18 18:33:20.227374647 +0200 @@ -25,26 +25,21 @@ provide autosave functions import gobject from pyroom_error import PyroomError import os -from globals import config +from globals import config, state def start_autosave(edit_instance): - """start the autosave timer""" + """start the autosave timer""" timeout_id = gobject.timeout_add(1000, autosave_timeout, edit_instance) edit_instance.autosave_timeout_id = timeout_id edit_instance.autosave_elapsed = 0 def stop_autosave(edit_instance): - """stop the autosave timer and remove backup files""" - for buf in edit_instance.buffers: - autosave_fn = get_autosave_filename(buf.filename) - if not buf.filename == edit_instance.UNNAMED_FILENAME and \ - os.path.isfile(autosave_fn): - os.remove(autosave_fn) + """stop the autosave timer""" gobject.source_remove(edit_instance.autosave_timeout_id) def autosave_timeout(edit_instance): """see if we have to autosave open files""" - if config.getint('editor', 'autosavetime'): + if config.getint('editor', 'autosave'): if edit_instance.autosave_elapsed >= \ config.getint('editor', 'autosavetime') * 60: autosave(edit_instance) @@ -57,7 +52,7 @@ def get_autosave_filename(filename): """get the filename autosave would happen to""" SUFFIX = ".pyroom-autosave" autosave_filename = os.path.join( - os.path.dirname(filename), + state['autosave_dir'], ".%s%s" % (os.path.basename(filename), SUFFIX) ) return autosave_filename --- PyRoom/basic_edit.py 2010-08-18 18:36:35.534624965 +0200 +++ PyRoom/basic_edit.py 2010-08-18 18:19:27.514614061 +0200 @@ -598,6 +598,11 @@ the file.') buf.begin_not_undoable_action() buf.end_not_undoable_action() self.status.set_text(_('File %s saved') % buf.filename) + + # Delete backup if exists + path_to_backup = autosave.get_autosave_filename(buf.filename) + if os.path.isfile(path_to_backup): + os.remove(path_to_backup) else: self.save_file_as() return @@ -693,14 +698,6 @@ continue editing your document.") def close_buffer(self): """ Close current buffer """ - autosave_fname = autosave.get_autosave_filename( - self.buffers[self.current].filename - ) - if os.path.isfile(autosave_fname): - try: - os.remove(autosave_fname) - except OSError: - raise PyroomError(_('Could not delete autosave file.')) if len(self.buffers) > 1: self.buffers.pop(self.current) self.current = min(len(self.buffers) - 1, self.current) --- PyRoom/globals.py 2010-08-18 18:36:35.531003799 +0200 +++ PyRoom/globals.py 2010-08-18 18:31:23.242626301 +0200 @@ -63,6 +63,7 @@ state = dict( conf_dir = os.path.join(config_home, 'pyroom'), data_dir = os.path.join(data_home, 'pyroom'), themes_dir = os.path.join(data_home, 'pyroom', 'themes'), + autosave_dir = os.path.join(data_home, 'pyroom', 'autosave'), # XXX: works only in linux global_themes_dir = '/usr/share/pyroom/themes', ) @@ -82,6 +83,6 @@ config = FailsafeConfigParser() config_file = os.path.join(state['conf_dir'], 'pyroom.conf') if os.path.isfile(config_file): config.readfp(open(config_file, 'r')) -for d in [state['conf_dir'], state['themes_dir']]: +for d in [state['conf_dir'], state['themes_dir'], state['autosave_dir']]: if not os.path.isdir(d): os.makedirs(d) --- PyRoom/preferences.py 2010-08-18 18:36:35.518651082 +0200 +++ PyRoom/preferences.py 2010-08-18 18:19:27.514614061 +0200 @@ -354,7 +354,7 @@ class Preferences(object): if self.autosave.get_active(): self.autosave_spinbutton.set_sensitive(True) autosave_time = self.autosave_spinbutton.get_value_as_int() - config.set('editor', 'autosavee', '1') + config.set('editor', 'autosave', '1') else: self.autosave_spinbutton.set_sensitive(False) autosave_time = 0