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 valueexiftool
will only work if the executable is in yourPATH
.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 callterminate()
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, otherwiseValueError
is raised. The final-execute
necessary to actually run the batch is appended automatically; see the documentation ofstart()
for the common options. Theexiftool
output is read up to the end-of-output sentinel and returned as a rawbytes
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 fromexiftool
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, typebytes
in Python 3.x) or Unicode strings (typeunicode
in Python 2.x, typestr
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 asfilenames
.
Return only specified tags for a single file.
The returned dictionary has the format described in the documentation of
execute_json()
.
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()
.
-
-
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
¶
-
-
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
-
-
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
-
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
-
rowCount
(parent=<PyQt5.QtCore.QModelIndex object>)[source]¶ Return the number of element within that model
-