Skip to content

Commit

Permalink
Call enableBMFF in module init, if needed
Browse files Browse the repository at this point in the history
The user enableBMFF() function no longer does anything and is
deprecated.
  • Loading branch information
jim-easterbrook committed Aug 1, 2024
1 parent 2ebff92 commit 8326135
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/interface/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# python-exiv2 - Python interface to exiv2
# http://github.com/jim-easterbrook/python-exiv2
# Copyright (C) 2021-22 Jim Easterbrook jim@jim-easterbrook.me.uk
# Copyright (C) 2021-24 Jim Easterbrook jim@jim-easterbrook.me.uk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,7 +31,6 @@ def main():
print('python-exiv2 version:', exiv2.__version__)
print('python-exiv2 examples:',
os.path.join(os.path.dirname(__file__), 'examples'))
print('BMFF support:', exiv2.enableBMFF(False))
if args.verbosity:
print('libexiv2 build options:')
pprint.pprint(exiv2.versionInfo())
Expand Down
17 changes: 14 additions & 3 deletions src/interface/image.i
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,30 @@ Create a MemIo subclass of BasicIo using the provided memory.
}
}

// Enable BMFF if libexiv2 was compiled with BMFF support
%init %{
#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
Exiv2::enableBMFF(true);
#endif
%}

// Make enableBMFF() function available regardless of exiv2 version
%feature("docstring") enableBMFF "Enable BMFF support.
If libexiv2 has been built with BMFF support included it can be enabled
by calling enableBMFF(True).
If libexiv2 has been built with BMFF support it is already enabled
and this fubction does nothing.
:type enable: bool, optional
:param enable: Set to True to enable BMFF file access.
:rtype: bool
:return: True if libexiv2 has been built with BMFF support.";
%inline %{
static bool enableBMFF(bool enable) {
// deprecated since 2024-08-01
PyErr_WarnEx(PyExc_DeprecationWarning,
"BMFF is already enabled if libexiv2 was built with BMFF support",
1);
#ifdef EXV_ENABLE_BMFF
return Exiv2::enableBMFF(enable);
return true;
#else
return false;
#endif // EXV_ENABLE_BMFF
Expand Down
3 changes: 1 addition & 2 deletions src/swig-0_27_7/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# python-exiv2 - Python interface to exiv2
# http://github.com/jim-easterbrook/python-exiv2
# Copyright (C) 2021-22 Jim Easterbrook jim@jim-easterbrook.me.uk
# Copyright (C) 2021-24 Jim Easterbrook jim@jim-easterbrook.me.uk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,7 +31,6 @@ def main():
print('python-exiv2 version:', exiv2.__version__)
print('python-exiv2 examples:',
os.path.join(os.path.dirname(__file__), 'examples'))
print('BMFF support:', exiv2.enableBMFF(False))
if args.verbosity:
print('libexiv2 build options:')
pprint.pprint(exiv2.versionInfo())
Expand Down
19 changes: 14 additions & 5 deletions src/swig-0_27_7/image_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4358,8 +4358,12 @@ namespace Exiv2 {


static bool enableBMFF(bool enable) {
// deprecated since 2024-08-01
PyErr_WarnEx(PyExc_DeprecationWarning,
"BMFF is already enabled if libexiv2 was built with BMFF support",
1);
#ifdef EXV_ENABLE_BMFF
return Exiv2::enableBMFF(enable);
return true;
#else
return false;
#endif // EXV_ENABLE_BMFF
Expand Down Expand Up @@ -7047,8 +7051,8 @@ static PyMethodDef SwigMethods[] = {
{ "enableBMFF", _wrap_enableBMFF, METH_VARARGS, "\n"
"Enable BMFF support.\n"
"\n"
"If libexiv2 has been built with BMFF support included it can be enabled\n"
"by calling enableBMFF(True).\n"
"If libexiv2 has been built with BMFF support it is already enabled\n"
"and this fubction does nothing.\n"
":type enable: bool, optional\n"
":param enable: Set to True to enable BMFF file access.\n"
":rtype: bool\n"
Expand All @@ -7062,8 +7066,8 @@ SWIGINTERN PyGetSetDef SwigPyBuiltin__Exiv2__Image_getset[] = {
{ (char *)"__dict__", SwigPyBuiltin_FunpackGetterClosure, 0, (char *)"\n"
"Enable BMFF support.\n"
"\n"
"If libexiv2 has been built with BMFF support included it can be enabled\n"
"by calling enableBMFF(True).\n"
"If libexiv2 has been built with BMFF support it is already enabled\n"
"and this fubction does nothing.\n"
":type enable: bool, optional\n"
":param enable: Set to True to enable BMFF file access.\n"
":rtype: bool\n"
Expand Down Expand Up @@ -8887,6 +8891,11 @@ SWIG_init(void) {
}


#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
Exiv2::enableBMFF(true);
#endif


{
PyObject* module = PyImport_ImportModule("enum");
if (!module)
Expand Down
3 changes: 1 addition & 2 deletions src/swig-0_28_3/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# python-exiv2 - Python interface to exiv2
# http://github.com/jim-easterbrook/python-exiv2
# Copyright (C) 2021-22 Jim Easterbrook jim@jim-easterbrook.me.uk
# Copyright (C) 2021-24 Jim Easterbrook jim@jim-easterbrook.me.uk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,7 +31,6 @@ def main():
print('python-exiv2 version:', exiv2.__version__)
print('python-exiv2 examples:',
os.path.join(os.path.dirname(__file__), 'examples'))
print('BMFF support:', exiv2.enableBMFF(False))
if args.verbosity:
print('libexiv2 build options:')
pprint.pprint(exiv2.versionInfo())
Expand Down
19 changes: 14 additions & 5 deletions src/swig-0_28_3/image_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4358,8 +4358,12 @@ namespace Exiv2 {


static bool enableBMFF(bool enable) {
// deprecated since 2024-08-01
PyErr_WarnEx(PyExc_DeprecationWarning,
"BMFF is already enabled if libexiv2 was built with BMFF support",
1);
#ifdef EXV_ENABLE_BMFF
return Exiv2::enableBMFF(enable);
return true;
#else
return false;
#endif // EXV_ENABLE_BMFF
Expand Down Expand Up @@ -7073,8 +7077,8 @@ static PyMethodDef SwigMethods[] = {
{ "enableBMFF", _wrap_enableBMFF, METH_VARARGS, "\n"
"Enable BMFF support.\n"
"\n"
"If libexiv2 has been built with BMFF support included it can be enabled\n"
"by calling enableBMFF(True).\n"
"If libexiv2 has been built with BMFF support it is already enabled\n"
"and this fubction does nothing.\n"
":type enable: bool, optional\n"
":param enable: Set to True to enable BMFF file access.\n"
":rtype: bool\n"
Expand All @@ -7088,8 +7092,8 @@ SWIGINTERN PyGetSetDef SwigPyBuiltin__Exiv2__Image_getset[] = {
{ (char *)"__dict__", SwigPyBuiltin_FunpackGetterClosure, 0, (char *)"\n"
"Enable BMFF support.\n"
"\n"
"If libexiv2 has been built with BMFF support included it can be enabled\n"
"by calling enableBMFF(True).\n"
"If libexiv2 has been built with BMFF support it is already enabled\n"
"and this fubction does nothing.\n"
":type enable: bool, optional\n"
":param enable: Set to True to enable BMFF file access.\n"
":rtype: bool\n"
Expand Down Expand Up @@ -8904,6 +8908,11 @@ SWIG_init(void) {
}


#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
Exiv2::enableBMFF(true);
#endif


{
PyObject* module = PyImport_ImportModule("enum");
if (!module)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def check_result(self, result, expected_type, expected_value):
self.assertEqual(result, expected_value)

def test_BMFF(self):
self.assertEqual(exiv2.enableBMFF(True),
exiv2.versionInfo()['EXV_ENABLE_BMFF'])
with self.assertWarns(DeprecationWarning):
enabled = exiv2.enableBMFF(True)
self.assertEqual(enabled, exiv2.versionInfo()['EXV_ENABLE_BMFF'])
with open(self.bmff_path, 'rb') as f:
image_data = f.read()
if not exiv2.versionInfo()['EXV_ENABLE_BMFF']:
Expand Down

0 comments on commit 8326135

Please sign in to comment.