| 1 |
from Base.Metadata import export, class_declarations |
| 2 |
from Base.PyObjectBase import PyObjectBase |
| 3 |
from typing import Any, List, Dict, overload, Optional |
| 4 |
|
| 5 |
|
| 6 |
@export( |
| 7 |
Constructor=True, |
| 8 |
Delete=True, |
| 9 |
NumberProtocol=False, |
| 10 |
RichCompare=False, |
| 11 |
) |
| 12 |
@class_declarations( |
| 13 |
"""public: |
| 14 |
MetadataPy(const Metadata & pla, PyTypeObject *T = &Type) |
| 15 |
:PyObjectBase(new Metadata(pla),T){} |
| 16 |
Metadata value() const |
| 17 |
{ return *(getMetadataPtr()); } |
| 18 |
""" |
| 19 |
) |
| 20 |
class Metadata(PyObjectBase): |
| 21 |
""" |
| 22 |
App.Metadata class. |
| 23 |
|
| 24 |
A Metadata object reads an XML-formatted package metadata file and provides |
| 25 |
read and write access to its contents. |
| 26 |
|
| 27 |
The following constructors are supported: |
| 28 |
|
| 29 |
Metadata() |
| 30 |
Empty constructor. |
| 31 |
|
| 32 |
Metadata(metadata) |
| 33 |
Copy constructor. |
| 34 |
metadata : App.Metadata |
| 35 |
|
| 36 |
Metadata(file) |
| 37 |
Reads the XML file and provides access to the metadata it specifies. |
| 38 |
file : str |
| 39 |
XML file name. |
| 40 |
|
| 41 |
Metadata(bytes) |
| 42 |
Treats the bytes as UTF-8-encoded XML data and provides access to the metadata it specifies. |
| 43 |
bytes : bytes |
| 44 |
Python bytes-like object. |
| 45 |
|
| 46 |
Author: Chris Hennes ([email protected]) |
| 47 |
Licence: LGPL |
| 48 |
DeveloperDocu: Metadata |
| 49 |
""" |
| 50 |
|
| 51 |
@overload |
| 52 |
def __init__(self) -> None: ... |
| 53 |
|
| 54 |
@overload |
| 55 |
def __init__(self, metadata: "Metadata") -> None: ... |
| 56 |
|
| 57 |
@overload |
| 58 |
def __init__(self, file: str) -> None: ... |
| 59 |
|
| 60 |
@overload |
| 61 |
def __init__(self, bytes: bytes) -> None: ... |
| 62 |
|
| 63 |
Name: str = "" |
| 64 |
"""String representing the name of this item.""" |
| 65 |
|
| 66 |
Version: str = "" |
| 67 |
"""String representing the version of this item in semantic triplet format.""" |
| 68 |
|
| 69 |
Date: str = "" |
| 70 |
"""String representing the date of this item in YYYY-MM-DD format (format not currently programmatically enforced)""" |
| 71 |
|
| 72 |
Type: str = "" |
| 73 |
"""String representing the type of this item (text only, no markup allowed).""" |
| 74 |
|
| 75 |
Description: str = "" |
| 76 |
"""String representing the description of this item (text only, no markup allowed).""" |
| 77 |
|
| 78 |
Maintainer: List[Any] = [] |
| 79 |
"""List of maintainer objects with 'name' and 'email' string attributes.""" |
| 80 |
|
| 81 |
License: List[Any] = [] |
| 82 |
"""List of applicable licenses as objects with 'name' and 'file' string attributes.""" |
| 83 |
|
| 84 |
Urls: List[Any] = [] |
| 85 |
""" |
| 86 |
List of URLs as objects with 'location' and 'type' string attributes, where type |
| 87 |
is one of: |
| 88 |
* website |
| 89 |
* repository |
| 90 |
* bugtracker |
| 91 |
* readme |
| 92 |
* documentation |
| 93 |
""" |
| 94 |
|
| 95 |
Author: List[Any] = [] |
| 96 |
""" |
| 97 |
List of author objects, each with a 'name' and a (potentially empty) 'email' |
| 98 |
string attribute. |
| 99 |
""" |
| 100 |
|
| 101 |
Depend: List[Any] = [] |
| 102 |
""" |
| 103 |
List of dependencies, as objects with the following attributes: |
| 104 |
* package |
| 105 |
Required. Must exactly match the contents of the 'name' element in the |
| 106 |
referenced package's package.xml file. |
| 107 |
* version_lt |
| 108 |
Optional. The dependency to the package is restricted to versions less than |
| 109 |
the stated version number. |
| 110 |
* version_lte |
| 111 |
Optional. The dependency to the package is restricted to versions less or |
| 112 |
equal than the stated version number. |
| 113 |
* version_eq |
| 114 |
Optional. The dependency to the package is restricted to a version equal |
| 115 |
than the stated version number. |
| 116 |
* version_gte |
| 117 |
Optional. The dependency to the package is restricted to versions greater |
| 118 |
or equal than the stated version number. |
| 119 |
* version_gt |
| 120 |
Optional. The dependency to the package is restricted to versions greater |
| 121 |
than the stated version number. |
| 122 |
* condition |
| 123 |
Optional. Conditional expression as documented in REP149. |
| 124 |
""" |
| 125 |
|
| 126 |
Conflict: List[Any] = [] |
| 127 |
"""List of conflicts, format identical to dependencies.""" |
| 128 |
|
| 129 |
Replace: List[Any] = [] |
| 130 |
""" |
| 131 |
List of things this item is considered by its author to replace. The format is |
| 132 |
identical to dependencies. |
| 133 |
""" |
| 134 |
|
| 135 |
Tag: List[str] = [] |
| 136 |
"""List of strings.""" |
| 137 |
|
| 138 |
Icon: str = "" |
| 139 |
"""Relative path to an icon file.""" |
| 140 |
|
| 141 |
Classname: str = "" |
| 142 |
""" |
| 143 |
String representing the name of the main Python class this item |
| 144 |
creates/represents. |
| 145 |
""" |
| 146 |
|
| 147 |
Subdirectory: str = "" |
| 148 |
""" |
| 149 |
String representing the name of the subdirectory this content item is located in. |
| 150 |
If empty, the item is in a directory named the same as the content item. |
| 151 |
""" |
| 152 |
|
| 153 |
File: List[Any] = [] |
| 154 |
""" |
| 155 |
List of files associated with this item. |
| 156 |
The meaning of each file is implementation-defined. |
| 157 |
""" |
| 158 |
|
| 159 |
Content: Dict[str, List["Metadata"]] = {} |
| 160 |
""" |
| 161 |
Dictionary of lists of content items: defined recursively, each item is itself |
| 162 |
a Metadata object. |
| 163 |
See package.xml file format documentation for details. |
| 164 |
""" |
| 165 |
|
| 166 |
FreeCADMin: str = "" |
| 167 |
""" |
| 168 |
String representing the minimum version of FreeCAD needed for this item. |
| 169 |
If unset it will be 0.0.0. |
| 170 |
""" |
| 171 |
|
| 172 |
FreeCADMax: str = "" |
| 173 |
""" |
| 174 |
String representing the maximum version of FreeCAD needed for this item. |
| 175 |
If unset it will be 0.0.0. |
| 176 |
""" |
| 177 |
|
| 178 |
PythonMin: str = "" |
| 179 |
""" |
| 180 |
String representing the minimum version of Python needed for this item. |
| 181 |
If unset it will be 0.0.0. |
| 182 |
""" |
| 183 |
|
| 184 |
def getLastSupportedFreeCADVersion(self) -> Optional[str]: |
| 185 |
""" |
| 186 |
getLastSupportedFreeCADVersion() -> str or None |
| 187 |
|
| 188 |
Search through all content package items, and determine if a maximum supported |
| 189 |
version of FreeCAD is set. |
| 190 |
Returns None if no maximum version is set, or if *any* content item fails to |
| 191 |
provide a maximum version (implying that that content item will work with all |
| 192 |
known versions). |
| 193 |
""" |
| 194 |
... |
| 195 |
|
| 196 |
def getFirstSupportedFreeCADVersion(self) -> Optional[str]: |
| 197 |
""" |
| 198 |
getFirstSupportedFreeCADVersion() -> str or None |
| 199 |
|
| 200 |
Search through all content package items, and determine if a minimum supported |
| 201 |
version of FreeCAD is set. |
| 202 |
Returns 0.0 if no minimum version is set, or if *any* content item fails to |
| 203 |
provide a minimum version (implying that that content item will work with all |
| 204 |
known versions. Technically limited to 0.20 as the lowest known version since |
| 205 |
the metadata standard was added then). |
| 206 |
""" |
| 207 |
... |
| 208 |
|
| 209 |
def supportsCurrentFreeCAD(self) -> bool: |
| 210 |
""" |
| 211 |
supportsCurrentFreeCAD() -> bool |
| 212 |
|
| 213 |
Returns False if this metadata object directly indicates that it does not |
| 214 |
support the current version of FreeCAD, or True if it makes no indication, or |
| 215 |
specifically indicates that it does support the current version. Does not |
| 216 |
recurse into Content items. |
| 217 |
""" |
| 218 |
... |
| 219 |
|
| 220 |
def getGenericMetadata(self, name: str) -> List[Any]: |
| 221 |
""" |
| 222 |
getGenericMetadata(name) -> list |
| 223 |
|
| 224 |
Get the list of GenericMetadata objects with key 'name'. |
| 225 |
Generic metadata objects are Python objects with a string 'contents' and a |
| 226 |
dictionary of strings, 'attributes'. They represent unrecognized simple XML tags |
| 227 |
in the metadata file. |
| 228 |
""" |
| 229 |
... |
| 230 |
|
| 231 |
def addContentItem(self, content_type: str, metadata: "Metadata") -> None: |
| 232 |
""" |
| 233 |
addContentItem(content_type,metadata) |
| 234 |
|
| 235 |
Add a new content item of type 'content_type' with metadata 'metadata'. |
| 236 |
""" |
| 237 |
... |
| 238 |
|
| 239 |
def removeContentItem(self, content_type: str, name: str) -> None: |
| 240 |
""" |
| 241 |
removeContentItem(content_type,name) |
| 242 |
|
| 243 |
Remove the content item of type 'content_type' with name 'name'. |
| 244 |
""" |
| 245 |
... |
| 246 |
|
| 247 |
def addMaintainer(self, name: str, email: str) -> None: |
| 248 |
""" |
| 249 |
addMaintainer(name, email) |
| 250 |
|
| 251 |
Add a new Maintainer. |
| 252 |
""" |
| 253 |
... |
| 254 |
|
| 255 |
def removeMaintainer(self, name: str, email: str) -> None: |
| 256 |
""" |
| 257 |
removeMaintainer(name, email) |
| 258 |
|
| 259 |
Remove the Maintainer. |
| 260 |
""" |
| 261 |
... |
| 262 |
|
| 263 |
def addLicense(self, short_code: str, path: str) -> None: |
| 264 |
""" |
| 265 |
addLicense(short_code,path) |
| 266 |
|
| 267 |
Add a new License. |
| 268 |
""" |
| 269 |
... |
| 270 |
|
| 271 |
def removeLicense(self, short_code: str) -> None: |
| 272 |
""" |
| 273 |
removeLicense(short_code) |
| 274 |
|
| 275 |
Remove the License. |
| 276 |
""" |
| 277 |
... |
| 278 |
|
| 279 |
def addUrl(self, url_type: str, url: str, branch: str) -> None: |
| 280 |
""" |
| 281 |
addUrl(url_type,url,branch) |
| 282 |
|
| 283 |
Add a new Url or type 'url_type' (which should be one of 'repository', 'readme', |
| 284 |
|
| 285 |
'bugtracker', 'documentation', or 'webpage') If type is 'repository' you |
| 286 |
|
| 287 |
must also specify the 'branch' parameter. |
| 288 |
""" |
| 289 |
... |
| 290 |
|
| 291 |
def removeUrl(self, url_type: str, url: str) -> None: |
| 292 |
""" |
| 293 |
removeUrl(url_type,url) |
| 294 |
|
| 295 |
Remove the Url. |
| 296 |
""" |
| 297 |
... |
| 298 |
|
| 299 |
def addAuthor(self, name: str, email: str) -> None: |
| 300 |
""" |
| 301 |
addAuthor(name, email) |
| 302 |
|
| 303 |
Add a new Author with name 'name', and optionally email 'email'. |
| 304 |
""" |
| 305 |
... |
| 306 |
|
| 307 |
def removeAuthor(self, name: str, email: str) -> None: |
| 308 |
""" |
| 309 |
removeAuthor(name, email) |
| 310 |
|
| 311 |
Remove the Author. |
| 312 |
""" |
| 313 |
... |
| 314 |
|
| 315 |
def addDepend(self, name: str, kind: str, optional: bool) -> None: |
| 316 |
""" |
| 317 |
addDepend(name, kind, optional) |
| 318 |
|
| 319 |
Add a new Dependency on package 'name' of kind 'kind' (optional, one of 'auto' (the default), |
| 320 |
|
| 321 |
'internal', 'addon', or 'python'). |
| 322 |
""" |
| 323 |
... |
| 324 |
|
| 325 |
def removeDepend(self, name: str, kind: str) -> None: |
| 326 |
""" |
| 327 |
removeDepend(name, kind) |
| 328 |
|
| 329 |
Remove the Dependency on package 'name' of kind 'kind' (optional - if unspecified any |
| 330 |
|
| 331 |
matching name is removed). |
| 332 |
""" |
| 333 |
... |
| 334 |
|
| 335 |
def addConflict(self, name: str, kind: str) -> None: |
| 336 |
""" |
| 337 |
addConflict(name, kind) |
| 338 |
|
| 339 |
Add a new Conflict. See documentation for addDepend(). |
| 340 |
""" |
| 341 |
... |
| 342 |
|
| 343 |
def removeConflict(self, name: str, kind: str) -> None: |
| 344 |
""" |
| 345 |
removeConflict(name, kind) |
| 346 |
|
| 347 |
Remove the Conflict. See documentation for removeDepend(). |
| 348 |
""" |
| 349 |
... |
| 350 |
|
| 351 |
def addReplace(self, name: str) -> None: |
| 352 |
""" |
| 353 |
addReplace(name) |
| 354 |
|
| 355 |
Add a new Replace. |
| 356 |
""" |
| 357 |
... |
| 358 |
|
| 359 |
def removeReplace(self, name: str) -> None: |
| 360 |
""" |
| 361 |
removeReplace(name) |
| 362 |
|
| 363 |
Remove the Replace. |
| 364 |
""" |
| 365 |
... |
| 366 |
|
| 367 |
def addTag(self, tag: str) -> None: |
| 368 |
""" |
| 369 |
addTag(tag) |
| 370 |
|
| 371 |
Add a new Tag. |
| 372 |
""" |
| 373 |
... |
| 374 |
|
| 375 |
def removeTag(self, tag: str) -> None: |
| 376 |
""" |
| 377 |
removeTag(tag) |
| 378 |
|
| 379 |
Remove the Tag. |
| 380 |
""" |
| 381 |
... |
| 382 |
|
| 383 |
def addFile(self, filename: str) -> None: |
| 384 |
""" |
| 385 |
addFile(filename) |
| 386 |
|
| 387 |
Add a new File. |
| 388 |
""" |
| 389 |
... |
| 390 |
|
| 391 |
def removeFile(self, filename: str) -> None: |
| 392 |
""" |
| 393 |
removeFile(filename) |
| 394 |
|
| 395 |
Remove the File. |
| 396 |
""" |
| 397 |
... |
| 398 |
|
| 399 |
def write(self, filename: str) -> None: |
| 400 |
""" |
| 401 |
write(filename) |
| 402 |
|
| 403 |
Write the metadata to the given file as XML data. |
| 404 |
""" |
| 405 |
... |