filter RNA classes for translation (removes over 1300 lines from messages.txt)
authorCampbell Barton <ideasman42@gmail.com>
Wed, 5 Oct 2011 03:39:22 +0000 (03:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 5 Oct 2011 03:39:22 +0000 (03:39 +0000)
- omit operators tagged as INTERNAL
- omit classes  for internal use: Event, Context, Property, Function, Window.

po/update_msg.py
release/scripts/modules/bpy/ops.py
source/blender/python/intern/bpy_operator.c

index 9fc9967146d70c1fdaf6f6fbde9ba272f2534ffd..e91371c17551c00782d688d27a15d387a032b506 100644 (file)
@@ -17,7 +17,7 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-# <pep8 compliant>
+# <pep8-80 compliant>
 
 # Write out messages.txt from blender
 
@@ -36,6 +36,71 @@ COMMENT_PREFIX = "#~ "
 def dump_messages_rna(messages):
     import bpy
 
+    def classBlackList():
+        blacklist_rna_class = [
+                               # core classes
+                               "Context", "Event", "Function", "UILayout",
+                               "BlendData",
+                               # registerable classes
+                               "Panel", "Menu", "Header", "RenderEngine",
+                               "Operator", "OperatorMacro", "UnknownType"
+                               # window classes
+                               "WindowManager", "Window"
+                               ]
+
+        # ---------------------------------------------------------------------
+        # Collect internal operators
+
+        # extend with all internal operators
+        # note that this uses internal api introspection functions
+        # all possible operator names
+        op_names = list(sorted(set(
+            [cls.bl_rna.identifier for cls in
+             bpy.types.OperatorProperties.__subclasses__()] +
+            [cls.bl_rna.identifier for cls in
+             bpy.types.Operator.__subclasses__()] +
+            [cls.bl_rna.identifier for cls in
+             bpy.types.OperatorMacro.__subclasses__()]
+            )))
+
+        get_inatance = __import__("_bpy").ops.get_instance
+        path_resolve = type(bpy.context).__base__.path_resolve
+        for idname in op_names:
+            op = get_inatance(idname)
+            if 'INTERNAL' in path_resolve(op, "bl_options"):
+                blacklist_rna_class.append(idname)
+
+        # ---------------------------------------------------------------------
+        # Collect builtin classes we dont need to doc
+        blacklist_rna_class.append("Property")
+        blacklist_rna_class.extend(
+                [cls.__name__ for cls in
+                 bpy.types.Property.__subclasses__()])
+
+        # ---------------------------------------------------------------------
+        # Collect classes which are attached to collections, these are api
+        # access only.
+        collection_props = set()
+        for cls_id in dir(bpy.types):
+            cls = getattr(bpy.types, cls_id)
+            for prop in cls.bl_rna.properties:
+                if prop.type == 'COLLECTION':
+                    prop_cls = prop.srna
+                    if prop_cls is not None:
+                        collection_props.add(prop_cls.identifier)
+        blacklist_rna_class.extend(sorted(collection_props))
+
+        return blacklist_rna_class
+
+    blacklist_rna_class = classBlackList()
+
+    def filterRNA(bl_rna):
+        id = bl_rna.identifier
+        if id in blacklist_rna_class:
+            print("  skipping", id)
+            return True
+        return False
+
     # -------------------------------------------------------------------------
     # Function definitions
 
@@ -70,6 +135,10 @@ def dump_messages_rna(messages):
                     messages.setdefault(item.description, []).append(msgsrc)
 
     def walkRNA(bl_rna):
+
+        if filterRNA(bl_rna):
+            return
+
         msgsrc = "bpy.types.%s" % bl_rna.identifier
 
         if bl_rna.name and bl_rna.name != bl_rna.identifier:
index 64c5a1a5f5fcf52d9e90f93110623bbf805091e1..ba9f6dafd191e908c66a9ce44071384afaecd007 100644 (file)
@@ -27,6 +27,7 @@ op_poll = ops_module.poll
 op_call = ops_module.call
 op_as_string = ops_module.as_string
 op_get_rna = ops_module.get_rna
+op_get_instance = ops_module.get_instance
 
 
 class BPyOps(object):
@@ -184,11 +185,13 @@ class BPyOpsSubModOp(object):
         return ret
 
     def get_rna(self):
-        '''
-        currently only used for 'bl_rna'
-        '''
+        """Internal function for introspection"""
         return op_get_rna(self.idname())
 
+    def get_instance(self):
+        """Internal function for introspection"""
+        return op_get_instance(self.idname())
+
     def __repr__(self):  # useful display, repr(op)
         import bpy
         idname = self.idname()
index 7327679cc7e06b10166a2b96f083c314f4658976..dedc5df1f1c13316f322175ac1420cb695f3524a 100644 (file)
@@ -408,12 +408,51 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
        return (PyObject *)pyrna;
 }
 
+static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value)
+{
+       wmOperatorType *ot;
+       wmOperator *op;
+       PointerRNA ptr;
+       char *opname= _PyUnicode_AsString(value);
+       BPy_StructRNA *pyrna= NULL;
+
+       if(opname==NULL) {
+               PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_instance() expects a string argument");
+               return NULL;
+       }
+       ot= WM_operatortype_find(opname, TRUE);
+       if(ot==NULL) {
+               PyErr_Format(PyExc_KeyError, "_bpy.ops.get_instance(\"%s\") not found", opname);
+               return NULL;
+       }
+
+#ifdef PYRNA_FREE_SUPPORT
+       op= MEM_callocN(sizeof(wmOperator), __func__);
+#else
+       op= PyMem_MALLOC(sizeof(wmOperator));
+       memset(op, 0, sizeof(wmOperator));
+#endif
+       BLI_strncpy(op->idname, op->idname, sizeof(op->idname)); /* incase its needed */
+       op->type= ot;
+
+       RNA_pointer_create(NULL, &RNA_Operator, op, &ptr);
+
+       pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
+#ifdef PYRNA_FREE_SUPPORT
+       pyrna->freeptr= TRUE;
+#endif
+       op->ptr= &pyrna->ptr;
+
+       return (PyObject *)pyrna;
+}
+
 static struct PyMethodDef bpy_ops_methods[]= {
        {"poll", (PyCFunction) pyop_poll, METH_VARARGS, NULL},
        {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL},
        {"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL},
        {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL},
-       {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL},
+       {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL},           /* only for introspection, leaks memory */
+       {"get_instance", (PyCFunction) pyop_getinstance, METH_O, NULL}, /* only for introspection, leaks memory */
        {"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL},
        {NULL, NULL, 0, NULL}
 };