filefinder.group#
Group management.
Module Attributes
Can be used to select one or more groups in a pattern. |
Classes
|
Manage a group inside the filename pattern. |
Exceptions
|
Custom errors when parsing group definition. |
- exception GroupParseError(message, group=None)#
Custom errors when parsing group definition.
- class Group(definition, idx)#
Manage a group inside the filename pattern.
- Parameters:
- Raises:
GroupParseError – Invalid group definition.:
- fix_value(fix)#
Fix the group regex to a specific value.
- get_regex()#
Get group regex.
Returns the fixed value if previously specified. Insert the regex into a capturing group, and make it optional if the
:opt
was indicated- Return type:
- unfix()#
Unfix value.
- DEFAULT_GROUPS = {'B': ['[a-zA-Z]*', 's'], 'F': ['%Y-%m-%d', 's'], 'H': ['\\d\\d', '02d'], 'I': ['\\d+', 'd'], 'M': ['\\d\\d', '02d'], 'S': ['\\d\\d', '02d'], 'X': ['%H%M%S', '06d'], 'Y': ['\\d{4}', '04d'], 'char': ['\\S*', 's'], 'd': ['\\d\\d', '02d'], 'j': ['\\d{3}', '03d'], 'm': ['\\d\\d', '02d'], 'text': ['\\w', 's'], 'x': ['%Y%m%d', '08d']}#
Regex and format strings for various default groups.
See the Name section of documentation for details.
- PATTERN = re.compile('(?P<name>[^:]+?)(?:(?P<fmt>:fmt=.+?)|(?P<rgx>:rgx=.*?)|(?P<bool>:bool=.*?(?::.*?)??)|(?P<opt>:opt)|(?P<discard>:discard)){,5}')#
Pattern used to find properties in group definition.
- definition#
The string that created the group
%(definition)
.
- fmt: FormatAbstract#
Format string object.
- optional: bool#
If True, the whole group is marked as optional (
()?
). Is set to False unless specification ‘:opt’ is indicated.
- GroupKey = int | str#
Can be used to select one or more groups in a pattern.