fietsboek.data module¶
Data manager for fietsboek.
Data are objects that belong to a track (such as images), but are not stored in the database itself. This module makes access to such data objects easier.
- class fietsboek.data.DataManager(data_dir)¶
Bases:
object
Data manager.
The data manager is usually provided as
request.data_manager
and can be used to access track’s images and other on-disk data.- Variables:
data_dir – Path to the data folder.
- initialize(track_id)¶
Creates the data directory for a track.
- Raises:
FileExistsError – If the directory already exists.
- Parameters:
track_id (
int
) – ID of the track.- Return type:
- Returns:
The manager that can be used to manage this track’s data.
- initialize_user(user_id)¶
Creates the data directory for a user.
- Raises:
FileExistsError – If the directory already exists.
- Parameters:
user_id (
int
) – ID of the user.- Return type:
- Returns:
The manager that can be used to manage this user’s data.
- maintenance_mode()¶
Checks whether the maintenance mode is enabled.
If maintenance mode is enabled, returns the reason given.
If maintenance mode is disabled, returns
None
.
- open(track_id)¶
Opens a track’s data directory.
- Raises:
FileNotFoundError – If the track directory does not exist.
- Parameters:
track_id (
int
) – ID of the track.- Return type:
- Returns:
The manager that can be used to manage this track’s data.
- open_user(user_id)¶
Opens a user’s data directory.
- Raises:
FileNotFoundError – If the user directory does not exist.
- Parameters:
user_id (
int
) – ID of the user.- Return type:
- Returns:
The manager that can be used to manage this user’s data.
- purge(track_id)¶
Forcefully purges all data from the given track.
This function logs errors but raises no exception, as such it can always be used to clean up after a track.
- class fietsboek.data.TrackDataDir(track_id, path, *, journal=False, is_fresh=False)¶
Bases:
object
Manager for a single track’s data.
If initialized with
journal = True
, then you can userollback()
to roll back the changes in case of an error. In case of no error, usecommit()
to commit the changes. If you don’t want the “journalling” semantics, usejournal = False
.- add_image(image, filename=None)¶
Saves an image to a track.
- backup()¶
Create a backup of the GPX file.
- backup_path()¶
Path of the GPX backup file.
- Return type:
Path
- Returns:
The path of the backup file.
- commit()¶
Commits all changed and deletes the journal.
Note that this function will do nothing if the journal is disabled, meaning it can always be called.
- compress_gpx(data, quality=4)¶
Set the GPX content to the compressed form of data.
If you want to write compressed data directly, use
gpx_path()
to get the path of the GPX file.
- decompress_gpx()¶
Returns the GPX bytes decompressed.
- Return type:
- Returns:
The saved GPX file, decompressed.
- delete_image(image_id)¶
Deletes an image from a track.
- Raises:
FileNotFoundError – If the given image could not be found.
- Parameters:
image_id (
str
) – ID of the image.
- engrave_metadata(title, description, author_name, time, *, gpx=None)¶
Engrave the given metadata into the GPX file.
Note that this will overwrite all existing metadata in the given fields.
If
None
is given, it will erase that specific part of the metadata.
- gpx_path()¶
Returns the path of the GPX file.
This file contains the (brotli) compressed GPX data.
- Return type:
Path
- Returns:
The path where the GPX is supposed to be.
- image_path(image_id)¶
Returns a path to a saved image.
- Raises:
FileNotFoundError – If the given image could not be found.
- Parameters:
image_id (
str
) – ID of the image.- Return type:
Path
- Returns:
A path pointing to the requested image.
- images()¶
Returns a list of images that belong to the track.
- lock()¶
Returns a FileLock that can be used to lock access to the track’s data.
- Return type:
UnixFileLock
- Returns:
The lock responsible for locking this data directory.
- purge()¶
Purge all data pertaining to the track.
This function logs errors but raises no exception, as such it can always be used to clean up after a track.
- rollback()¶
Rolls back the journal, e.g. in case of error.
- Raises:
ValueError – If the data directory was opened without the journal, this raises
ValueError
.
- class fietsboek.data.UserDataDir(user_id, path)¶
Bases:
object
Manager for a single user’s data.
- heatmap_path()¶
Returns the path for the heatmap tile file.
- Return type:
Path
- Returns:
The path of the heatmap SQLite databse.
- tilehunt_path()¶
Returns the path for the tilehunt tile file.
- Return type:
Path
- Returns:
The path of the tilehunt SQLite database.