Page MenuHome

new_python_unpack.patch

Authored By
Pablo Martin (caedes)
Nov 13 2013, 12:57 PM
Size
15 KB
Subscribers
None

new_python_unpack.patch

Index: source/blender/python/api2_2x/Blender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Blender.c,v
retrieving revision 1.80
diff -u -r1.80 Blender.c
--- source/blender/python/api2_2x/Blender.c 23 Apr 2006 17:01:03 -0000 1.80
+++ source/blender/python/api2_2x/Blender.c 6 May 2006 04:58:57 -0000
@@ -54,6 +54,7 @@
#include "BSE_headerbuttons.h"
#include "DNA_screen_types.h" /* for SPACE_VIEW3D */
#include "DNA_userdef_types.h"
+#include "DNA_packedFile_types.h"
#include "EXPP_interface.h" /* for bpy_gethome() */
#include "gen_utils.h"
#include "modules.h"
@@ -107,6 +108,9 @@
static PyObject *Blender_RemoveFakeuser(PyObject *self, PyObject *args);
static PyObject *Blender_ShowHelp( PyObject * self, PyObject * args );
static PyObject *Blender_UpdateMenus( PyObject * self);
+static PyObject *Blender_PackAll( PyObject * self);
+static PyObject *Blender_UnpackAll( PyObject * self, PyObject * args);
+static PyObject *Blender_CountPackedFiles( PyObject * self );
extern PyObject *Text3d_Init( void ); /* missing in some include */
@@ -184,6 +188,17 @@
"() - Update the menus where scripts are registered. Only needed for\n\
scripts that save other new scripts in the default or user defined folders.";
+static char Blender_PackAll_doc[] =
+"() - Pack all files.\n\
+All files will packed into the blend file.";
+static char Blender_UnpackAll_doc[] =
+"(mode) - Unpack all files.\n\
+All files will be unpacked using specified mode.\n\n\
+(mode) - the unpack mode.";
+
+static char Blender_CountPackedFiles_doc[] =
+"() - Returns the number of packed files.";
+
/*****************************************************************************/
/* Python method structure definition. */
/*****************************************************************************/
@@ -197,6 +212,9 @@
{"Run", Blender_Run, METH_VARARGS, Blender_Run_doc},
{"RemoveFakeuser", Blender_RemoveFakeuser, METH_VARARGS, Blender_RemoveFakeuser_doc},
{"ShowHelp", Blender_ShowHelp, METH_VARARGS, Blender_ShowHelp_doc},
+ {"CountPackedFiles", ( PyCFunction ) Blender_CountPackedFiles, METH_NOARGS, Blender_CountPackedFiles_doc},
+ {"PackAll", ( PyCFunction ) Blender_PackAll, METH_NOARGS, Blender_PackAll_doc},
+ {"UnpackAll", Blender_UnpackAll, METH_VARARGS, Blender_UnpackAll_doc},
{"UpdateMenus", ( PyCFunction ) Blender_UpdateMenus, METH_NOARGS,
Blender_UpdateMenus_doc},
{NULL, NULL, 0, NULL}
@@ -801,7 +819,55 @@
return Py_None;
}
+/*****************************************************************************/
+/* Function: Blender_PackAll */
+/* Python equivalent: Blender.PackAll */
+/*****************************************************************************/
+static PyObject *Blender_PackAll( PyObject * self)
+{
+ packAll();
+ Py_RETURN_NONE;
+}
+/*****************************************************************************/
+/* Function: Blender_UnpackAll */
+/* Python equivalent: Blender.UnpackAll */
+/*****************************************************************************/
+static PyObject *Blender_UnpackAll( PyObject * self, PyObject *args)
+{
+ int mode;
+ PyArg_ParseTuple( args, "i", &mode );
+ unpackAll(mode);
+ Py_RETURN_NONE;
+}
+
+/*****************************************************************************/
+/* Function: Blender_CountPackedFiles */
+/* Python equivalent: Blender.CountPackedFiles */
+/*****************************************************************************/
+static PyObject *Blender_CountPackedFiles( PyObject * self )
+{
+ int nfiles = countPackedFiles();
+ return PyInt_FromLong( nfiles );
+}
+static PyObject *Blender_UnpackModesDict( void )
+{
+ PyObject *UnpackModes = PyConstant_New( );
+ if( UnpackModes ) {
+ BPy_constant *d = ( BPy_constant * ) UnpackModes;
+ PyConstant_Insert( d, "EQUAL", PyInt_FromLong((long)PF_EQUAL) );
+ PyConstant_Insert( d, "DIFFERS",PyInt_FromLong((long)PF_DIFFERS) );
+ PyConstant_Insert( d, "NOFILE", PyInt_FromLong((long)PF_NOFILE) );
+ PyConstant_Insert( d, "WRITE_ORIGINAL", PyInt_FromLong((long)PF_WRITE_ORIGINAL) );
+ PyConstant_Insert( d, "WRITE_LOCAL", PyInt_FromLong((long)PF_WRITE_LOCAL) );
+ PyConstant_Insert( d, "USE_LOCAL", PyInt_FromLong((long)PF_USE_LOCAL) );
+ PyConstant_Insert( d, "USE_ORIGINAL", PyInt_FromLong((long)PF_USE_ORIGINAL) );
+ PyConstant_Insert( d, "KEEP", PyInt_FromLong((long)PF_KEEP) );
+ PyConstant_Insert( d, "NOOP", PyInt_FromLong((long)PF_NOOP) );
+ PyConstant_Insert( d, "ASK", PyInt_FromLong((long)PF_EQUAL) );
+ }
+ return UnpackModes;
+}
/*****************************************************************************/
/* Function: initBlender */
@@ -809,7 +875,7 @@
void M_Blender_Init(void)
{
PyObject *module;
- PyObject *dict, *smode, *SpaceHandlers;
+ PyObject *dict, *smode, *SpaceHandlers, *UnpackModes;
/* G.scene should only aver be NULL if blender is executed in
background mode, not loading a blend file and executing a python script eg.
@@ -827,6 +893,11 @@
types_InitAll(); /* set all our pytypes to &PyType_Type */
+ // constants for packed files
+ UnpackModes = Blender_UnpackModesDict( );
+ if( UnpackModes )
+ PyModule_AddObject( module, "UnpackModes", UnpackModes );
+
SpaceHandlers = PyConstant_New();
if (SpaceHandlers) {
BPy_constant *d = (BPy_constant *)SpaceHandlers;
Index: source/blender/python/api2_2x/Image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Image.c,v
retrieving revision 1.45
diff -u -r1.45 Image.c
--- source/blender/python/api2_2x/Image.c 16 Apr 2006 15:28:50 -0000 1.45
+++ source/blender/python/api2_2x/Image.c 6 May 2006 04:58:58 -0000
@@ -166,7 +166,7 @@
{"save", ( PyCFunction ) Image_save, METH_NOARGS,
"() - Write image buffer to file"},
{"unpack", ( PyCFunction ) Image_unpack, METH_VARARGS,
- "(int) - Unpack image. [0,1,2], Never overwrite, Overwrite if different, Overwrite all."},
+ "(int) - Unpack image. Uses the values defined in Blender.UnpackModes."},
{"pack", ( PyCFunction ) Image_pack, METH_NOARGS,
"() Pack the image"},
{NULL, NULL, 0, NULL}
@@ -642,19 +642,12 @@
"could not determine min x or y" );
}
-
-/* unpack
-mode 0; never overwrite
-mode 1; overwrite only if differs packed.
-mode 2; always overwrite.
-*/
-
+/* unpack image */
static PyObject *Image_unpack( BPy_Image * self, PyObject * args )
{
Image *image = self->image;
- int mode, check, ret=RET_OK; /* offset into image data */
- char expandpath[FILE_MAXDIR + FILE_MAXFILE];
+ int mode;
/*get the absolute path */
if( !PyArg_ParseTuple( args, "i", &mode ) )
@@ -665,41 +658,19 @@
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"image not packed" );
- BLI_strncpy(expandpath, image->name, FILE_MAXDIR+FILE_MAXFILE);
- BLI_convertstringcode(expandpath, G.sce, 1);
- check= checkPackedFile(expandpath, image->packedfile);
-
- if (check==PF_NOFILE) {
- ret= writePackedFile(expandpath, image->packedfile, 0); /* no guimode */
- } else if (check==PF_EQUAL){
- if (mode==2) /*always overwrite */
- ret= writePackedFile(expandpath, image->packedfile, 0);
- } else if (check==PF_DIFFERS) {
- if (mode!=0)
- ret= writePackedFile(expandpath, image->packedfile, 0); /* no guimode */
- }
-
- if (ret==RET_ERROR)
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "internal unpacking error, could not write packed image, image still packed." );
-
- /*free packed data*/
- freePackedFile(image->packedfile);
- image->packedfile=NULL;
-
- /*free icon*/
- BKE_icon_delete(&image->id);
- image->id.icon_id = 0;
-
+ unpackImage(image, mode);
Py_RETURN_NONE;
}
+/* pack image */
+
static PyObject *Image_pack( BPy_Image * self )
{
Image *image = self->image;
char expandpath[FILE_MAXDIR + FILE_MAXFILE];
BLI_strncpy(expandpath, image->name, FILE_MAXDIR+FILE_MAXFILE);
-
+ BLI_convertstringcode(expandpath, G.sce, 1);
+
if (image->packedfile )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"image alredy packed" );
Index: source/blender/python/api2_2x/Sound.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Sound.c,v
retrieving revision 1.6
diff -u -r1.6 Sound.c
--- source/blender/python/api2_2x/Sound.c 18 Jul 2005 03:50:37 -0000 1.6
+++ source/blender/python/api2_2x/Sound.c 6 May 2006 04:58:59 -0000
@@ -35,7 +35,9 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BLI_blenlib.h"
+#include "BKE_sound.h"
#include "BIF_editsound.h"
+#include "BKE_packedFile.h"
#include "mydevice.h" /* redraw defines */
#include "gen_utils.h"
@@ -123,6 +125,8 @@
static PyObject *Sound_getFilename( BPy_Sound * self );
static PyObject *Sound_play( BPy_Sound * self );
static PyObject *Sound_setCurrent( BPy_Sound * self );
+static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args);
+static PyObject *Sound_pack( BPy_Sound * self );
//static PyObject *Sound_reload ( BPy_Sound * self );
SOUND_FLOAT_METHODS( Volume, volume )
SOUND_FLOAT_METHODS( Attenuation, attenuation )
@@ -148,7 +152,10 @@
"() - play this sound"},
{"setCurrent", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
"() - make this the active sound in the sound buttons win (also redraws)"},
-
+ {"unpack", ( PyCFunction ) Sound_unpack, METH_VARARGS,
+ "(int) - Unpack sound. Uses one of the values defined in Blender.UnpackModes."},
+ {"pack", ( PyCFunction ) Sound_pack, METH_NOARGS,
+ "() Pack the sound"},
/*
{"reload", ( PyCFunction ) Sound_setCurrent, METH_NOARGS,
"() - reload this Sound object's sample.\n\
@@ -428,6 +435,55 @@
Py_INCREF( Py_None );
return Py_None;
}
+
+/* unpack sound */
+
+static PyObject *Sound_unpack( BPy_Sound * self, PyObject * args )
+{
+ bSound *sound = self->sound;
+ int mode;
+ if( !PyArg_ParseTuple( args, "i", &mode ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 1 integer" );
+
+ if (!sound_sample_is_null(sound))
+ {
+ bSample *sample = sound_find_sample(sound);
+ if (sample->packedfile==NULL)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound not packed" );
+ unpackSample(sample, mode);
+ }
+ else
+ {
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound has no samples" );
+ }
+ Py_RETURN_NONE;
+
+}
+
+/* pack sound */
+
+static PyObject *Sound_pack( BPy_Sound * self )
+{
+ bSound *sound = self->sound;
+ if (!sound_sample_is_null(sound))
+ {
+ bSample *sample = sound_find_sample(sound);
+ if (sample->packedfile )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound alredy packed" );
+ sound_set_packedfile(sample, newPackedFile(sample->name));
+ }
+ else
+ {
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "sound has no samples" );
+ }
+ Py_RETURN_NONE;
+}
+
/*
static PyObject *Sound_reload( BPy_Sound * self)
{
@@ -459,7 +515,19 @@
else if( strcmp( name, "__members__" ) == 0 )
attr = Py_BuildValue( "[s,s]", "name", "filename" );
-
+ else if( strcmp( name, "packed" ) == 0 ) {
+ if (!sound_sample_is_null(self->sound))
+ {
+ bSample *sample = sound_find_sample(self->sound);
+ if (sample->packedfile)
+ attr = EXPP_incr_ret_True();
+ else
+ attr = EXPP_incr_ret_False();
+ }
+ else
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "Sound has no sample to unpack!" ) );
+ }
if( !attr )
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyObject" ) );
@@ -538,3 +606,5 @@
return PyString_FromFormat( "[Sound \"%s\"]",
self->sound->id.name + 2 );
}
+
+
Index: source/blender/python/api2_2x/doc/Blender.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Blender.py,v
retrieving revision 1.37
diff -u -r1.37 Blender.py
--- source/blender/python/api2_2x/doc/Blender.py 3 Oct 2005 19:12:11 -0000 1.37
+++ source/blender/python/api2_2x/doc/Blender.py 6 May 2006 04:58:59 -0000
@@ -12,6 +12,7 @@
B{New}: L{Run}, L{UpdateMenus}, new options to L{Get}, L{ShowHelp},
L{SpaceHandlers} dictionary.
+L{UnpackModes} dictionary.
Blender
=======
@@ -41,6 +42,12 @@
will exit as soon as it finishes rendering or executing a script
(ex: 'C{blender -b <blender file> -P <script>}'). Try 'C{blender -h}'
for more detailed informations.
+@type UnpackModes: constant dictionary
+@var UnpackModes: dictionary with available unpack modes.
+ - USE_LOCAL - use files in current directory (create when necessary)
+ - WRITE_LOCAL - write files in current directory (overwrite when necessary)
+ - USE_ORIGINAL - use files in original location (create when necessary)
+ - WRITE_ORIGINAL - write files in original location (overwrite when necessary)
@type SpaceHandlers: constant dictionary
@var SpaceHandlers: dictionary with space handler types.
- VIEW3D_EVENT;
@@ -192,6 +199,22 @@
data and will make them accessible via menus.
@note: only scripts that save other new scripts in the default or user
defined folders need to call this function.
+ """
+def UnpackAll (mode):
+ """
+ Unpack all files with specified mode.
+ @param mode: The Mode for unpacking. Must be one of the modes in
+ Blender.UnpackModes dictionary.
+ @type mode: int
+ """
+def PackAll ():
+ """
+ Pack all files.
+ """
+
+def Blender_CountPackedFiles():
+ """
+ Returns the number of packed files.
"""
def Quit ():
Index: source/blender/python/api2_2x/doc/Image.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Image.py,v
retrieving revision 1.15
diff -u -r1.15 Image.py
--- source/blender/python/api2_2x/doc/Image.py 27 Mar 2006 08:34:06 -0000 1.15
+++ source/blender/python/api2_2x/doc/Image.py 6 May 2006 04:59:00 -0000
@@ -320,9 +320,9 @@
def unpack(mode):
"""
Unpacks the image to the images filename.
- @param mode: if 0, the existing file located at filename will be used. 1, The file will be overwritten if its different. 2, always overwrite the existing image file.
+ @param mode: One of the values in Blender.UnpackModes dict.
@note: An error will be raised if the image is not packed or the filename path does not exist.
@returns: nothing
@rtype: none
@type mode: int
- """
\ No newline at end of file
+ """
Index: source/blender/python/api2_2x/doc/Sound.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Sound.py,v
retrieving revision 1.3
diff -u -r1.3 Sound.py
--- source/blender/python/api2_2x/doc/Sound.py 14 Sep 2005 11:04:13 -0000 1.3
+++ source/blender/python/api2_2x/doc/Sound.py 6 May 2006 04:59:00 -0000
@@ -50,6 +50,7 @@
This object gives access to Sounds in Blender.
@ivar name: The name of this Sound object.
@ivar filename: The filename (path) to the sound file loaded into this Sound
+ @ivar packed: Boolean, True when the sample is packed (readonly).
object.
"""
@@ -112,5 +113,23 @@
Set this sound's pitch.
@type f: float
@param f: the new pitch value in the range [-12.0, 12.0].
+ """
+
+ def pack():
+ """
+ Packs the sound's sample into the current blend file.
+ @note: An error will be raised if the sound is alredy packed, the filename path does not exist or the sound has no sample.
+ @returns: nothing
+ @rtype: none
+ """
+
+ def unpack(mode):
+ """
+ Unpacks the sound's sample to the samples filename.
+ @param mode: One of the values in Blender.UnpackModes dict.
+ @note: An error will be raised if the sound is alredy packed, the filename path does not exist or the sound has no sample.
+ @returns: nothing
+ @rtype: none
+ @type mode: int
"""

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
39/14/176cf0aa988cc10a81d386181ef5

Event Timeline