Commits

akalias  committed 9ca221a

added docs_as_dict() function to makeref.py, and ability to use it when imported while getcwd() other than trunk

  • Participants
  • Parent commits 3172fb9

Comments (0)

Files changed (1)

     alist = map(lambda x:x[1], keys_and_list)
     return alist
 
+def collect_doc_files():
+    # ABSPATH ONLY WORKS FOR docs_as_dict
+    #
+    # if __name__ == '__main__': Run()
+    #     must be ran from in trunk dir
+    
+    # get files and shuffle ordering
+    trunk_dir = os.path.abspath(os.path.dirname(__file__))
+    
+    src_dir = os.path.join(trunk_dir, 'src')
+    lib_dir = os.path.join(trunk_dir, 'lib')
+
+    pygame_doc = os.path.join(src_dir, "pygame.doc")
+
+    files = (
+        glob.glob(os.path.join(src_dir,'*.doc')) +
+        glob.glob(os.path.join(lib_dir,'*.doc'))
+    )
+
+    files.remove(pygame_doc)
+    
+    #XXX: sort(key=) is only available in >= python2.4
+    # files.sort(key=sortkey)
+    files = sort_list_by_keyfunc(files, sortkey)
+
+    files.insert(0, pygame_doc)
+
+    return files
 
 def Run():
-    # get files and shuffle ordering
-    files = glob.glob(os.path.join('src','*.doc')) + glob.glob(os.path.join('lib','*.doc'))
+    files = collect_doc_files()
     for file in files:
-        print file
-    files.remove(os.path.join("src","pygame.doc"))
-
-
-    #XXX: sort(key=) is only available in >= python2.4
-    #files.sort(key=sortkey)
-    files = sort_list_by_keyfunc(files, sortkey)
-
-    files.insert(0, os.path.join("src","pygame.doc"))
+        # print file
+        print os.path.basename(file)
+    
     docs = []
     pages = []
     for f in files:
     def __cmp__(self, b):
         return cmp(self.name.lower(), b.name.lower())
 
+def docs_as_dict():
+    """
 
+    Dict Format:
+
+        {'pygame.rect.Rect.center': 'Rect.center: ...' ...}
+
+    Generally works, has some workarounds, inspect results manually.
+
+    """
+
+    import pygame
+    files = collect_doc_files()
+
+    def make_mapping(doc, parent_name):
+        docs = {}
+        for k in doc.kids:
+            if k.docs:
+                kid_name = k.fullname
+
+                if parent_name == 'pygame':
+                    if hasattr(pygame.base, k.name):
+                        kid_name = '%s.%s' % ('pygame.base', k.name)
+
+                elif not kid_name.startswith(parent_name):
+                    kid_name = '%s.%s' % (parent_name, kid_name)
+
+                docs[kid_name] = '\n'.join(k.docs)
+
+            if k.kids:
+                docs.update(make_mapping(k, parent_name))
+        return docs
+
+    mapping = {}
+    for f in files:
+        doc = Doc('', open(f, "U"))
+        mapping.update(make_mapping(doc, doc.name.lower()))
+
+    return mapping
 
 HTMLHeader = """
 <html>
 </body></html>
 """
 
-
-
 if __name__ == '__main__':
-    Run()
-
+    Run()