Skip to content
Snippets Groups Projects
Commit 79f67069 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: add config file

parent 4abe3f46
No related branches found
No related tags found
1 merge request!5MAINT: move datamodel config to a separate file
Pipeline #60982 passed with warnings
......@@ -24,10 +24,26 @@ classifiers = [
requires-python = ">= 3.8"
dependencies = [
"caosadvancedtools",
"importlib_resources",
"py3-validate-email",
"linkahead@git+https://gitlab.indiscale.com/caosdb/src/caosdb-pylib.git@dev"
]
[project.optional-dependencies]
test = [
"pytest",
"pytest-env",
"pytest-cov",
"coverage>=4.4.2",
]
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.package-data]
"loan" = ["*.ini"]
[project.urls]
Homepage = "https://getlinkahead.com"
Documentation = "https://docs.indiscale.com"
......
import linkahead as db
import os
import configparser
import importlib.resources as pkg_resources
from importlib_resources import files, as_file
default_config_path = pkg_resources.path(__package__, 'default_config.ini')
user_config_path = os.path.expanduser('~/.linkahead_loan')
config = configparser.ConfigParser()
config.read([default_config_path, user_config_path])
rts = config['RecordTypes']
ps = config['Properties']
# RecordTypes
with as_file(files('loan').joinpath('default_config.ini')) as default_config_path:
user_config_path = os.path.expanduser('~/.linkahead_loan')
config = configparser.ConfigParser()
config.read([default_config_path, user_config_path])
global rts, ps
rts = config['RecordTypes']
ps = config['Properties']
# RecordTypes
BOX = db.RecordType(name=rts['BOX'])
PERSON = db.RecordType(name=rts['PERSON'])
LOAN = db.RecordType(name=rts['LOAN'])
LOCATION = db.RecordType(name=rts['LOCATION'])
# Properties
FIRST_NAME = db.Property(name=ps['FIRST_NAME'], datatype=db.TEXT)
LAST_NAME = db.Property(name=ps['LAST_NAME'], datatype=db.TEXT)
EMAIL = db.Property(name=ps['EMAIL'], datatype=db.TEXT)
LOCATION = db.RecordType(name=rts['LOCATION'])
DESTINATION = db.Property(name=ps['DESTINATION'], datatype=rts['LOCATION'])
RETURNLOCATION = db.Property(name=ps['RETURNLOCATION'], datatype=rts['LOCATION'])
COMMENT = db.Property(name=ps['COMMENT'], datatype=db.TEXT)
......
[RecordTypes]
BOX = Box
PERSON = Person
LOAN = Loan
LOCATION = Location
[Properties]
FIRST_NAME = firstName
LAST_NAME = lastName
EMAIL = email
DESTINATION = LoanLocation
RETURNLOCATION = ReturnLocation
COMMENT = comment
EXHAUST_CONTENTS = exhaustContents
BORROWER = Borrower
CONTENT = Content
LOAN_REQUESTED = loanRequested
EXPECTED_RETURN = expectedReturn
LOAN_ACCEPTED = loanAccepted
LENT = lent
RETURN_REQUESTED = returnRequested
RETURN_ACCEPTED = returnAccepted
RETURNED = returned
BOX_NUMBER = Number
......@@ -83,8 +83,8 @@ def _check_data(data):
bad_references.append(item)
if bad_references:
raise ValueError(
f"The following value(s) of {F_BOX} has/have the wrong type. It should be "
f"integers or string representations thereof.\n{bad_references}")
f"The following value(s) of {F_BOX} has/have the wrong type. It should be "
f"integers or string representations thereof.\n{bad_references}")
assert_date_in_future(
data[F_EXPECTED_RETURN_DATE],
("The expected return date needs to be in the future."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment