dabodoc Commit
Revision 69
Date: 2011-03-30 01:47:36 -0700 (Wed, 30 Mar 2011)
Author: Werner
Trac: http://trac.dabodev.com/changeset/69

Changed:
A   trunk/api/sphinx/checkMissingImage.py
U   trunk/api/sphinx/genGallery.py
A   trunk/api/sphinx/resizeWidgetImages.py

Log:
- clean up
- add two little utility scripts

Diff:
Added: trunk/api/sphinx/checkMissingImage.py
===================================================================
--- trunk/api/sphinx/checkMissingImage.py                               (rev 0)
+++ trunk/api/sphinx/checkMissingImage.py       2011-03-30 08:47:36 UTC (rev 69)
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-#
+
+"""
+check that mac and nic folder has all images
+"""
+
+import os
+import glob
+
+import config
+
+imagesWin = glob.glob(os.path.join(config.docFolder, 
"_static/winWidgets/*.png"))
+imagesMac = glob.glob(os.path.join(config.docFolder, 
"_static/macWidgets/*.png"))
+imagesNix = glob.glob(os.path.join(config.docFolder, 
"_static/nixWidgets/*.png"))
+
+print "images missing for MAC"
+print "======================"
+imagesMacF = []
+for img in imagesMac:
+    tPath, tFile = os.path.split(img)
+    imagesMacF.append(tFile)
+
+for img in imagesWin:
+    tPath, tFile = os.path.split(img)
+    if not tFile in imagesMacF:
+        if not "_thumb" in tFile:
+            print tFile
+
+print "======================"
+print "images missing for Nix"
+print "======================"
+
+imagesNixF = []
+for img in imagesNix:
+    tPath, tFile = os.path.split(img)
+    imagesNixF.append(tFile)
+
+for img in imagesWin:
+    tPath, tFile = os.path.split(img)
+    if not tFile in imagesNixF:
+        if not "_thumb" in tFile:
+            print tFile

Modified: trunk/api/sphinx/genGallery.py
===================================================================
--- trunk/api/sphinx/genGallery.py      2011-03-30 08:45:21 UTC (rev 68)
+++ trunk/api/sphinx/genGallery.py      2011-03-30 08:47:36 UTC (rev 69)
@@ -21,89 +21,18 @@
 {%% endblock %%}
 """
 
-pattern = re.compile(r'{(.*?)}', re.DOTALL)
 
-
-def bylength(word1, word2):
-
-       return len(word2) - len(word1)
-
-
-def replace_epydoc_links(name, obj, line):
-
-       matches = pattern.findall(line)
-       matches.sort(cmp=bylength)
-
-       classes = lastMethods["class"]
-       newMatches = matches[:]
-
-       for m in matches:
-               newM = "L{%s}"%m
-               for kls, dummy in classes:
-                       if kls.endswith(m):
-                               line = line.replace(newM, ":class:`~%s`"%kls)
-                               newMatches.remove(m)
-                               break
-
-       matches = newMatches[:]
-       methods = lastMethods["method"]
-       
-       for m in matches:
-               newM = "L{%s}"%m
-               for kls, method in methods:
-                       if m in method:
-                               if "." not in m:
-                                       index = name.rfind(".")
-                                       newname = name[0:index] + "." + m
-                                       index2 = newname.rfind(".")
-                                       othername = newname[0:index2] + "." + m
-                                       
-                                       if newname == method:
-                                               line = line.replace(newM, 
":meth:`~%s`"%method)
-                                               newMatches.remove(m)
-                                               break
-                                       elif othername.endswith(method):
-                                               line = line.replace(newM, 
":meth:`~%s`"%method)
-                                               newMatches.remove(m)
-                                               break
-                                       elif m == "CmpThumb":
-                                               line = line.replace(newM, 
":meth:`~thumbnailctrl.CmpThumb`")
-                                               newMatches.remove(m)
-                                               break
-                                               
-                               else:
-                                       if method.endswith(m):
-                                               line = line.replace(newM, 
":meth:`%s() <%s>`"%(m, method))
-                                               newMatches.remove(m)
-                                               break
-                                       
-
-       if newMatches:
-               print "\n==================================================="
-               print "UNCONVERTED LINKS IN %s:"%name
-               print "===================================================", 
"\n"
-               for m in newMatches:
-                       print " "*4, m
-
-               print "\n\n"
-               
-       return line
-
-
 def gen_gallery(app, doctree):
-
-##    print 'gen_gallery: %s, %s' % (app, app.builder.name)
        
        if app.builder.name not in ['html', 'singlehtml']:
                return
 
+       print 'gen_gallery: %s, %s' % (app, app.builder.name)
+
        outdir = app.builder.outdir
-##    print outdir
-##    print app.builder.srcdir
-##    rootdir = '_staticGallery/'
 
        link = '<div class="gallery_class">'
-##     <table><caption align="bottom"><b>%s</b></caption>
+
        link_template = """\
        <table><caption align="bottom"><a href="%s"<b>%s</b></a</caption>
        <tr><td><a href="%s"><img src="%s" border="5" alt="%s" width="100" 
height="100"/></a></td></tr>
@@ -114,56 +43,65 @@
        rows = ["<br/>", link]
 
        # need to join srcdir
-       for item in sorted(glob.glob(os.path.join(app.builder.srcdir, 
"_static/*_thumb.png"))):
-##        print "item: %s" % item
+       for item in sorted(glob.glob(os.path.join(app.builder.srcdir, 
"_static\\winWidgets\\*_thumb.png"))):
                path, filename = os.path.split(item)
                basename, ext = os.path.splitext(item)
                
-               # need to get rid of srcdir as links have to be relative
-               basename = basename.replace(app.builder.srcdir + "\\", "")
-               item = item.replace(app.builder.srcdir + "\\", "")
+               # get rid of _thumb and path
+               widgetName = basename.replace("_thumb", "")
+               widgetName = widgetName.replace(app.builder.srcdir + 
"\\_static\\winWidgets\\", "")
+               
+               # get rid of srcdir
+               thumbFile = item.replace(app.builder.srcdir + "\\", "")
+               # get rid of _thumb
+               largeFile = thumbFile.replace("_thumb", "")
+               # fix up path sep for html
+               thumbFile = thumbFile.replace("\\", "/")
+               largeFile = largeFile.replace("\\", "/")
 
-               realfile = basename[0:-6] + ext
-
-               realfile = realfile.replace("\\", "/")
-               item = item.replace("\\", "/")
-               # Create thumbnails based on images in tmpdir, and place
-               # them within the build tree
                linkName = ""
-               linkKey = basename[8:-6]
+               linkKey = widgetName
                linkKeyL = len(linkKey)
                if linkKey[linkKeyL-1:linkKeyL].isdigit():
                        linkKey = linkKey[:linkKeyL-1]
-               if galleryToClassIndex.pictureIndex.has_key(linkKey):
+               if galleryToClassIndex.pictureIndex.has_key(linkKey):
                        # lets find the documentation link for this image
                        linkName = galleryToClassIndex.pictureIndex[linkKey]
                else:
                        linkName = "gallery.html"
 ##             print "base: %s" % basename
-##             print "base2: %s" % basename[8:-6]
+##             print "widget: %s" % widgetName
 ##             print "linkKey: %s" % linkKey
-##             print realfile
-##             print item
-##             print linkName
+##             print "thumb: %s" % thumbFile
+##             print "large: %s" % largeFile
+##             print "link: %s" % linkName
 ##             print link_template
 
-               rows.append(link_template % (linkName, basename[8:-6], 
realfile, item, basename[8:-6]))
+               rows.append(link_template % (linkName, widgetName, largeFile, 
thumbFile, widgetName))
 
        rows.append("</div>")
        rows.append('<br clear="all"> ')
        
-##    # Only write out the file if the contents have actually changed.
-##    # Otherwise, this triggers a full rebuild of the docs
        content = template % '\n'.join(rows)
-##    print content
        gallery_path = os.path.join(app.builder.srcdir, '_templates', 
'gallery.html')
-##    print gallery_path
 
+### thought this would reduce build time
+##     # check if file has already up to date content
+##     fhCheck = file(gallery_path, 'r')
+##     oldContent = fhCheck.read()
+##     if oldContent.strip() == content.strip():
+##             print "gallery file is already up to date"
+##     else:
+##             fh = file(gallery_path, 'w')
+##             fh.write(content)
+##             fh.flush()
+##             fh.close()
+##             print "gallery file updated"
+
        fh = file(gallery_path, 'w')
        fh.write(content)
        fh.flush()
        fh.close()
-
        
 def setup(app):
 

Added: trunk/api/sphinx/resizeWidgetImages.py
===================================================================
--- trunk/api/sphinx/resizeWidgetImages.py                              (rev 0)
+++ trunk/api/sphinx/resizeWidgetImages.py      2011-03-30 08:47:36 UTC (rev 69)
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-#
+
+"""
+take a list of images and size them to 400 x nnn and create a _thumb of 200 x 
nnn
+"""
+
+import PIL
+from PIL import Image
+import os
+import glob
+
+import config
+
+def resizeWidgets(widgets):
+    for img in images:
+        if not "_thumb" in img:
+            file, ext = os.path.splitext(img)
+            im = Image.open(img)
+            orgSize = im.size
+            orgFormat = im.format
+            # resize the big one
+            im.thumbnail((400, 400), Image.ANTIALIAS)
+            im.save(img, orgFormat)
+            print "resized image: %s\n" % img
+            im.thumbnail((200, 200), Image.ANTIALIAS)
+            tName = file + "_thumb" + ext
+            im.save(tName)
+            print "resized image: %s\n" % tName
+        
+
+print "resizing window images"
+images = glob.glob(os.path.join(config.docFolder, "_static/winWidgets/*.png"))
+resizeWidgets(images)
+
+print "resizing mac images"
+images = glob.glob(os.path.join(config.docFolder, "_static/macWidgets/*.png"))
+resizeWidgets(images)
+
+print "resizing linux images"
+images = glob.glob(os.path.join(config.docFolder, "_static/nixWidgets/*.png"))
+resizeWidgets(images)
+



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to