core
Core types of dirschema.
DEF_MATCH
module-attribute
¶
DEF_MATCH: Final[str] = '(.*)'
Default match regex to assume when none is set, but required by semantics.
DEF_REWRITE
module-attribute
¶
DEF_REWRITE: Final[str] = '\\1'
Default rewrite rule to assume when none is set, but required by semantics.
MetaConvention ¶
Bases: BaseModel
Filename convention for metadata files that are associated with other entities.
It defines where to look for metadata for files that are not themselves known as json, or metadata concerning directories.
At the same time, these files are ignored by themselves and act as "sidecar" files.
Source code in src/dirschema/core.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 |
|
check_valid ¶
check_valid(values)
Check that at least one filename extension is non-empty.
Source code in src/dirschema/core.py
34 35 36 37 38 39 40 |
|
to_tuple ¶
to_tuple() -> Tuple[str, str, str, str]
Convert convention instance to tuple (e.g. used within CLI).
Source code in src/dirschema/core.py
42 43 44 |
|
from_tuple
classmethod
¶
from_tuple(pp: str, ps: str, fp: str, fs: str)
Return new metadata file convention.
Source code in src/dirschema/core.py
46 47 48 49 50 51 |
|
is_meta ¶
is_meta(path: str) -> bool
Check whether given path is a metadata file according to the convention.
Source code in src/dirschema/core.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
meta_for ¶
meta_for(path: str, is_dir: bool = False) -> str
Return metadata filename for provided path, based on this convention.
Source code in src/dirschema/core.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
PathSlice ¶
Bases: BaseModel
Helper class to slice into path segments and do regex-based match/substitution.
Invariant: into(path, sl).unslice() == path for all sl and path.
Source code in src/dirschema/core.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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
into
classmethod
¶
into(
path: str,
start: Optional[int] = None,
stop: Optional[int] = None,
) -> PathSlice
Slice into a path, splitting on the slashes.
Slice semantics is mostly like Python, except that stop=0 means "until the end", so that [0:0] means the full path.
Source code in src/dirschema/core.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
unslice ¶
unslice() -> str
Inverse of slice operation (recovers complete path string).
Source code in src/dirschema/core.py
122 123 124 |
|
match ¶
match(pat: Optional[Union[re.Pattern, str]] = None)
Do full regex match on current slice.
Source code in src/dirschema/core.py
129 130 131 132 133 134 |
|
rewrite ¶
rewrite(
pat: Optional[Union[re.Pattern, str]] = None,
sub: Optional[str] = None,
) -> Optional[PathSlice]
Match and rewrite in the slice string and return a new PathSlice.
If no pattern given, default pattern is used. If no substitution is given, just match on pattern is performed. Returns new PathSlice with possibly rewritten slice. Returns None if match fails. Raises exception of rewriting fails due to e.g. invalid capture groups.
Source code in src/dirschema/core.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
JSONSchema ¶
Bases: BaseModel
Helper class wrapping an arbitrary JSON Schema to be acceptable for pydantic.
Source code in src/dirschema/core.py
155 156 157 158 159 160 161 162 163 164 165 |
|
TypeEnum ¶
Bases: Enum
Possible values for a path type inside a dirschema rule.
MISSING means that the path must not exist (i.e. neither file or directory), whereas ANY means that any of these options is fine, as long as the path exists.
Source code in src/dirschema/core.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
is_satisfied ¶
is_satisfied(is_file: bool, is_dir: bool) -> bool
Check whether the flags of a path satisfy this path type.
Source code in src/dirschema/core.py
180 181 182 183 184 185 186 187 188 189 190 |
|
DSRule ¶
Bases: BaseModel
A DirSchema rule is either a trivial (boolean) rule, or a complex object.
Use this class for parsing, if it is not known which of these it is.
Source code in src/dirschema/core.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
__init__ ¶
__init__(
b: Optional[bool] = None, **kwargs: Optional[bool]
)
Construct wrapped boolean or object, depending on arguments.
Source code in src/dirschema/core.py
208 209 210 211 212 213 214 215 216 217 |
|
__repr__ ¶
__repr__() -> str
Make wrapper transparent and just return repr of wrapped object.
Source code in src/dirschema/core.py
219 220 221 222 223 224 |
|
__bool__ ¶
__bool__()
Just return value for wrapped object.
Source code in src/dirschema/core.py
226 227 228 |
|
Rule ¶
Bases: BaseModel
A DirSchema is a conjunction of a subset of distinct constraints/keywords.
Source code in src/dirschema/core.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
__repr__ ¶
__repr__(stream = None) -> str
Print out the rule as YAML (only the non-default values).
Source code in src/dirschema/core.py
315 316 317 318 319 320 321 322 323 324 325 |
|