Anonymous avatar Anonymous committed bcddcdb

refactor code into functions

Comments (0)

Files changed (1)

 import unicodedata
 import re
 
-CSS = "body{width=100%;}\n"
-PROC_HTML_TEMPLATE = ""
+PROC_CSS = "body{width=100%;}\n"
+PROC_TEMPLATE = ""
+INDEX_TEMPLATE = ""
 
 def slugify(value):
     """
 
         return response
 
+def prepare(root) :
+        # create sub directory if it doesnt exist
+        outDirectory = os.path.join(
+                        root,
+                        "pdb"
+        )
+
+        if not os.path.exists(outDirectory):
+                os.makedirs(outDirectory)
+
+        return outDirectory
+
+def dump_css(outDirectory) :
+        # write css file
+        outFile = os.path.join(
+                outDirectory,
+                "proc.css"
+        )
+
+        with open(outFile,'w') as f:
+                f.write(PROC_CSS)
+
+        return None
+
+def dump_proc(proc, outFile, mode) :
+
+        with open(outFile, mode) as f :
+                f.write("author:\n%s\n"%proc.proc_author)
+                f.write("date:\n%s\n"%proc.proc_date)
+                f.write("cpy:\n%s\n"%proc.proc_copyright)
+                f.write("blurb:\n%s\n"%proc.proc_blurb)
+                f.write("help:\n%s\n"%proc.proc_help)
+
+        return None
+
 def dump_pdb() :
         MessageBox = ctypes.windll.user32.MessageBoxA
 
-        outDirectory = get_dir()
-        if("" == outDirectory) :
+        root = get_dir()
+        if("" == root) :
                 return None
 
-        outFile = os.path.join(
-                outDirectory,
-                "main.css"
-        )
+        outDirectory = prepare(root)
+        dump_css(outDirectory)
 
-        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]
+        # loop through PDB
+        procs = gimp.pdb.query()
+        procs.sort()
+        for i in range(len(procs)):
+                name = procs[i]
                 outFile = os.path.join(
                         outDirectory,
-                        "pdb",
-                        "%s%s"%(slugify(name), ".txt")
+                        "%s%s"%(slugify(name), ".html")
                 )
 
-                #MessageBox(None, str(outFile), "Hiro, Gaia!", 0)
+                dump_proc(pdb[name], outFile, 'w+')
 
-                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)
+        # write index file
 
         return None
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.