def initialise(cls, config_store, verbosity): if not GExiv2.initialize(): raise RuntimeError('Failed to initialise GExiv2') GExiv2.log_set_level( max(GExiv2.LogLevel.DEBUG, min(GExiv2.LogLevel.ERROR, 4 - verbosity))) GExiv2.log_use_glib_logging() # Recent versions of Exiv2 have these namespaces defined, but # older versions may not recognise them. The xapGImg URL is # invalid, but Photini doesn't write xapGImg so it doesn't # matter. for prefix, name in (('exifEX', 'http://cipa.jp/exif/1.0/'), ('xapGImg', 'http://ns.adobe.com/xxx/'), ('xmpGImg', 'http://ns.adobe.com/xap/1.0/g/img/'), ('xmpRights', 'http://ns.adobe.com/xap/1.0/rights/')): GExiv2.Metadata.register_xmp_namespace(name, prefix) # Gexiv2 won't register the 'Iptc4xmpExt' namespace as its # abbreviated version 'iptcExt' is already defined. This kludge # registers it by reading some data with the full namespace data = XMP_WRAPPER.format( 'xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/"') # open the data to register the namespace GExiv2.Metadata().open_buf(data.encode('utf-8')) # make list of possible character encodings cls.encodings = ['utf-8', 'iso8859-1', 'ascii'] char_set = locale.getdefaultlocale()[1] if char_set: try: name = codecs.lookup(char_set).name if name not in cls.encodings: cls.encodings.append(name) except LookupError: pass
# import required libraries from gi.repository import GExiv2, GLib, GObject # import optional library try: from gi.repository import Gspell except ImportError: Gspell = None logger = logging.getLogger(__name__) # initialise GObject stuff GLib.set_prgname('Photini') if not GExiv2.initialize(): raise RuntimeError('Failed to initialise GExiv2') GExiv2.log_use_glib_logging() if GLib.glib_version >= (2, 46): # the numeric values of GLib.LogLevelFlags suggest ERROR is more # severe than CRITICAL, Python's logging has them the other way # round _log_mapping = { GLib.LogLevelFlags.LEVEL_DEBUG: logging.DEBUG, GLib.LogLevelFlags.LEVEL_INFO: logging.INFO, GLib.LogLevelFlags.LEVEL_MESSAGE: logging.INFO, GLib.LogLevelFlags.LEVEL_WARNING: logging.WARNING, GLib.LogLevelFlags.LEVEL_CRITICAL: logging.ERROR, GLib.LogLevelFlags.LEVEL_ERROR: logging.CRITICAL, } def _gi_log_callback(log_domain, log_level, message, data):