From 9ed34bf504a637724282b9d355b48aef8e89f106 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 9 May 2020 13:30:03 -0500 Subject: [PATCH] Updated Structure of the code (markdown) --- Structure-of-the-code.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Structure-of-the-code.md b/Structure-of-the-code.md index 623b386..76df82a 100644 --- a/Structure-of-the-code.md +++ b/Structure-of-the-code.md @@ -25,6 +25,13 @@ The package code is organized in osxphotos per the table below. Most of the file |`template.py`| constants used by the PhotoInfo.render_template() method| |`templates`| contains [mako](https://www.makotemplates.org/) templates| |`templates/xmp_sidecar.mako`|mako template used to create [XMP](https://en.wikipedia.org/wiki/Extensible_Metadata_Platform) sidecar files| -|`utils.py`|. various utility methods--this file is getting bloated and needs to be refactored| +|`utils.py`| various utility methods--this file is getting bloated and needs to be refactored| +Broadly, osxphotos works like this: +1. Opens a readonly copy of `photos.db`. If the file is locked, a temporary copy will be created then opened. +2. Reads `photos.db` to determine which version of Photos created the library (`PhotosDB._get_db_version()`) +3. If library created with Photos version 2, 3, or 4, `PhotosDB._process_database4()` processes the database file to extract all required information. +4. If library created with Photos 5, the actual database is `Photos.sqlite` so this is opened readonly or copied to a temporary file if locked, then `PhotosDB._process_database5()` is called to process the database file and extra all required information. +5. `_process_database4` and `_process_database5` execute several SQL queries to extract the required data. These methods populate a series of data structures in `PhotosDB` which are then used by the rest of code to create the `PhotoInfo`, `AlbumInfo`, and `FolderInfo` objects. These database structures are ugly...in general, they flatten the SQL database into several different python dicts. The "master" dict is called `_dbphotos`. The key is the [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) of the photo and the value is another dict containing details about the photo. Read the code for `PhotosDB.__init__()` for additional details. Each of the data structures is documented in the code. +