Hi all,

periodical autosave is long standing demand (bug 138373).
While in my regard this is headed in a totally wrong direction [1],
there's nothing wrong with having a plugin that works this way.

Somewhat suprisingly, i couldn't find such a plugin, so here's some
dirty PyGIMP which at first glance seems to do the job. Perhaps someone
gets inspired to create something worth uploading to the registry.

Usage:
- start GIMP from a terminal  (so the script's messages become visible)
- toolbox: File->Activate Autosave     (activate only once)

Every 30 minutes the script saves backups of all opened images to a temp folder.
The backup files won't be deleted when GIMP exits, so some manual clean-up will
be required from time to time.


have fun,
peter


[1] http://bugzilla.gnome.org/show_bug.cgi?id=138373#c25


#!/usr/bin/env python


import tempfile, os
from time import *
from gimpfu import *


def autosave():
    backupInterval = 30*60

    backupFiles = {}
    print "Autosave activated"

    while 1:
        sleep(backupInterval)

        print ctime(time())

        curImages = {}
        for k in gimp.image_list():
            curImages[k.ID] = k

        curIDs = curImages.keys()
        oldIDs = backupFiles.keys()

        newIDs = [x for x in curIDs if x not in oldIDs];
        delIDs = [x for x in oldIDs if x not in curIDs];

        # create (empty) backup files for new images
        for id in newIDs:
            prefix = 'gimpbackup-ID' + str(id) + '-'
            fn = tempfile.mkstemp(prefix = prefix, suffix = '.xcf')
            os.close(fn[0])
            backupFiles[id] = fn[1]

        # remove closed images' backups
        for id in delIDs:
            filename = backupFiles[id]
            del(backupFiles[id])
            try:
                os.remove(filename)
            except:
                print "ERROR: ", sys.exc_info()[0]

        # backup images
        for id, filename in backupFiles.iteritems():
            img = curImages[id]
            try:
                print "saving " + img.name + '-' + str(id) + ' to ' + filename
                pdb.gimp_xcf_save(1, img, img.active_drawable, filename, 
filename)
            except:
                print "ERROR: ", sys.exc_info()[0]




register(
        "autosave",
        "Autosave dirty hack",
        "Periodically saves all opened images to a temp directory",
        "public domain",
        "public domain",
        "2009",
        "<Toolbox>/File/Activate Autosave",
        "RGB*, GRAY*",
        [],
        [],
        autosave)

main()


_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to