4.3.2. PictureManager package

4.3.2.1. Submodules

4.3.2.2. PictureManager.exiftool module

PyExifTool is a Python library to communicate with an instance of Phil Harvey’s excellent ExifTool command-line application. The library provides the class ExifTool that runs the command-line tool in batch mode and features methods to send commands to that program, including methods to extract meta-information from one or more image files. Since exiftool is run in batch mode, only a single instance needs to be launched and can be reused for many queries. This is much more efficient than launching a separate process for every single query.

The source code can be checked out from the github repository with

git clone git://github.com/smarnach/pyexiftool.git

Alternatively, you can download a tarball. There haven’t been any releases yet.

PyExifTool is licenced under GNU GPL version 3 or later.

Example usage:

import exiftool

files = ["a.jpg", "b.png", "c.tif"]
with exiftool.ExifTool() as et:
    metadata = et.get_metadata_batch(files)
for d in metadata:
    print("{:20.20} {:20.20}".format(d["SourceFile"],
                                     d["EXIF:DateTimeOriginal"]))
class PictureManager.exiftool.ExifTool(executable_=None)[source]

Bases: object

Run the exiftool command-line tool and communicate to it.

You can pass the file name of the exiftool executable as an argument to the constructor. The default value exiftool will only work if the executable is in your PATH.

Most methods of this class are only available after calling start(), which will actually launch the subprocess. To avoid leaving the subprocess running, make sure to call terminate() method when finished using the instance. This method will also be implicitly called when the instance is garbage collected, but there are circumstance when this won’t ever happen, so you should not rely on the implicit process termination. Subprocesses won’t be automatically terminated if the parent process exits, so a leaked subprocess will stay around until manually killed.

A convenient way to make sure that the subprocess is terminated is to use the ExifTool instance as a context manager:

with ExifTool() as et:
    ...

Warning

Note that there is no error handling. Nonsensical options will be silently ignored by exiftool, so there’s not much that can be done in that regard. You should avoid passing non-existent files to any of the methods, since this will lead to undefied behaviour.

running

A Boolean value indicating whether this instance is currently associated with a running subprocess.

execute(*params)[source]

Execute the given batch of parameters with exiftool.

This method accepts any number of parameters and sends them to the attached exiftool process. The process must be running, otherwise ValueError is raised. The final -execute necessary to actually run the batch is appended automatically; see the documentation of start() for the common options. The exiftool output is read up to the end-of-output sentinel and returned as a raw bytes object, excluding the sentinel.

The parameters must also be raw bytes, in whatever encoding exiftool accepts. For filenames, this should be the system’s filesystem encoding.

Note

This is considered a low-level method, and should rarely be needed by application developers.

execute_json(*params)[source]

Execute the given batch of parameters and parse the JSON output.

This method is similar to execute(). It automatically adds the parameter -j to request JSON output from exiftool and parses the output. The return value is a list of dictionaries, mapping tag names to the corresponding values. All keys are Unicode strings with the tag names including the ExifTool group name in the format <group>:<tag>. The values can have multiple types. All strings occurring as values will be Unicode strings. Each dictionary contains the name of the file it corresponds to in the key "SourceFile".

The parameters to this function must be either raw strings (type str in Python 2.x, type bytes in Python 3.x) or Unicode strings (type unicode in Python 2.x, type str in Python 3.x). Unicode strings will be encoded using system’s filesystem encoding. This behaviour means you can pass in filenames according to the convention of the respective Python version – as raw strings in Python 2.x and as Unicode strings in Python 3.x.

get_metadata(filename)[source]

Return meta-data for a single file.

The returned dictionary has the format described in the documentation of execute_json().

get_metadata_batch(filenames)[source]

Return all meta-data for the given files.

The return value will have the format described in the documentation of execute_json().

get_tag(tag, filename)[source]

Extract a single tag from a single file.

The return value is the value of the specified tag, or None if this tag was not found in the file.

get_tag_batch(tag, filenames)[source]

Extract a single tag from the given files.

The first argument is a single tag name, as usual in the format <group>:<tag>.

The second argument is an iterable of file names.

The return value is a list of tag values or None for non-existent tags, in the same order as filenames.

get_tags(tags, filename)[source]

Return only specified tags for a single file.

The returned dictionary has the format described in the documentation of execute_json().

get_tags_batch(tags, filenames)[source]

Return only specified tags for the given files.

The first argument is an iterable of tags. The tag names may include group names, as usual in the format <group>:<tag>.

The second argument is an iterable of file names.

The format of the return value is the same as for execute_json().

start()[source]

Start an exiftool process in batch mode for this instance.

This method will issue a UserWarning if the subprocess is already running. The process is started with the -G and -n as common arguments, which are automatically included in every command you run with execute().

terminate()[source]

Terminate the exiftool process of this instance.

If the subprocess isn’t running, this method will do nothing.

PictureManager.exiftool.executable = 'exiftool'

The name of the executable to run.

If the executable is not located in one of the paths listed in the PATH environment variable, the full path should be given here.

PictureManager.exiftool.fsencode(filename)

Encode filename to the filesystem encoding with ‘surrogateescape’ error handler, return bytes unchanged. On Windows, use ‘strict’ error handler if the file system encoding is ‘mbcs’ (which is the default encoding).

4.3.2.3. PictureManager.pictureManager module

class PictureManager.pictureManager.MetaPictureModel[source]

Bases: PyQt5.QtCore.pyqtWrapperType, Savable.Savable

class PictureManager.pictureManager.Picture(resourcesPath, path, latitude, longitude, date=None, status=0)[source]

Bases: object

A container used to store all data about a particular picture. It reflects an xml structure and is used to manipulate photos as dataModel along the use of the application

circleColor
icon
serialize()[source]

Serialize a Picture object.

class PictureManager.pictureManager.PictureManager[source]

Bases: PyQt5.QtCore.QSortFilterProxyModel

computeCenter()[source]

Compute the coordinates of the center associated to all pictures

Returns:The coordinates, latitude then longitude
Return type:list<float>
count()[source]

An alias to be used in QML as a property. We can”t use the rowCount method as it should remain available inside the class.

Returns:The number of element in the model
Return type:int
deleteAll(rows)[source]

Remove pictures from the model

Parameters:rows (list<QModelIndex>) – The related rows in the proxy model
discardAll(rows)[source]

Change the status of pictures to DISCARDED or THUMBNAIL_DISCARDED

Parameters:rows (list<QModelIndex>) – The related rows in the proxy model
getName(index)[source]
move(initRow, finalRow)[source]

Move a row from an index to another. Exactly, put initRow after finalRow if moving up to down, and before finalRow if moving down to up

Parameters:
  • initRow (QModelIndex) – The starting index
  • finalRow (QModelIndex) – The final index
renewAll(rows)[source]

Change the status of pictures DISCARDED, THUMBNAIL_DISCARDED or REJECTED to NEW

Parameters:rows (list<QModelIndex>) – The related rows in the proxy model
class PictureManager.pictureManager.PictureModel(resourcesPath, listPictures=[], parent=None)[source]

Bases: PyQt5.QtCore.QAbstractListModel

Represent and handle a list of pictures as a ListModel. Directly implements QAbstractListModel.

PATH_ROLE

int

Role that handle the picture’s path name of an item

NAME_ROLE

int

Role that handle the picture’s name of an item

DATE_ROLE

int

Role that handle the picture’s date of creation

STATUS_ROLE

int

Role that handle the picture’s status of an item

ICON_ROLE

int

Role that handle the picture’s icon of an item

ITEM_ROLE

int

Role related to the whole item / picture

LATITUDE_ROLE

int

Role related to the latitude of an item

LONGITUDE_ROLE

int

Roled related to the longitude of an item

COLOR_ROLE

int

Role that handle the color of an item on the map

COLOR_ROLE = 264
DATE_ROLE = 259
ICON_ROLE = 261
ITEM_ROLE = 306
LATITUDE_ROLE = 262
LONGITUDE_ROLE = 263
NAME_ROLE = 258
PATH_ROLE = 257
STATUS_ROLE = 260
add(picture, index=None)[source]

Add a picture to the model

picture – The picture to add index – The index where the picture should be inserted. If None, the picture will be appended at the end.

data(index, role=258)[source]

Retrieve a piece of information from an item (a picture) of the model

Parameters:
  • index (int) – The index of the element
  • role (int) – The role of the element we are interested in
Returns:

The requested element or data related to this element.

Return type:

QVariant

static deserialize(serial)[source]

Recreate a pictureModel object from its serialization.

Parameters:serial (dict()) – The serialized version of a pictureModel object.
insertRow(row, parent=<PyQt5.QtCore.QModelIndex object>)[source]

An implementation of the parent method insertRow. It add an empty row at the given index See Qt Documentation for more details <3.

Parameters:
  • row (int) – The index of tization between pictures. If more than one index are supplied, the first he future row. If superior to model size, the row will be appended.
  • parent (QModelIndex) – The parent index, always default in our case.
Returns:

Return True if the row have been successfully inserted.

Return type:

bool

instantiateManager()[source]

Create an instance of this model manager. The manager add an indirection that allow, for instance, filtering.

Returns:The picture manager corresponding to that model
Return type:PictureManager
classmethod load(base_path, file_name, object_class=None)[source]

Recreate a pictureModel object from a file.

Parameters:
  • base_path (str) – The path of the directory containing the file.
  • file_name (str) – The name of the file to load.
  • object_class (class) – The class of the object to recreate.
populate(picturesFiles, status=0)[source]

Populate the model, i.e. add instance of pictures element. Element are added with the status “NEW”

Parameters:
  • picturesFiles (list<str>) – List of path to the different pictures
  • status (int) – The initial status to assign to the item
printData()[source]
removeDiscardedThumbnails()[source]
removeRow(row, parent=<PyQt5.QtCore.QModelIndex object>)[source]

Remove a picture from the model

row – The picture”s index

removeRows(row, count, parent=<PyQt5.QtCore.QModelIndex object>)[source]

Remove contiguous pictures from the model

Parameters:
  • row (int) – The first picture’s index
  • count (int) – Number of picture to remove
  • parent (QModelIndex) – The parent row
roleNames()[source]

An accessor to roles names

rowCount(parent=<PyQt5.QtCore.QModelIndex object>)[source]

Return the number of element within that model

save(base_path, file_name)[source]

Save the object in the file system.

serialize()[source]

Serialize a pictureModel object.

setData(index, value, role)[source]

Set a particular value in the data model using his role.

index – The index of the related element value – The new value role – The related role

thumbnails()[source]
validFiles()[source]

Retrieve all files that may be used for the reconstruction; i.e. with status : NEW or PROCESSED

Returns:The list of all valid pictures in that model
Return type:list<Picture>
class PictureManager.pictureManager.PictureState[source]

Bases: object

An Enumeration to handle all different state in which a picture may be

DISCARDED = 6
NEW = 0
PROCESSED = 3
RECONSTRUCTION = 1
REJECTED = 2
THUMBNAIL = 4
THUMBNAIL_DISCARDED = 5

4.3.2.4. Module contents