caosadvancedtools.utils module#
- caosadvancedtools.utils.check_win_path(path: str, filename: str = None)#
check whether ‘/’ are in the path but no ‘’.
If that is the case, it is likely, that the path is not a Windows path.
- Parameters:
path (str) – Path to be checked.
filename (str) – If the path is located in a file, this parameter can be used to direct the user to the file where the path is located.
- caosadvancedtools.utils.create_entity_link(entity: Entity, base_url: str = '')#
creates a string that contains the code for an html link to the provided entity.
The text of the link is the entity name if one exists and the id otherwise.
- Parameters:
entity (db.Entity) – the entity object to which the link will point
base_url (str) – optional, by default, the url starts with ‘/Entity’ and thus is relative. You can provide a base url that will be prefixed.
- Returns:
the string containing the html code
- Return type:
str
- caosadvancedtools.utils.find_records_that_reference_ids(referenced_ids, rt='', step_size=50)#
Returns a list with ids of records that reference entities with supplied ids
Sometimes a file or folder will be referenced in a README.md (e.g. in an Analysis) but not those files shall be referenced but the corresponding object (e.g. the Experiment). Thus the ids of all Records (of a suitable type) are collected that reference one or more of the supplied ids. This is done in chunks as the ids are passed in the header of the http request.
- caosadvancedtools.utils.get_referenced_files(glob: str, prefix: str = None, filename: str = None, location: str = None)#
queries the database for files referenced by the provided glob
- Parameters:
glob (str) – the glob referencing the file(s)
prefix (str, optional) – the glob can be relative to some path, in that case that path needs to be given as prefix
filename (str, optional) – the file in which the glob is given (used for error messages)
location (str, optional) – the location in the file in which the glob is given (used for error messages)
- caosadvancedtools.utils.read_field_as_list(field)#
E.g. in yaml headers entries can be single values or list. To simplify the work with those values, this function puts single values in a list.
- caosadvancedtools.utils.replace_path_prefix(path, old_prefix, new_prefix)#
Replaces the prefix old_prefix in path with new_prefix.
Raises a RuntimeError when the path does not start with old_prefix.
- caosadvancedtools.utils.return_field_or_property(value, prop=None)#
returns value itself of a property.
Typical in yaml headers is that a field might sometimes contain a single value and other times a dict itself. This function either returns the single value or (in case of dict as value) a value of the dict.
- caosadvancedtools.utils.set_log_level(level=10)#
- caosadvancedtools.utils.string_to_person(person)#
Creates a Person Record from a string.
The following formats are supported: - <Firstname> <Lastname> <*> - <Lastname(s)>,<Firstname(s)>,<*>
The part after the name can be used for an affiliation for example.