sshfsdb
plantdb.commons.sshfsdb Link
This module implement a database as a file structure on a remote server using SSHFS.
SSHFSDB Link
SSHFSDB(basedir, remotedir=None)
Bases: FSDB
Subclass of FSDB that first mounts a remote directory using SSHFS.
Implementation of a database on a remote file system.
Attributes:
Name | Type | Description |
---|---|---|
basedir |
str
|
Path to the local directory where to mount the remote directory. |
remotedir |
(str, optional)
|
Path to the remote directory containing the database.
Should be in the format |
scans |
list
|
The list of |
is_connected |
bool
|
|
Database constructor.
Mount remotedir
directory on the basedir
directory and load accessible Scan
objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
basedir
|
str
|
Path to local directory of the database |
required |
remotedir
|
str
|
Path to the remote directory containing the database.
Should be in the format |
None
|
Examples:
>>> # EXAMPLE 1: Use a temporary dummy database:
>>> from plantdb.commons.sshfsdb import SSHFSDB
>>> db = SSHFSDB("db", "someone@example.com:/data")
>>> print(db.basedir)
db
>>> print(db.remotedir)
someone@example.com:/data
>>> # Now connecting to this remote DB...
>>> db.connect()
>>> # ...allows to create new `Scan` in it:
>>> new_scan = db.create_scan("007")
>>> print(type(new_scan))
<class 'plantdb.commons.fsdb.Scan'>
>>> db.disconnect()
Source code in plantdb/commons/sshfsdb.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
connect Link
connect(login=None, unsafe=False)
Connect to the remote database.
Handle DB "locking" system by adding a LOCK_FILE_NAME
file in the DB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
login
|
bool
|
UNUSED |
None
|
Examples:
>>> from plantdb.commons.sshfsdb import SSHFSDB
>>> db = SSHFSDB("db", "someone@example.com:/data")
>>> print(db.is_connected)
False
>>> db.connect()
>>> print(db.is_connected)
True
Source code in plantdb/commons/sshfsdb.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
create_scan Link
create_scan(scan_id, metadata=None)
Create a new Scan
instance in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The identifier of the scan to create. It should contain only alphanumeric characters, underscores, dashes and dots. It should be non-empty and not longer than 255 characters It should not exist in the local database |
required |
metadata
|
dict
|
A dictionary of metadata to append to the new |
None
|
Returns:
Type | Description |
---|---|
Scan
|
The |
Raises:
Type | Description |
---|---|
OSError
|
If the |
See Also
plantdb.commons.fsdb._is_valid_id plantdb.commons.fsdb._make_scan
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db()
>>> new_scan = db.create_scan('007', metadata={'project': 'GoldenEye'}) # create a new scan dataset
>>> print(new_scan.get_metadata('owner')) # default user 'anonymous' for dummy database
anonymous
>>> print(new_scan.get_metadata('project'))
GoldenEye
>>> scan = db.create_scan('007') # attempt to create an existing scan dataset
OSError: Given scan identifier '007' already exists!
>>> scan = db.create_scan('0/07') # attempt to create a scan dataset using invalid characters
OSError: Invalid scan identifier '0/07'!
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
|
create_user Link
create_user(username, fullname, password)
Create a new user and store the user information in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username
|
str
|
The username of the user to be created. This will be converted to lowercase. |
required |
fullname
|
str
|
The full name of the user to be created. |
required |
password
|
str
|
The password of the user to be created. |
required |
Examples:
>>> from plantdb.commons.fsdb import FSDB
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db()
>>> db.create_user('batman', "Bruce Wayne", "joker")
>>> db.connect('batman', 'joker')
>>> print(db.user)
batman
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
delete_scan Link
delete_scan(scan_id)
Delete an existing Scan
from the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan to delete from the local database. |
required |
Raises:
Type | Description |
---|---|
IOError
|
If the |
See Also
plantdb.commons.fsdb._delete_scan
Examples:
>>> from plantdb.commons.fsdb import FSDB
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db()
>>> new_scan = db.create_scan('007')
>>> print(new_scan)
<plantdb.commons.fsdb.Scan object at 0x7f0730b1e390>
>>> db.delete_scan('007')
>>> scan = db.get_scan('007')
>>> print(scan)
None
>>> db.delete_scan('008')
OSError: Invalid id
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
|
disconnect Link
disconnect()
Disconnect from the database.
Handle DB "locking" system by removing the LOCK_FILE_NAME
file from the DB.
Examples:
>>> from plantdb.commons.sshfsdb import SSHFSDB
>>> db = SSHFSDB("db", "someone@example.com:/data")
>>> print(db.is_connected)
False
>>> db.connect()
>>> print(db.is_connected)
True
>>> db.disconnect()
>>> print(db.is_connected)
False
Source code in plantdb/commons/sshfsdb.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
get_scan Link
get_scan(scan_id, create=False)
Get or create a Scan
instance in the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The name of the scan dataset to get/create.
It should exist if |
required |
create
|
bool
|
If |
False
|
Raises:
Type | Description |
---|---|
ScanNotFoundError
|
If the |
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db()
>>> db.list_scans()
[]
>>> new_scan = db.get_scan('007', create=True)
>>> print(new_scan)
<plantdb.commons.fsdb.Scan object at **************>
>>> db.list_scans()
['007']
>>> unknown_scan = db.get_scan('unknown')
plantdb.commons.fsdb.ScanNotFoundError: Unknown scan id 'unknown'!
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
|
get_scans Link
get_scans(query=None, fuzzy=False, owner_only=True)
Get the list of Scan
instances defined in the local database, possibly filtered using a query
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
dict
|
A query to use to filter the returned list of scans.
The metadata must match given |
None
|
fuzzy
|
bool
|
Whether to use fuzzy matching or not, that is the use of regular expressions. |
False
|
owner_only
|
bool
|
Whether to filter the returned list of scans to only include scans owned by the current user.
Default is |
True
|
Returns:
Type | Description |
---|---|
list of plantdb.commons.fsdb.Scan
|
List of |
See Also
plantdb.commons.fsdb._filter_query
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db(with_file=True)
>>> db.get_scans()
[<plantdb.commons.fsdb.Scan at *x************>]
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
|
list_scans Link
list_scans(query=None, fuzzy=False, owner_only=True)
Get the list of scans in identifiers the local database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
dict
|
A query to use to filter the returned list of scans.
The metadata must match given |
None
|
fuzzy
|
bool
|
Whether to use fuzzy matching or not, that is the use of regular expressions. |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
The list of scan identifiers in the local database. |
See Also
plantdb.commons.fsdb._filter_query
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db(with_scan=True)
>>> db.list_scans()
['myscan_001']
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
|
path Link
path()
Get the path to the local database root directory.
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db()
>>> print(db.path())
/tmp/romidb_********
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
865 866 867 868 869 870 871 872 873 874 875 876 |
|
reload Link
reload(scan_id=None)
Reload the database by scanning datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str or list of str
|
The name of the scan(s) to reload. |
None
|
Source code in plantdb/commons/fsdb/core.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
scan_exists Link
scan_exists(scan_id)
Check if a given scan ID exists in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scan_id
|
str
|
The ID of the scan to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Examples:
>>> from plantdb.commons.fsdb import dummy_db
>>> db = dummy_db(with_scan=True)
>>> db.scan_exists("myscan_001")
True
>>> db.scan_exists("nonexistent_id")
False
>>> db.disconnect() # clean up (delete) the temporary dummy database
Source code in plantdb/commons/fsdb/core.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
|
user_exists Link
user_exists(username)
Check if the user exists in the local database.
Source code in plantdb/commons/fsdb/core.py
551 552 553 |
|
validate_user Link
validate_user(username, password)
Validate the user login.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username
|
str
|
The username provided by the user attempting to log in. |
required |
password
|
str
|
The password provided by the user attempting to log in. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Raises:
Type | Description |
---|---|
KeyError
|
If there is an issue accessing necessary user data. |
Source code in plantdb/commons/fsdb/core.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|