Skip to content
Snippets Groups Projects
Commit b590fed2 authored by Manuel Günther's avatar Manuel Günther
Browse files

Improved FileSet object

parent 87811a90
Branches
Tags
No related merge requests found
...@@ -40,36 +40,30 @@ class FileSet: ...@@ -40,36 +40,30 @@ class FileSet:
Use this class, whenever the database provides several files that belong to the same probe. Use this class, whenever the database provides several files that belong to the same probe.
Each file set has an id, an associated client (aka. identity, person, user), and a list of associated files. Each file set has an id, and a list of associated files, which are of type :py:class:`File` of the same client.
Usually, these files are part of a database, which has a common directory for all files. The file set id can be anything hashable, but needs to be unique all over the database.
The paths of this file set are usually *relative* to that common directory, and they are usually stored *without* filename extension.
The file id can be anything hashable, but needs to be unique all over the database.
The client id can be anything hashable, but needs to be identical for different files of the same client, and different between clients.
**Parameters:** **Parameters:**
file_id : str or int file_set_id : str or int
A unique ID that identifies the file. A unique ID that identifies the file set.
This ID might be identical to the ``path``, though integral IDs perform faster.
client_id : str or int
A unique ID that identifies the client (user) to which this file belongs.
This ID might be the name of the person, though integral IDs perform faster.
path : str files : [:py:class:`File`]
The file path of the file, which is relative to the common database directory, and without filename extension. A list of File objects that should be stored inside this file.
All files of that list need to have the same client ID.
""" """
def __init__(self, file_set_id, client_id, file_set_name): def __init__(self, file_set_id, files, path=None):
# The **unique** id of the file set # The **unique** id of the file set
self.id = file_set_id self.id = file_set_id
# The id of the client that is attached to the file # The id of the client that is attached to the file
self.client_id = client_id assert len(files)
# A name of the file set self.client_id = files[0].client_id
self.path = file_set_name assert all(f.client_id == self.client_id for f in files)
# The list of files contained in this set # The list of files contained in this set
self.files = [] self.files = files
def __lt__(self, other): def __lt__(self, other):
"""Defines an order between file sets by using the order of the file set ids."""
# compare two File set objects by comparing their IDs # compare two File set objects by comparing their IDs
return self.id < other.id return self.id < other.id
import bob.db.atnt import bob.db.atnt
import os import os
from bob.bio.base.database import DatabaseBob, DatabaseBobZT, FileSet from bob.bio.base.database import DatabaseBob, DatabaseBobZT, File, FileSet
from bob.bio.base.test.utils import atnt_database_directory from bob.bio.base.test.utils import atnt_database_directory
class FileSetDatabase (DatabaseBobZT): class FileSetDatabase (DatabaseBobZT):
...@@ -28,9 +28,10 @@ class FileSetDatabase (DatabaseBobZT): ...@@ -28,9 +28,10 @@ class FileSetDatabase (DatabaseBobZT):
# arrange files by clients # arrange files by clients
file_sets = [] file_sets = []
for client_files in files: for client_files in files:
# convert into our File objects (so that they are tested as well)
our_files = [File(f.id, f.client_id, f.path) for f in client_files]
# generate file set for each client # generate file set for each client
file_set = FileSet(client_files[0].client_id, client_files[0].client_id, client_files[0].path) file_set = FileSet(our_files[0].client_id, our_files)
file_set.files = client_files
file_sets.append(file_set) file_sets.append(file_set)
return file_sets return file_sets
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment