db
plantdb.commons.db Link
API for the database module in the ROMI project.
The following classes are defined:
- A database
DB
contains a list of scansScan
distinguishable by their id. - A
Scan
can be made of several list of filesFileset
. - A
Fileset
is made of a list of filesFiles
. - A
File
can be an image, text of bytes.
It should be subclassed to implement an actual database interface.
DB Link
DB()
Bases: object
Class defining the database object DB
.
Abstract class defining the API used to communicate with a database in the ROMI project.
Source code in plantdb/commons/db.py
47 48 |
|
connect Link
connect(login_data=None)
Connect to the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
login_data
|
list or dict
|
Use this to access to a |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
create_scan Link
create_scan(id)
Create a new scan object in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the scan to retrieve |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
delete_scan Link
delete_scan(id)
Delete a scan from the DB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the scan to delete |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
disconnect Link
disconnect()
Disconnect from the database.
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
64 65 66 67 68 69 70 71 |
|
get_scan Link
get_scan(id, create=False)
Get a scan saved in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the scan instance to retrieve. |
required |
create
|
bool
|
Create the scan if it does not exist, default to |
False
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
get_scans Link
get_scans()
Get the list of scans saved in the database.
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
73 74 75 76 77 78 79 80 |
|
DBBusyError Link
DBBusyError(message)
Bases: OSError
Raises an error if the database is busy.
This error is raised when the database is busy and an operation cannot be done on it.
Source code in plantdb/commons/db.py
608 609 |
|
File Link
File(fileset, id, **kwargs)
Bases: object
Class defining a file File
contained in a Fileset
.
Abstract class defining the API used to represent a file in the ROMI project.
Attributes:
Name | Type | Description |
---|---|---|
db |
DB
|
Database instance where to find the scan, fileset and file. |
scan |
Scan
|
Scan instance containing the fileset and file. |
fileset |
Fileset
|
Fileset instance containing the file. |
id |
str
|
Id of the file instance. |
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fileset
|
Fileset
|
Instance containing the file. |
required |
id
|
str
|
Id of the file instance. |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
ext |
str
|
The extension of the file. |
Source code in plantdb/commons/db.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
get_db Link
get_db()
Get parent database instance.
Returns:
Type | Description |
---|---|
DB
|
The parent database instance. |
Source code in plantdb/commons/db.py
466 467 468 469 470 471 472 473 474 |
|
get_fileset Link
get_fileset()
Get parent fileset.
Returns:
Type | Description |
---|---|
Fileset
|
The parent fileset instance. |
Source code in plantdb/commons/db.py
486 487 488 489 490 491 492 493 494 |
|
get_id Link
get_id()
Get file id.
Returns:
Type | Description |
---|---|
str
|
The id of the file instance. |
Source code in plantdb/commons/db.py
456 457 458 459 460 461 462 463 464 |
|
get_metadata Link
get_metadata(key=None, default=None)
Get metadata associated to scan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Metadata key to retrieve (defaults to |
None
|
default
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
get_scan Link
get_scan()
Get parent scan instance.
Returns:
Type | Description |
---|---|
Scan
|
The parent scan instance. |
Source code in plantdb/commons/db.py
476 477 478 479 480 481 482 483 484 |
|
import_file Link
import_file(path)
Import an existing file to the File
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path of the file to import |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
read Link
read()
Reads from a file.
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
592 593 594 595 596 597 598 599 |
|
read_raw Link
read_raw()
Reads bytes from a file.
Returns:
Type | Description |
---|---|
bytearray
|
File buffer |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
set_metadata Link
set_metadata(data, value=None)
Get metadata associated to scan.
If value is None
, scan metadata is set to data.
If value is not None
data is a key and is set to value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str or dict
|
Key or value to set as metadata |
required |
value
|
any
|
Value to set (default is |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
write Link
write(str, ext='')
Writes to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str
|
Data to write |
required |
ext
|
str
|
File extension to use |
''
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|
write_raw Link
write_raw(buffer, ext='')
Writes bytes to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer
|
bytearray
|
Data to write |
required |
ext
|
str
|
File extension to use |
''
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
|
Fileset Link
Fileset(scan, id)
Bases: object
Class defining a set of files Fileset
contained in a Scan
.
Abstract class defining the API used to represent a set of files in the ROMI project.
Notes
Files can be 2D images, RGB pictures, text,...
Attributes:
Name | Type | Description |
---|---|---|
db |
DB
|
Database instance where to find the scan and fileset. |
scan |
Scan
|
Scan instance containing the fileset. |
id |
int
|
Id of the fileset instance. |
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan
|
Scan
|
Scan instance containing the fileset. |
required |
id
|
str
|
Id of the fileset instance. |
required |
Source code in plantdb/commons/db.py
283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
create_file Link
create_file(id)
Create a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the new file. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
delete_file Link
delete_file(file_id)
Delete a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the file to delete. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
get_db Link
get_db()
Get parent database instance.
Returns:
Type | Description |
---|---|
DB
|
The parent database instance. |
Source code in plantdb/commons/db.py
307 308 309 310 311 312 313 314 315 |
|
get_file Link
get_file(id, create=False)
Get file with given id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
File instance id. |
required |
create
|
bool
|
Create the file if it does not exist, default to |
False
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
get_files Link
get_files()
Get all files.
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
327 328 329 330 331 332 333 334 |
|
get_id Link
get_id()
Get the fileset instance id.
Returns:
Type | Description |
---|---|
str
|
The id of the fileset instance. |
Source code in plantdb/commons/db.py
297 298 299 300 301 302 303 304 305 |
|
get_metadata Link
get_metadata(key=None, default=None)
Get metadata associated to scan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Metadata key to retrieve, default to |
None
|
default
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
get_scan Link
get_scan()
Get parent scan instance.
Returns:
Type | Description |
---|---|
Scan
|
The parent scan instance. |
Source code in plantdb/commons/db.py
317 318 319 320 321 322 323 324 325 |
|
set_metadata Link
set_metadata(data, value=None)
Get metadata associated to scan.
If value is None
, scan metadata is set to data.
If value is not None
data is a key and is set to value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str or dict
|
Key or value to set as metadata. |
required |
value
|
any
|
Value to set, default to |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
Scan Link
Scan(db, id)
Bases: object
Class defining the scan object Scan
.
Abstract class defining the API used to represent a scan in the ROMI project.
Attributes:
Name | Type | Description |
---|---|---|
db |
DB
|
Database instance where to find the scan. |
id |
int
|
Id of the scan instance. |
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db
|
DB
|
Database instance where to find the scan. |
required |
id
|
str
|
Id of the scan instance. |
required |
Source code in plantdb/commons/db.py
140 141 142 143 144 145 146 147 148 149 150 151 |
|
create_fileset Link
create_fileset(id)
Create a fileset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the new fileset. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
delete_fileset Link
delete_fileset(fileset_id)
Delete a fileset from the DB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the fileset to delete. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
get_db Link
get_db()
Get parent database instance.
Returns:
Type | Description |
---|---|
DB
|
Database instance where to find the scan. |
Source code in plantdb/commons/db.py
163 164 165 166 167 168 169 170 171 |
|
get_fileset Link
get_fileset(id, create=False)
Get a fileset with a given id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Id of the fileset to be retrieved. |
required |
create
|
bool
|
Create the fileset if it does not exist, default to |
False
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
get_filesets Link
get_filesets()
Get all sets of files.
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
173 174 175 176 177 178 179 180 |
|
get_id Link
get_id()
Get the scan instance id.
Returns:
Type | Description |
---|---|
str
|
Id of the scan instance. |
Source code in plantdb/commons/db.py
153 154 155 156 157 158 159 160 161 |
|
get_metadata Link
get_metadata(key=None, default=None)
Get metadata associated to scan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Metadata key to retrieve, default to |
None
|
default
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
set_metadata Link
set_metadata(data, value=None)
Get metadata associated to scan.
If value is None
, scan metadata is set to data.
If value is not None
data is a key and is set to value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str or dict
|
Key or value. |
required |
value
|
any
|
Value to set, default to |
None
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|