Skip to content

Commit 8326135

Browse files
Call enableBMFF in module init, if needed
The user enableBMFF() function no longer does anything and is deprecated.
1 parent 2ebff92 commit 8326135

File tree

7 files changed

+48
-21
lines changed

7 files changed

+48
-21
lines changed

src/interface/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# python-exiv2 - Python interface to exiv2
22
# http://github.com/jim-easterbrook/python-exiv2
3-
# Copyright (C) 2021-22 Jim Easterbrook [email protected]
3+
# Copyright (C) 2021-24 Jim Easterbrook [email protected]
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,6 @@ def main():
3131
print('python-exiv2 version:', exiv2.__version__)
3232
print('python-exiv2 examples:',
3333
os.path.join(os.path.dirname(__file__), 'examples'))
34-
print('BMFF support:', exiv2.enableBMFF(False))
3534
if args.verbosity:
3635
print('libexiv2 build options:')
3736
pprint.pprint(exiv2.versionInfo())

src/interface/image.i

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,30 @@ Create a MemIo subclass of BasicIo using the provided memory.
139139
}
140140
}
141141

142+
// Enable BMFF if libexiv2 was compiled with BMFF support
143+
%init %{
144+
#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
145+
Exiv2::enableBMFF(true);
146+
#endif
147+
%}
148+
142149
// Make enableBMFF() function available regardless of exiv2 version
143150
%feature("docstring") enableBMFF "Enable BMFF support.
144151
145-
If libexiv2 has been built with BMFF support included it can be enabled
146-
by calling enableBMFF(True).
152+
If libexiv2 has been built with BMFF support it is already enabled
153+
and this fubction does nothing.
147154
:type enable: bool, optional
148155
:param enable: Set to True to enable BMFF file access.
149156
:rtype: bool
150157
:return: True if libexiv2 has been built with BMFF support.";
151158
%inline %{
152159
static bool enableBMFF(bool enable) {
160+
// deprecated since 2024-08-01
161+
PyErr_WarnEx(PyExc_DeprecationWarning,
162+
"BMFF is already enabled if libexiv2 was built with BMFF support",
163+
1);
153164
#ifdef EXV_ENABLE_BMFF
154-
return Exiv2::enableBMFF(enable);
165+
return true;
155166
#else
156167
return false;
157168
#endif // EXV_ENABLE_BMFF

src/swig-0_27_7/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# python-exiv2 - Python interface to exiv2
22
# http://github.com/jim-easterbrook/python-exiv2
3-
# Copyright (C) 2021-22 Jim Easterbrook [email protected]
3+
# Copyright (C) 2021-24 Jim Easterbrook [email protected]
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,6 @@ def main():
3131
print('python-exiv2 version:', exiv2.__version__)
3232
print('python-exiv2 examples:',
3333
os.path.join(os.path.dirname(__file__), 'examples'))
34-
print('BMFF support:', exiv2.enableBMFF(False))
3534
if args.verbosity:
3635
print('libexiv2 build options:')
3736
pprint.pprint(exiv2.versionInfo())

src/swig-0_27_7/image_wrap.cxx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,8 +4358,12 @@ namespace Exiv2 {
43584358

43594359

43604360
static bool enableBMFF(bool enable) {
4361+
// deprecated since 2024-08-01
4362+
PyErr_WarnEx(PyExc_DeprecationWarning,
4363+
"BMFF is already enabled if libexiv2 was built with BMFF support",
4364+
1);
43614365
#ifdef EXV_ENABLE_BMFF
4362-
return Exiv2::enableBMFF(enable);
4366+
return true;
43634367
#else
43644368
return false;
43654369
#endif // EXV_ENABLE_BMFF
@@ -7047,8 +7051,8 @@ static PyMethodDef SwigMethods[] = {
70477051
{ "enableBMFF", _wrap_enableBMFF, METH_VARARGS, "\n"
70487052
"Enable BMFF support.\n"
70497053
"\n"
7050-
"If libexiv2 has been built with BMFF support included it can be enabled\n"
7051-
"by calling enableBMFF(True).\n"
7054+
"If libexiv2 has been built with BMFF support it is already enabled\n"
7055+
"and this fubction does nothing.\n"
70527056
":type enable: bool, optional\n"
70537057
":param enable: Set to True to enable BMFF file access.\n"
70547058
":rtype: bool\n"
@@ -7062,8 +7066,8 @@ SWIGINTERN PyGetSetDef SwigPyBuiltin__Exiv2__Image_getset[] = {
70627066
{ (char *)"__dict__", SwigPyBuiltin_FunpackGetterClosure, 0, (char *)"\n"
70637067
"Enable BMFF support.\n"
70647068
"\n"
7065-
"If libexiv2 has been built with BMFF support included it can be enabled\n"
7066-
"by calling enableBMFF(True).\n"
7069+
"If libexiv2 has been built with BMFF support it is already enabled\n"
7070+
"and this fubction does nothing.\n"
70677071
":type enable: bool, optional\n"
70687072
":param enable: Set to True to enable BMFF file access.\n"
70697073
":rtype: bool\n"
@@ -8887,6 +8891,11 @@ SWIG_init(void) {
88878891
}
88888892

88898893

8894+
#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
8895+
Exiv2::enableBMFF(true);
8896+
#endif
8897+
8898+
88908899
{
88918900
PyObject* module = PyImport_ImportModule("enum");
88928901
if (!module)

src/swig-0_28_3/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# python-exiv2 - Python interface to exiv2
22
# http://github.com/jim-easterbrook/python-exiv2
3-
# Copyright (C) 2021-22 Jim Easterbrook [email protected]
3+
# Copyright (C) 2021-24 Jim Easterbrook [email protected]
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,6 @@ def main():
3131
print('python-exiv2 version:', exiv2.__version__)
3232
print('python-exiv2 examples:',
3333
os.path.join(os.path.dirname(__file__), 'examples'))
34-
print('BMFF support:', exiv2.enableBMFF(False))
3534
if args.verbosity:
3635
print('libexiv2 build options:')
3736
pprint.pprint(exiv2.versionInfo())

src/swig-0_28_3/image_wrap.cxx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,8 +4358,12 @@ namespace Exiv2 {
43584358

43594359

43604360
static bool enableBMFF(bool enable) {
4361+
// deprecated since 2024-08-01
4362+
PyErr_WarnEx(PyExc_DeprecationWarning,
4363+
"BMFF is already enabled if libexiv2 was built with BMFF support",
4364+
1);
43614365
#ifdef EXV_ENABLE_BMFF
4362-
return Exiv2::enableBMFF(enable);
4366+
return true;
43634367
#else
43644368
return false;
43654369
#endif // EXV_ENABLE_BMFF
@@ -7073,8 +7077,8 @@ static PyMethodDef SwigMethods[] = {
70737077
{ "enableBMFF", _wrap_enableBMFF, METH_VARARGS, "\n"
70747078
"Enable BMFF support.\n"
70757079
"\n"
7076-
"If libexiv2 has been built with BMFF support included it can be enabled\n"
7077-
"by calling enableBMFF(True).\n"
7080+
"If libexiv2 has been built with BMFF support it is already enabled\n"
7081+
"and this fubction does nothing.\n"
70787082
":type enable: bool, optional\n"
70797083
":param enable: Set to True to enable BMFF file access.\n"
70807084
":rtype: bool\n"
@@ -7088,8 +7092,8 @@ SWIGINTERN PyGetSetDef SwigPyBuiltin__Exiv2__Image_getset[] = {
70887092
{ (char *)"__dict__", SwigPyBuiltin_FunpackGetterClosure, 0, (char *)"\n"
70897093
"Enable BMFF support.\n"
70907094
"\n"
7091-
"If libexiv2 has been built with BMFF support included it can be enabled\n"
7092-
"by calling enableBMFF(True).\n"
7095+
"If libexiv2 has been built with BMFF support it is already enabled\n"
7096+
"and this fubction does nothing.\n"
70937097
":type enable: bool, optional\n"
70947098
":param enable: Set to True to enable BMFF file access.\n"
70957099
":rtype: bool\n"
@@ -8904,6 +8908,11 @@ SWIG_init(void) {
89048908
}
89058909

89068910

8911+
#if defined EXV_ENABLE_BMFF && !EXIV2_TEST_VERSION(0, 28, 3)
8912+
Exiv2::enableBMFF(true);
8913+
#endif
8914+
8915+
89078916
{
89088917
PyObject* module = PyImport_ImportModule("enum");
89098918
if (!module)

tests/test_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def check_result(self, result, expected_type, expected_value):
3939
self.assertEqual(result, expected_value)
4040

4141
def test_BMFF(self):
42-
self.assertEqual(exiv2.enableBMFF(True),
43-
exiv2.versionInfo()['EXV_ENABLE_BMFF'])
42+
with self.assertWarns(DeprecationWarning):
43+
enabled = exiv2.enableBMFF(True)
44+
self.assertEqual(enabled, exiv2.versionInfo()['EXV_ENABLE_BMFF'])
4445
with open(self.bmff_path, 'rb') as f:
4546
image_data = f.read()
4647
if not exiv2.versionInfo()['EXV_ENABLE_BMFF']:

0 commit comments

Comments
 (0)