Source

python-fu-dump / dump.py

Full commit
from gimpfu import *
from random import *
import gtk
import os
import collections
import ctypes
import unicodedata
import re

CSS = "body{width=100%;}\n"
PROC_HTML_TEMPLATE = ""

def slugify(value):
    """
    Normalizes string, converts to lowercase, removes non-alpha characters,
    and converts spaces to hyphens.

    Based on code in: Django
    """
    value = unicodedata.normalize('NFKD', unicode(value))
    value = value.encode('ascii', 'ignore')
    value = re.sub('[^\w\s-]', '', value).strip().lower()
    value = re.sub('[-\s]+', '-', value)
    return value

def get_dir() :
        MessageBox = ctypes.windll.user32.MessageBoxA
        response = ""

        # Check for new pygtk: this is new class in PyGtk 2.4
        if (gtk.pygtk_version < (2,3,90)) :
                MessageBox(None, "This plugin requires PyGtk 2.3.90 or later", "Error", 0)
                return response

        dialog = gtk.FileChooserDialog(
                "Dump to...",
                None,
                gtk.FILE_CHOOSER_ACTION_OPEN,
                (
                        gtk.STOCK_CANCEL,
                        gtk.RESPONSE_CANCEL,
                        gtk.STOCK_OPEN,
                        gtk.RESPONSE_OK
                )
        )
        dialog.set_default_response(gtk.RESPONSE_OK)
        dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)

        if (dialog.run() == gtk.RESPONSE_OK) :
                response = dialog.get_filename()
        dialog.destroy()

        return response

def dump_pdb() :
        MessageBox = ctypes.windll.user32.MessageBoxA

        outDirectory = get_dir()
        if("" == outDirectory) :
                return None

        outFile = os.path.join(
                outDirectory,
                "main.css"
        )

        with open(outFile,'w') as f:
                f.write(CSS)

        tmp = os.path.join(
                        outDirectory,
                        "pdb"
        )
        if not os.path.exists(tmp):
                os.makedirs(tmp)

        for name in gimp.pdb.query() :
                plugin = pdb[name]
                outFile = os.path.join(
                        outDirectory,
                        "pdb",
                        "%s%s"%(slugify(name), ".txt")
                )

                #MessageBox(None, str(outFile), "Hiro, Gaia!", 0)

                with open(outFile, 'w+') as f :
                        f.write("author:\n%s\n"%plugin.proc_author)
                        f.write("date:\n%s\n"%plugin.proc_date)
                        f.write("cpy:\n%s\n"%plugin.proc_copyright)
                        f.write("blurb:\n%s\n"%plugin.proc_blurb)
                        f.write("help:\n%s\n"%plugin.proc_help)

        return None

register(
        #name
        "dump-pdb",
        #blurb
        "dumps pdb database to HTML",
        #help
        "man up buttercup",
        #author
        "codefox",
        #copyright
        "MIT license => rtfm",
        #date
        "Jan 29, 2013",
        #menu path
        "<Toolbox>/Help/Procedure Dump",
        #image types
        None,
        #params
        [],
        #results
        [],
        #function
        dump_pdb
)

main()